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`.
14 lines
462 B
TypeScript
14 lines
462 B
TypeScript
/**
|
|
* Plain JSON-compatible representation of a World.
|
|
* Returned by `world.toJSON()`, consumed by `World.fromJSON()`.
|
|
*/
|
|
export interface WorldSnapshot {
|
|
/** Entity stable ID → component map (component name → data). */
|
|
entities: Record<string, Record<string, unknown>>;
|
|
/** Relationship name → (source ID → target ID or edge object). */
|
|
relationships: Record<
|
|
string,
|
|
Record<string, string | { target: string; data: unknown }>
|
|
>;
|
|
}
|