@codehz/ecs 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- //#region src/entity.d.ts
1
+ //#region src/core/entity-types.d.ts
2
2
  /**
3
3
  * Unique symbol brand for associating component type information with EntityId
4
4
  */
@@ -23,17 +23,6 @@ type EntityRelationId<T = void> = EntityId<T, "entity-relation">;
23
23
  type ComponentRelationId<T = void> = EntityId<T, "component-relation">;
24
24
  type WildcardRelationId<T = void> = EntityId<T, "wildcard-relation">;
25
25
  type RelationId<T = void> = EntityRelationId<T> | ComponentRelationId<T> | WildcardRelationId<T>;
26
- /**
27
- * Type for relation ID based on component and target types
28
- */
29
- type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T> : R extends EntityId<any> ? EntityRelationId<T> : never;
30
- /**
31
- * Create a relation ID by associating a component with another ID (entity or component)
32
- * @param componentId The component ID (0-1023)
33
- * @param targetId The target ID (entity, component, or '*' for wildcard)
34
- */
35
- declare function relation<T>(componentId: ComponentId<T>, targetId: "*"): WildcardRelationId<T>;
36
- declare function relation<T, R extends EntityId<any>>(componentId: ComponentId<T>, targetId: R): RelationIdType<T, R>;
37
26
  /**
38
27
  * Check if an ID is a component ID
39
28
  */
@@ -46,6 +35,19 @@ declare function isEntityId<T>(id: EntityId<T>): id is EntityId<T>;
46
35
  * Check if an ID is a relation ID
47
36
  */
48
37
  declare function isRelationId<T>(id: EntityId<T>): id is RelationId<T>;
38
+ //#endregion
39
+ //#region src/core/entity-relation.d.ts
40
+ /**
41
+ * Type for relation ID based on component and target types
42
+ */
43
+ type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T> : R extends EntityId<any> ? EntityRelationId<T> : never;
44
+ /**
45
+ * Create a relation ID by associating a component with another ID (entity or component)
46
+ * @param componentId The component ID (0-1023)
47
+ * @param targetId The target ID (entity, component, or '*' for wildcard)
48
+ */
49
+ declare function relation<T>(componentId: ComponentId<T>, targetId: "*"): WildcardRelationId<T>;
50
+ declare function relation<T, R extends EntityId<any>>(componentId: ComponentId<T>, targetId: R): RelationIdType<T, R>;
49
51
  /**
50
52
  * Check if an ID is a wildcard relation id
51
53
  */
@@ -60,6 +62,8 @@ declare function decodeRelationId(relationId: RelationId<any>): {
60
62
  targetId: EntityId<any>;
61
63
  type: "entity" | "component" | "wildcard";
62
64
  };
65
+ //#endregion
66
+ //#region src/core/component-registry.d.ts
63
67
  /**
64
68
  * Component options that define intrinsic properties
65
69
  */
@@ -117,7 +121,57 @@ declare function getComponentIdByName(name: string): ComponentId<any> | undefine
117
121
  */
118
122
  declare function getComponentNameById(id: ComponentId<any>): string | undefined;
119
123
  //#endregion
120
- //#region src/types.d.ts
124
+ //#region src/commands/changeset.d.ts
125
+ /**
126
+ * @internal Represents a set of component changes to be applied to an entity
127
+ */
128
+ declare class ComponentChangeset {
129
+ readonly adds: Map<EntityId<any>, any>;
130
+ readonly removes: Set<EntityId<any>>;
131
+ /**
132
+ * Add a component to the changeset
133
+ */
134
+ set<T>(componentType: EntityId<T>, component: T): void;
135
+ /**
136
+ * Remove a component from the changeset
137
+ */
138
+ delete<T>(componentType: EntityId<T>): void;
139
+ /**
140
+ * Check if the changeset has any changes
141
+ */
142
+ hasChanges(): boolean;
143
+ /**
144
+ * Clear all changes
145
+ */
146
+ clear(): void;
147
+ /**
148
+ * Merge another changeset into this one
149
+ */
150
+ merge(other: ComponentChangeset): void;
151
+ /**
152
+ * Apply the changeset to existing components and return the final state
153
+ */
154
+ applyTo(existingComponents: Map<EntityId<any>, any>): Map<EntityId<any>, any>;
155
+ /**
156
+ * Get the final component types after applying the changeset
157
+ * @param existingComponentTypes - The current component types on the entity
158
+ * @returns The final component types or undefined if no changes
159
+ */
160
+ getFinalComponentTypes(existingComponentTypes: EntityId<any>[]): EntityId<any>[] | undefined;
161
+ }
162
+ //#endregion
163
+ //#region src/commands/command-buffer.d.ts
164
+ /**
165
+ * Command for deferred execution
166
+ */
167
+ interface Command {
168
+ type: "set" | "delete" | "destroy";
169
+ entityId: EntityId;
170
+ componentType?: EntityId<any>;
171
+ component?: any;
172
+ }
173
+ //#endregion
174
+ //#region src/core/types.d.ts
121
175
  /**
122
176
  * Hook types for component lifecycle events
123
177
  */
