feat: add support for data-carrying relationships

Introduce the ability to attach optional data payloads to
relationships. This includes:

- Updating `defineRelationship` to accept default values.
- Adding `getRelData` and `setRelData` to the `World` class.
- Allowing `relate` to accept an optional data override.
- Updating serialization to include relationship data in snapshots.
- Implementing lazy storage for relationship data using `SparseSet`.
This commit is contained in:
2026-06-02 17:56:12 +08:00
parent a97488e8d6
commit cd6350e0b1
4 changed files with 288 additions and 15 deletions
+5 -2
View File
@@ -5,6 +5,9 @@
export interface WorldSnapshot {
/** Entity stable ID → component map (component name → data). */
entities: Record<string, Record<string, unknown>>;
/** Relationship name → (source ID → target ID). */
relationships: Record<string, Record<string, string>>;
/** Relationship name → (source ID → target ID or edge object). */
relationships: Record<
string,
Record<string, string | { target: string; data: unknown }>
>;
}