ecs-observable/src/relationship.ts

25 lines
724 B
TypeScript

// ── Relationship ─────────────────────────────────────
/**
* A relationship definition — like a component, but represents a directed
* link between two entities.
*
* @example
* ```ts
* const ChildOf = defineRelationship('childOf');
* world.relate(child, ChildOf, parent);
* ```
*/
export interface RelationshipDef {
/** Unique symbol used as the storage key. */
readonly _key: symbol;
/** Human-readable name, used for serialization. */
readonly name: string;
}
/**
* Define a named relationship between entities.
*/
export function defineRelationship(name: string): RelationshipDef {
return { _key: Symbol(), name };
}