42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
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<ChildOf, Parent>
|
|
/// {
|
|
/// Source = child,
|
|
/// Target = parent
|
|
/// });
|
|
///
|
|
/// // Later, find all children of a parent.
|
|
/// var children = world.GetSources<Relationship<ChildOf, Parent>>(parent);
|
|
/// </code>
|
|
/// </example>
|
|
/// </summary>
|
|
[MessagePackObject]
|
|
public struct Relationship<TSelf, TTarget> : IRelationship
|
|
where TSelf : struct where TTarget : struct
|
|
{
|
|
/// <summary>
|
|
/// The entity that owns this relationship component.
|
|
/// </summary>
|
|
[Key(0)]
|
|
public Entity Source { get; set; }
|
|
|
|
/// <summary>
|
|
/// The entity that this relationship points to.
|
|
/// </summary>
|
|
[Key(1)]
|
|
public Entity Target { get; set; }
|
|
}
|