@codehz/ecs 0.2.0 → 0.2.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/entity.d.ts +6 -2
- package/index.js +19 -3
- package/package.json +1 -1
- package/world.d.ts +1 -1
package/entity.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare function createEntityId(id: number): EntityId;
|
|
|
47
47
|
/**
|
|
48
48
|
* Type for relation ID based on component and target types
|
|
49
49
|
*/
|
|
50
|
-
type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T
|
|
50
|
+
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;
|
|
51
51
|
/**
|
|
52
52
|
* Create a relation ID by associating a component with another ID (entity or component)
|
|
53
53
|
* @param componentId The component ID (0-1023)
|
|
@@ -95,9 +95,13 @@ export declare function getDetailedIdType(id: EntityId<any>): {
|
|
|
95
95
|
componentId?: never;
|
|
96
96
|
targetId?: never;
|
|
97
97
|
} | {
|
|
98
|
-
type: "entity-relation" | "
|
|
98
|
+
type: "entity-relation" | "wildcard-relation";
|
|
99
99
|
componentId: ComponentId<any>;
|
|
100
100
|
targetId: EntityId<any>;
|
|
101
|
+
} | {
|
|
102
|
+
type: "component-relation";
|
|
103
|
+
componentId: ComponentId<any>;
|
|
104
|
+
targetId: ComponentId<any>;
|
|
101
105
|
};
|
|
102
106
|
/**
|
|
103
107
|
* Inspect an EntityId and return a human-readable string representation
|
package/index.js
CHANGED
|
@@ -814,12 +814,20 @@ class World {
|
|
|
814
814
|
throw new Error(`Unknown component name in snapshot: ${componentTypeRaw}`);
|
|
815
815
|
}
|
|
816
816
|
componentType = compId;
|
|
817
|
-
} else if (typeof componentTypeRaw === "object" && componentTypeRaw !== null && typeof componentTypeRaw.component === "string"
|
|
817
|
+
} else if (typeof componentTypeRaw === "object" && componentTypeRaw !== null && typeof componentTypeRaw.component === "string") {
|
|
818
818
|
const compId = getComponentIdByName(componentTypeRaw.component);
|
|
819
819
|
if (compId === undefined) {
|
|
820
820
|
throw new Error(`Unknown component name in snapshot: ${componentTypeRaw.component}`);
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
if (typeof componentTypeRaw.target === "string") {
|
|
823
|
+
const targetCompId = getComponentIdByName(componentTypeRaw.target);
|
|
824
|
+
if (targetCompId === undefined) {
|
|
825
|
+
throw new Error(`Unknown target component name in snapshot: ${componentTypeRaw.target}`);
|
|
826
|
+
}
|
|
827
|
+
componentType = relation(compId, targetCompId);
|
|
828
|
+
} else {
|
|
829
|
+
componentType = relation(compId, componentTypeRaw.target);
|
|
830
|
+
}
|
|
823
831
|
} else {
|
|
824
832
|
throw new Error(`Invalid component type in snapshot: ${JSON.stringify(componentTypeRaw)}`);
|
|
825
833
|
}
|
|
@@ -1272,12 +1280,20 @@ class World {
|
|
|
1272
1280
|
type = getComponentNameById(rawType) || rawType;
|
|
1273
1281
|
break;
|
|
1274
1282
|
case "entity-relation":
|
|
1275
|
-
case "component-relation":
|
|
1276
1283
|
componentName = getComponentNameById(detailedType.componentId);
|
|
1277
1284
|
if (componentName) {
|
|
1278
1285
|
type = { component: componentName, target: detailedType.targetId };
|
|
1279
1286
|
}
|
|
1280
1287
|
break;
|
|
1288
|
+
case "component-relation":
|
|
1289
|
+
componentName = getComponentNameById(detailedType.componentId);
|
|
1290
|
+
if (componentName) {
|
|
1291
|
+
type = {
|
|
1292
|
+
component: componentName,
|
|
1293
|
+
target: getComponentNameById(detailedType.targetId) || detailedType.targetId
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1281
1297
|
}
|
|
1282
1298
|
return { type, value: value === MISSING_COMPONENT ? undefined : value };
|
|
1283
1299
|
})
|
package/package.json
CHANGED