oecs-sharp/OECS/Relationship.cs

35 lines
998 B
C#
Raw Permalink Normal View History

using MessagePack;
namespace OECS;
/// <summary>
/// A convenience base struct for relationship components.
///
/// The type parameters <typeparamref name="TSelf"/> and <typeparamref name="TTarget"/>
/// are phantom types that differentiate relationship kinds at the type level,
/// enabling type-safe queries and reverse lookups.
///
/// <example>
/// <code>
/// // Define a "ChildOf" relationship between a child and a parent entity.
/// world.AddComponent(child, new Relationship&lt;ChildOf, Parent&gt;
/// {
/// Target = parent
/// });
///
/// // Later, find all children of a parent.
/// var children = world.GetSources&lt;Relationship&lt;ChildOf, Parent&gt;&gt;(parent);
/// </code>
/// </example>
/// </summary>
[MessagePackObject]
public struct Relationship<TSelf, TTarget> : IRelationship
where TSelf : struct where TTarget : struct
{
/// <summary>
/// The entity that this relationship points to.
/// </summary>
[Key(0)]
public Entity Target { get; set; }
}