@@ -154,7 +208,7 @@ type ComponentTypeToData<T> = T extends {
154
208
  */
155
209
  type ComponentTuple<T extends readonly ComponentType<any>[]> = { readonly [K in keyof T]: ComponentTypeToData<T[K]> };
156
210
  //#endregion
157
- //#region src/archetype.d.ts
211
+ //#region src/core/archetype.d.ts
158
212
  /**
159
213
  * Archetype class for ECS architecture
160
214
  * Represents a group of entities that share the same set of components
@@ -186,224 +240,46 @@ declare class Archetype {
186
240
  private dontFragmentRelations;
187
241
  /**
188
242
  * Cache for pre-computed component data sources to avoid repeated calculations
189
- * For regular components: data array
190
- * For wildcards: matching relation types array
191
243
  */
192
244
  private componentDataSourcesCache;
193
- /**
194
- * Create a new archetype with the specified component types
195
- * @param componentTypes The component types that define this archetype
196
- * @param dontFragmentRelations Reference to the World's dontFragmentRelations storage
197
- */
198
245
  constructor(componentTypes: EntityId<any>[], dontFragmentRelations: Map<EntityId, Map<EntityId<any>, any>>);
199
- /**
200
- * Get the number of entities in this archetype
201
- */
202
246
  get size(): number;
203
- /**
204
- * Check if this archetype matches the given component types
205
- * @param componentTypes The component types to check
206
- */
207
247
  matches(componentTypes: EntityId<any>[]): boolean;
208
- /**
209
- * Add an entity to this archetype with initial component data
210
- * @param entityId The entity to add
211
- * @param componentData Map of component type to component data (includes both regular and dontFragment components)
212
- */
213
248
  addEntity(entityId: EntityId, componentData: Map<EntityId<any>, any>): void;
214
- /**
215
- * Get all component data for a specific entity
216
- * @param entityId The entity to get data for
217
- * @returns Map of component type to component data (includes both regular and dontFragment components)
218
- */
249
+ private addDontFragmentRelations;
219
250
  getEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
220
- /**
221
- * Dump all entities and their component data in this archetype
222
- * @returns Array of objects with entity and component data (includes both regular and dontFragment components)
223
- */
224
251
  dump(): Array<{
225
252
  entity: EntityId;
226
253
  components: Map<EntityId<any>, any>;
227
254
  }>;
228
- /**
229
- * Remove an entity from this archetype
230
- * @param entityId The entity to remove
231
- * @returns The component data of the removed entity (includes both regular and dontFragment components)
232
- */
233
255
  removeEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
234
- /**
235
- * Check if an entity is in this archetype
236
- * @param entityId The entity to check
237
- */
238
256
  exists(entityId: EntityId): boolean;
239
- /**
240
- * Get component data for a specific entity and wildcard relation type
241
- * Returns an array of all matching relation instances
242
- * @param entityId The entity
243
- * @param componentType The wildcard relation type
244
- */
245
257
  get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, any][];
246
- /**
247
- * Get component data for a specific entity and component type
248
- * @param entityId The entity
249
- * @param componentType The component type
250
- */
251
258
  get<T>(entityId: EntityId, componentType: EntityId<T>): T;
252
- /**
253
- * Get optional component data for a specific entity and component type
254
- * @param entityId The entity
255
- * @param componentType The component type
256
- * @returns { value: T } if component exists, undefined otherwise
257
- */
259
+ private getWildcardRelations;
260
+ private getRegularComponent;
258
261
  getOptional<T>(entityId: EntityId, componentType: EntityId<T>): {
259
262
  value: T;
260
263
  } | undefined;
