@codehz/ecs 0.7.1 → 0.7.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.
package/builder.d.mts CHANGED
@@ -1339,7 +1339,8 @@ declare class EntityBuilder {
1339
1339
  * builder.with(Position, { x: 10, y: 20 });
1340
1340
  * builder.with(Marker); // void component
1341
1341
  */
1342
- with<T>(componentId: EntityId<T>, ...args: T extends void ? [] | [void] : [T]): this;
1342
+ with<T extends void>(componentId: EntityId<T>): this;
1343
+ with<T>(componentId: EntityId<T>, value: T): this;
1343
1344
  /**
1344
1345
  * Add a relation component to the entity under construction.
1345
1346
  *
@@ -1353,7 +1354,8 @@ declare class EntityBuilder {
1353
1354
  * builder.withRelation(Parent, parentEntity);
1354
1355
  * builder.withRelation(ChildOf, childEntity, { order: 1 });
1355
1356
  */
1356
- withRelation<T>(componentId: ComponentId<T>, targetEntity: EntityId<any>, ...args: T extends void ? [] | [void] : [T]): this;
1357
+ withRelation<T extends void>(componentId: ComponentId<T>, targetEntity: EntityId<any>): this;
1358
+ withRelation<T>(componentId: ComponentId<T>, targetEntity: EntityId<any>, value: T): this;
1357
1359
  /**
1358
1360
  * Create the entity and enqueue all configured components.
1359
1361
  * The entity and components are only materialised after {@link World.sync} is called.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codehz/ecs",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/codehz/ecs"
6
6
  },
package/world.mjs CHANGED
@@ -600,20 +600,7 @@ var EntityBuilder = class {
600
600
  constructor(world) {
601
601
  this.world = world;
602
602
  }
603
- /**
604
- * Add a regular component to the entity under construction.
605
- *
606
- * @template T - The component data type
607
- * @param componentId - The component type to add
608
- * @param args - Component data (omit for void components)
609
- * @returns This builder for chaining
610
- *
611
- * @example
612
- * builder.with(Position, { x: 10, y: 20 });
613
- * builder.with(Marker); // void component
614
- */
615
- with(componentId, ...args) {
616
- const value = args.length > 0 ? args[0] : void 0;
603
+ with(componentId, value) {
617
604
  this.components.push({
618
605
  type: "component",
619
606
  id: componentId,
@@ -621,21 +608,7 @@ var EntityBuilder = class {
621
608
  });
622
609
  return this;
623
610
  }
624
- /**
625
- * Add a relation component to the entity under construction.
626
- *
627
- * @template T - The relation data type
628
- * @param componentId - The base component type for the relation
629
- * @param targetEntity - The target entity or component for the relation
630
- * @param args - Relation data (omit for void relations)
631
- * @returns This builder for chaining
632
- *
633
- * @example
634
- * builder.withRelation(Parent, parentEntity);
635
- * builder.withRelation(ChildOf, childEntity, { order: 1 });
636
- */
637
- withRelation(componentId, targetEntity, ...args) {
638
- const value = args.length > 0 ? args[0] : void 0;
611
+ withRelation(componentId, targetEntity, value) {
639
612
  this.components.push({
640
613
  type: "relation",
641
614
  componentId,
@@ -2036,10 +2009,16 @@ function collectMultiHookComponents(ctx, entityId, componentTypes) {
2036
2009
  /**
2037
2010
  * Reconstructs wildcard relation data by merging current data with removed components.
2038
2011
  * Returns an array of [targetId, value] tuples for the wildcard relation.
2012
+ *
2013
+ * This is used during "on_remove" hook invocation: the removed components have already
2014
+ * been taken out of the entity's archetype, but the hook callback expects to see the
2015
+ * full data as it existed *before* removal. We reconstruct that snapshot by taking the
2016
+ * current wildcard data (post-removal) and adding back the entries that were just removed.
2039
2017
  */
2040
2018
  function reconstructWildcardWithRemoved(ctx, entityId, wildcardId, removedComponents) {
2041
2019
  const currentData = ctx.get(entityId, wildcardId);
2042
- const result = Array.isArray(currentData) ? [...currentData] : [];
2020
+ if (!Array.isArray(currentData)) throw new Error(`Expected wildcard relation data to be an array, but got ${typeof currentData} for entity ${entityId} and wildcard ${wildcardId}. This indicates a HooksContext implementation that does not conform to the expected contract.`);
2021
+ const result = [...currentData];
2043
2022
  for (const [removedCompId, removedValue] of removedComponents.entries()) if (componentMatchesHookType(removedCompId, wildcardId)) {
2044
2023
  const targetId = getTargetIdFromRelationId(removedCompId);
2045
2024
  if (targetId !== void 0) result.push([targetId, removedValue]);