261
- /**
262
- * Set component data for a specific entity and component type
263
- * @param entityId The entity
264
- * @param componentType The component type
265
- * @param data The component data
266
- */
267
264
  set<T>(entityId: EntityId, componentType: EntityId<T>, data: T): void;
268
- /**
269
- * Get all entities in this archetype
270
- */
271
265
  getEntities(): EntityId[];
272
- /**
273
- * Get the mapping of entities to their indices in this archetype
274
- */
275
266
  getEntityToIndexMap(): Map<EntityId, number>;
276
- /**
277
- * Get component data for all entities of a specific component type
278
- * @param componentType The component type
279
- */
280
267
  getComponentData<T>(componentType: EntityId<T>): T[];
281
- /**
282
- * Get optional component data for all entities of a specific component type
283
- * @param componentType The component type
284
- * @returns An array of component data or undefined if not present
285
- */
286
268
  getOptionalComponentData<T>(componentType: EntityId<T>): T[] | undefined;
287
- /**
288
- * Helper: compute or return cached data sources for provided componentTypes
289
- */
290
269
  private getCachedComponentDataSources;
291
- /**
292
- * Build cache key for component types
293
- */
294
- private buildCacheKey;
295
- /**
296
- * Get data source for a single component type
297
- */
298
270
  private getComponentDataSource;
299
- /**
300
- * Get data source for wildcard relations
301
- */
302
- private getWildcardRelationDataSource;
303
- /**
304
- * Helper: build component tuples for a specific entity index using precomputed data sources
305
- */
306
271
  private buildComponentsForIndex;
307
- /**
308
- * Build a single component value from its data source
309
- */
310
- private buildSingleComponent;
311
- /**
312
- * Build wildcard relation value from matching relations
313
- */
314
- private buildWildcardRelationValue;
315
- /**
316
- * Build regular component value from data source
317
- */
318
- private buildRegularComponentValue;
319
- /**
320
- * Get entities with their component data for specified component types
321
- * Optimized for bulk component access with pre-computed indices
322
- * @param componentTypes Array of component types to retrieve
323
- * @returns Array of objects with entity and component data
324
- */
325
272
  getEntitiesWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): Array<{
326
273
  entity: EntityId;
327
274
  components: ComponentTuple<T>;
328
275
  }>;
329
- /**
330
- * Iterate over entities with their component data for specified component types
331
- * implemented as a generator returning each entity/components pair lazily
332
- * @param componentTypes Array of component types to retrieve
333
- */
334
276
  iterateWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): IterableIterator<[EntityId, ...ComponentTuple<T>]>;
335
- /**
336
- * Iterate over entities with their component data for specified component types
337
- * Optimized for bulk component access
338
- * @param componentTypes Array of component types to retrieve
339
- * @param callback Function called for each entity with its components
340
- */
341
277
  forEachWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T, callback: (entity: EntityId, ...components: ComponentTuple<T>) => void): void;
342
- /**
343
- * Iterate over all entities with their component data
344
- * @param callback Function called for each entity with its component data
345
- */
346
278
  forEach(callback: (entityId: EntityId, components: Map<EntityId<any>, any>) => void): void;
347
- /**
348
- * Check if any entity in this archetype has a relation matching the given component ID
349
- * This includes both regular relations in componentTypes and dontFragment relations
350
- * @param componentId The component ID to match
351
- * @returns true if any entity has a matching relation
352
- */
353
279
  hasRelationWithComponentId(componentId: EntityId<any>): boolean;
354
280
  }
355
281
  //#endregion
356
- //#region src/changeset.d.ts
357
- /**
358
- * @internal Represents a set of component changes to be applied to an entity
359
- */
360
- declare class ComponentChangeset {
361
- readonly adds: Map<EntityId<any>, any>;
362
- readonly removes: Set<EntityId<any>>;
363
- /**
364
- * Add a component to the changeset
365
- */
366
- set<T>(componentType: EntityId<T>, component: T): void;
367
- /**
368
- * Remove a component from the changeset
369
- */
370
- delete<T>(componentType: EntityId<T>): void;
371
- /**
372
- * Check if the changeset has any changes
373
- */
374
- hasChanges(): boolean;
375
- /**
376
- * Clear all changes
377
- */
378
- clear(): void;
379
- /**
380
- * Merge another changeset into this one
381
- */
382
- merge(other: ComponentChangeset): void;
383
- /**
384
- * Apply the changeset to existing components and return the final state
385
- */
386
- applyTo(existingComponents: Map<EntityId<any>, any>): Map<EntityId<any>, any>;
387
- /**
388
- * Get the final component types after applying the changeset
389
- * @param existingComponentTypes - The current component types on the entity
390
- * @returns The final component types or undefined if no changes
391
- */
392
- getFinalComponentTypes(existingComponentTypes: EntityId<any>[]): EntityId<any>[] | undefined;
393
- }
394
- //#endregion
395
- //#region src/command-buffer.d.ts
396
- /**
397
- * Command for deferred execution
398
- */
399
- interface Command {
400
- type: "set" | "delete" | "destroy";
401
- entityId: EntityId;
402
- componentType?: EntityId<any>;
403
- component?: any;
404
- }
405
- //#endregion
406
- //#region src/query-filter.d.ts
282
+ //#region src/query/filter.d.ts
407
283
  /**
408
284
  * Filter options for queries
409
285
  */
@@ -411,7 +287,7 @@ interface QueryFilter {
411
287
  negativeComponentTypes?: EntityId<any>[];
412
288
  }
413
289
  //#endregion
414
- //#region src/query.d.ts
290
+ //#region src/query/query.d.ts
415
291
  /**
416
292
  * Query class for efficient entity queries with cached archetypes
417
293
  */
@@ -421,6 +297,8 @@ declare class Query {
421
297
  private filter;
422
298
  private cachedArchetypes;
423
299
  private isDisposed;
300
+ /** Cached wildcard component types for faster entity filtering */
301
+ private wildcardTypes;
424
302
  constructor(world: World, componentTypes: EntityId<any>[], filter?: QueryFilter);
425
303
  /**
426
304
  * Check if query is disposed and throw error if so
@@ -430,6 +308,10 @@ declare class Query {
430
308
  * Get all entities matching the query
431
309
  */
432
310
  getEntities(): EntityId[];
311
+ /**
312
+ * Check if entity has all required wildcard relations
313
+ */
314
+ private entityHasAllWildcards;
433
315
  /**
434
316
  * Get entities with their component data
435
317
  * @param componentTypes Array of component types to retrieve
@@ -469,9 +351,6 @@ declare class Query {
469
351
  * Remove an archetype from the cached archetypes
470
352
  */
471
353
  removeArchetype(archetype: Archetype): void;
472
- /**
473
- * Dispose the query and disconnect from world
474
- */
475
354
  /**
476
355
  * Request disposal of this query.
477
356
  * This will decrement the world's reference count for the query.
@@ -492,331 +371,90 @@ declare class Query {
492
371
  get disposed(): boolean;
493
372
  }
494
373
  //#endregion
495
- //#region src/world.d.ts
374
+ //#region src/core/serialization.d.ts
496
375
  type SerializedEntityId = number | string | {
497
376
  component: string;
498
377
  target: number | string | "*";
499
378
  };
379
+ type SerializedWorld = {
380
+ version: number;
381
+ entityManager: any;
382
+ entities: SerializedEntity[];
383
+ };
384
+ type SerializedEntity = {
385
+ id: SerializedEntityId;
386
+ components: SerializedComponent[];
387
+ };
388
+ type SerializedComponent = {
389
+ type: SerializedEntityId;
390
+ value: any;
391
+ };
392
+ //#endregion
393
+ //#region src/core/world.d.ts
500
394
  /**
501
395
  * World class for ECS architecture
502
396
  * Manages entities and components
503
397
  */
504
398
  declare class World {
505
- /** Manages allocation and deallocation of entity IDs */
506
399
  private entityIdManager;
507
- /** Array of all archetypes in the world */
508
400
  private archetypes;
509
- /** Maps archetype signatures (component type signatures) to archetype instances */
510
401
  private archetypeBySignature;
511
- /** Maps entity IDs to their current archetype */
512
402
  private entityToArchetype;
513
- /** Maps component types to arrays of archetypes that contain them */
514
403
  private archetypesByComponent;
515
- /** Tracks which entities reference each entity as a component type */
516
404
  private entityReferences;
517
- /** Storage for dontFragment relations - maps entity ID to a map of relation type to component data */
518
405
  private dontFragmentRelations;
519
- /** Array of all active queries for archetype change notifications */
520
406
  private queries;
521
- /** Cache for queries keyed by component types and filter signatures */
522
407
  private queryCache;
523
- /** Buffers structural changes for deferred execution */
524
408
  private commandBuffer;
525
- /** Stores lifecycle hooks for component and relation events */
526
409
  private hooks;
527
- /** Stores multi-component lifecycle hooks */
528
410
  private multiHooks;
529
- /**
530
- * Create a new World.
531
- * If an optional snapshot object is provided (previously produced by `world.serialize()`),
532
- * the world will be restored from that snapshot. The snapshot may contain non-JSON values.
533
- */
534
411
  constructor(snapshot?: SerializedWorld);
535
- /**
536
- * Generate a signature string for component types array
537
- * @returns A string signature for the component types
538
- */
412
+ private deserializeSnapshot;
539
413
  private createArchetypeSignature;
540
- /**
541
- * Create a new entity
542
- * @returns The ID of the newly created entity
543
- */
544
414
  new<T = void>(): EntityId<T>;
545
- /**
546
- * Destroy an entity and remove all its components (immediate execution)
547
- */
548
415
  private destroyEntityImmediate;
549
- /**
550
- * Check if an entity exists
551
- */
552
416
  exists(entityId: EntityId): boolean;
553
- /**
554
- * Add a component to an entity (deferred)
555
- */
556
417
  set(entityId: EntityId, componentType: EntityId<void>): void;
557
418
  set<T>(entityId: EntityId, componentType: EntityId<T>, component: NoInfer<T>): void;
558
- /**
559
- * Remove a component from an entity (deferred)
560
- */
561
419
  remove<T>(entityId: EntityId, componentType: EntityId<T>): void;
562
- /**
563
- * Destroy an entity and remove all its components (deferred)
564
- */
565
420
  delete(entityId: EntityId): void;
566
- /**
567
- * Check if an entity has a specific component
568
- */
569
421
  has<T>(entityId: EntityId, componentType: EntityId<T>): boolean;
570
- /**
571
- * Get component data for a specific entity and wildcard relation type
572
- * Returns an array of all matching relation instances
573
- * @param entityId The entity
574
- * @param componentType The wildcard relation type
575
- * @returns Array of [targetEntityId, componentData] pairs for all matching relations
576
- */
577
422
  get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, T][];
578
- /**
579
- * Get component data for a specific entity and component type
580
- * @param entityId The entity
581
- * @param componentType The component type
582
- * @returns The component data
583
- */
584
423
  get<T>(entityId: EntityId, componentType: EntityId<T>): T;
585
- /**
586
- * Get optional component data for a specific entity and component type
587
- * @param entityId The entity
588
- * @param componentType The component type
589
- * @returns { value: T } if component exists, undefined otherwise
590
- */
591
424
  getOptional<T>(entityId: EntityId, componentType: EntityId<T>): {
592
425
  value: T;
593
426
  } | undefined;
594
- /**
595
- * Register a lifecycle hook for component or wildcard relation events
596
- */
597
427
  hook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
598
428
  hook<const T extends readonly ComponentType<any>[]>(componentTypes: T, hook: MultiLifecycleHook<T>): void;
599
- /**
600
- * Unregister a lifecycle hook for component or wildcard relation events
601
- */
602
429
  unhook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
603
430
  unhook<const T extends readonly ComponentType<any>[]>(componentTypes: T, hook: MultiLifecycleHook<T>): void;
604
- /**
605
- * Execute all deferred commands immediately
606
- */
607
431
  sync(): void;
608
- /**
609
- * Create a cached query for efficient entity lookups
610
- * @returns A Query object for the specified component types and filter
611
- */
612
432
  createQuery(componentTypes: EntityId<any>[], filter?: QueryFilter): Query;
613
- /**
614
- * Create an EntityBuilder for convenient entity creation.
615
- * @returns EntityBuilder
616
- */
617
433
  spawn(): EntityBuilder;
618
- /**
619
- * Spawn multiple entities using an EntityBuilder configuration callback
620
- * @param count number of entities
621
- * @param configure builder configuration callback
622
- * @returns Created entity IDs
623
- */
624
434
  spawnMany(count: number, configure: (builder: EntityBuilder, index: number) => EntityBuilder): EntityId[];
625
- /**
626
- * @internal Register a query for archetype update notifications
627
- */
628
435
  _registerQuery(query: Query): void;
629
- /**
630
- * @internal Unregister a query
631
- */
632
436
  _unregisterQuery(query: Query): void;
633
- /**
634
- * Release a query reference obtained from createQuery.
635
- * Decrements the refCount and fully disposes the query when it reaches zero.
636
- */
637
437
  releaseQuery(query: Query): void;
638
- /**
639
- * @internal Get archetypes that match specific component types (for internal use by queries)
640
- */
641
438
  getMatchingArchetypes(componentTypes: EntityId<any>[]): Archetype[];
642
- /**
643
- * Query entities with specific components
644
- * @returns Array of entity IDs that have all the specified components
645
- */
439
+ private getArchetypesWithComponents;
646
440
  query(componentTypes: EntityId<any>[]): EntityId[];
647
441
  query<const T extends readonly EntityId<any>[]>(componentTypes: T, includeComponents: true): Array<{
648
442
  entity: EntityId;
649
443
  components: ComponentTuple<T>;
650
444
  }>;
651
- /**
652
- * @internal Execute commands for a single entity (for internal use by CommandBuffer)
653
- * @returns ComponentChangeset describing the changes made
654
- */
655
445
  executeEntityCommands(entityId: EntityId, commands: Command[]): ComponentChangeset;
656
- /**
657
- * Process commands and populate the changeset
658
- */
659
- private processCommands;
660
- /**
661
- * Process a set command, handling exclusive relations
662
- */
663
- private processSetCommand;
664
- /**
665
- * Remove all relations with the same base component (for exclusive relations)
666
- */
667
- private removeExclusiveRelations;
668
- private isRelationWithComponent;
669
- /**
670
- * Process a delete command, handling wildcard relations
671
- */
672
- private processDeleteCommand;
673
- /**
674
- * Remove all relations matching a wildcard component ID
675
- */
676
- private removeWildcardRelations;
677
- /**
678
- * Remove a single component from an entity immediately, handling dontFragment relations correctly.
679
- * Used by destroyEntityImmediate for non-cascade relation cleanup.
680
- */
446
+ private createHooksContext;
681
447
  private removeComponentImmediate;
682
- /**
683
- * Apply changeset to entity, moving to new archetype if needed
684
- * @returns Map of removed components with their data
685
- */
686
- private applyChangeset;
687
- /**
688
- * Move entity to a new archetype with updated components
689
- */
690
- private moveEntityToNewArchetype;
691
- /**
692
- * Update entity in same archetype (no archetype change needed)
693
- */
694
- private updateEntityInSameArchetype;
695
- /**
696
- * Apply dontFragment relation changes directly to World's storage
697
- * This is much more efficient than the removeEntity + addEntity approach
698
- */
699
- private applyDontFragmentChanges;
700
- /**
701
- * Update entity reference tracking based on changeset
702
- */
703
448
  private updateEntityReferences;
704
- /**
705
- * Get or create an archetype for the given component types
706
- * Filters out dontFragment relations from the archetype signature
707
- * @returns The archetype for the given component types (excluding dontFragment relations)
708
- */
709
449
  private ensureArchetype;
710
- /**
711
- * Compare two arrays of component types for equality (order-independent)
712
- */
713
- private areComponentTypesEqual;
714
- /**
715
- * Filter out dontFragment relations from component types, but keep wildcard markers
716
- */
717
- private filterRegularComponentTypes;
718
- /**
719
- * Create a new archetype and register it with all tracking structures
720
- */
721
450
  private createNewArchetype;
722
- /**
723
- * Register archetype in the component-to-archetype index
724
- */
725
- private registerArchetypeInComponentIndex;
726
- /**
727
- * Notify all queries to check the new archetype
728
- */
729
- private notifyQueriesOfNewArchetype;
730
- /**
731
- * Add a component reference to the reverse index when an entity is used as a component type
732
- * @param sourceEntityId The entity that has the component
733
- * @param componentType The component type (which may be an entity ID used as component type)
734
- * @param targetEntityId The entity being used as component type
735
- */
736
- private trackEntityReference;
737
- /**
738
- * Remove a component reference from the reverse index
739
- * @param sourceEntityId The entity that has the component
740
- * @param componentType The component type
741
- * @param targetEntityId The entity being used as component type
742
- */
743
- private untrackEntityReference;
744
- /**
745
- * Get all component references where a target entity is used as a component type
746
- * @param targetEntityId The target entity
747
- * @returns A MultiMap of sourceEntityId to componentTypes that reference the target entity
748
- */
749
- private getEntityReferences;
750
- /**
751
- * Check if an archetype's signature references a specific entity
752
- * (via entity-relation targeting the entity, or using entity as component type)
753
- */
754
451
  private archetypeReferencesEntity;
755
- /**
756
- * Cleanup empty archetypes that reference a specific deleted entity
757
- * Only removes archetypes whose component types reference the entity
758
- */
759
452
  private cleanupArchetypesReferencingEntity;
760
- /**
761
- * Remove archetype from the main archetypes list
762
- */
763
- private removeArchetypeFromList;
764
- /**
765
- * Remove archetype from the signature-to-archetype map
766
- */
767
- private removeArchetypeFromSignatureMap;
768
- /**
769
- * Remove archetype from the component-to-archetypes index
770
- */
771
- private removeArchetypeFromComponentIndex;
772
- /**
773
- * Remove archetype from all queries
774
- */
775
- private removeArchetypeFromQueries;
776
- /**
777
- * Execute component lifecycle hooks for added and removed components
778
- */
779
- private triggerLifecycleHooks;
780
- /**
781
- * Trigger multi-component hooks based on changes
782
- */
783
- private triggerMultiComponentHooks;
784
- /**
785
- * Check if entity currently has all required components
786
- */
787
- private entityHasAllComponents;
788
- /**
789
- * Check if entity had all required components before removal
790
- */
791
- private entityHadAllComponentsBefore;
792
- /**
793
- * Collect component values for multi-component hook (current state)
794
- */
795
- private collectMultiHookComponents;
796
- /**
797
- * Collect component values for multi-component hook with removed components (snapshot before removal)
798
- */
799
- private collectMultiHookComponentsWithRemoved;
800
- /**
801
- * Convert the world into a plain snapshot object.
802
- * This returns an in-memory structure and does not perform JSON stringification.
803
- * Component values are stored as-is (they may be non-JSON-serializable).
804
- */
453
+ private removeArchetype;
805
454
  serialize(): SerializedWorld;
806
455
  }
807
- type SerializedWorld = {
808
- version: number;
809
- entityManager: any;
810
- entities: SerializedEntity[];
811
- };
812
- type SerializedEntity = {
813
- id: SerializedEntityId;
814
- components: SerializedComponent[];
815
- };
816
- type SerializedComponent = {
817
- type: SerializedEntityId;
818
- value: any;
819
- };
456
+ //#endregion
457
+ //#region src/core/builder.d.ts
820
458
  /**
821
459
  * A component definition for entity building, supporting both regular components and relations
822
460
  */
@@ -847,5 +485,5 @@ declare class EntityBuilder {
847
485
  build(): EntityId;
848
486
  }
849
487
  //#endregion
850
- export { isComponentId as C, relation as D, isWildcardRelationId as E, getComponentNameById as S, isRelationId as T, RelationId as _, SerializedEntityId as a, decodeRelationId as b, Query as c, LifecycleHook as d, ComponentId as f, EntityRelationId as g, EntityId as h, SerializedEntity as i, ComponentTuple as l, ComponentRelationId as m, EntityBuilder as n, SerializedWorld as o, ComponentOptions as p, SerializedComponent as r, World as s, ComponentDef as t, ComponentType as u, WildcardRelationId as v, isEntityId as w, getComponentIdByName as x, component as y };
851
- //# sourceMappingURL=world.d.mts.map
488
+ export { RelationId as C, isRelationId as D, isEntityId as E, EntityRelationId as S, isComponentId as T, isWildcardRelationId as _, SerializedEntity as a, ComponentRelationId as b, Query as c, LifecycleHook as d, ComponentOptions as f, decodeRelationId as g, getComponentNameById as h, SerializedComponent as i, ComponentTuple as l, getComponentIdByName as m, EntityBuilder as n, SerializedEntityId as o, component as p, World as r, SerializedWorld as s, ComponentDef as t, ComponentType as u, relation as v, WildcardRelationId as w, EntityId as x, ComponentId as y };
489
+ //# sourceMappingURL=builder.d.mts.map