@codehz/ecs 0.1.0 → 0.1.1
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/index.js +17 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -259,7 +259,7 @@ class Archetype {
|
|
|
259
259
|
this.entityToIndex.set(entityId, index);
|
|
260
260
|
for (const componentType of this.componentTypes) {
|
|
261
261
|
const data = componentData.get(componentType);
|
|
262
|
-
this.
|
|
262
|
+
this.getComponentData(componentType).push(data === undefined ? MISSING_COMPONENT : data);
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
removeEntity(entityId) {
|
|
@@ -271,7 +271,7 @@ class Archetype {
|
|
|
271
271
|
this.entityToIndex.delete(entityId);
|
|
272
272
|
const removedData = new Map;
|
|
273
273
|
for (const componentType of this.componentTypes) {
|
|
274
|
-
const dataArray = this.
|
|
274
|
+
const dataArray = this.getComponentData(componentType);
|
|
275
275
|
removedData.set(componentType, dataArray[index]);
|
|
276
276
|
dataArray.splice(index, 1);
|
|
277
277
|
}
|
|
@@ -295,7 +295,7 @@ class Archetype {
|
|
|
295
295
|
for (const relType of this.componentTypes) {
|
|
296
296
|
const relDetailed = getDetailedIdType(relType);
|
|
297
297
|
if ((relDetailed.type === "entity-relation" || relDetailed.type === "component-relation") && relDetailed.componentId === componentId) {
|
|
298
|
-
const dataArray = this.
|
|
298
|
+
const dataArray = this.getComponentData(relType);
|
|
299
299
|
if (dataArray && dataArray[index] !== undefined) {
|
|
300
300
|
const data = dataArray[index];
|
|
301
301
|
relations.push([relDetailed.targetId, data === MISSING_COMPONENT ? undefined : data]);
|
|
@@ -304,7 +304,7 @@ class Archetype {
|
|
|
304
304
|
}
|
|
305
305
|
return relations;
|
|
306
306
|
} else {
|
|
307
|
-
const data = this.
|
|
307
|
+
const data = this.getComponentData(componentType)[index];
|
|
308
308
|
return data === MISSING_COMPONENT ? undefined : data;
|
|
309
309
|
}
|
|
310
310
|
}
|
|
@@ -316,14 +316,18 @@ class Archetype {
|
|
|
316
316
|
if (index === undefined) {
|
|
317
317
|
throw new Error(`Entity ${entityId} is not in this archetype`);
|
|
318
318
|
}
|
|
319
|
-
const dataArray = this.
|
|
319
|
+
const dataArray = this.getComponentData(componentType);
|
|
320
320
|
dataArray[index] = data;
|
|
321
321
|
}
|
|
322
322
|
getEntities() {
|
|
323
|
-
return
|
|
323
|
+
return this.entities;
|
|
324
324
|
}
|
|
325
325
|
getComponentData(componentType) {
|
|
326
|
-
|
|
326
|
+
const data = this.componentData.get(componentType);
|
|
327
|
+
if (!data) {
|
|
328
|
+
throw new Error(`Component type ${componentType} is not in this archetype`);
|
|
329
|
+
}
|
|
330
|
+
return data;
|
|
327
331
|
}
|
|
328
332
|
getEntitiesWithComponents(componentTypes) {
|
|
329
333
|
const result = [];
|
|
@@ -347,7 +351,7 @@ class Archetype {
|
|
|
347
351
|
});
|
|
348
352
|
return matchingRelations;
|
|
349
353
|
} else {
|
|
350
|
-
return this.
|
|
354
|
+
return this.getComponentData(compType);
|
|
351
355
|
}
|
|
352
356
|
});
|
|
353
357
|
});
|
|
@@ -359,12 +363,10 @@ class Archetype {
|
|
|
359
363
|
const matchingRelations = dataSource;
|
|
360
364
|
const relations = [];
|
|
361
365
|
for (const relType of matchingRelations) {
|
|
362
|
-
const dataArray = this.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
relations.push([decodedRel.targetId, data === MISSING_COMPONENT ? undefined : data]);
|
|
367
|
-
}
|
|
366
|
+
const dataArray = this.getComponentData(relType);
|
|
367
|
+
const data = dataArray[entityIndex];
|
|
368
|
+
const decodedRel = decodeRelationId(relType);
|
|
369
|
+
relations.push([decodedRel.targetId, data === MISSING_COMPONENT ? undefined : data]);
|
|
368
370
|
}
|
|
369
371
|
return relations;
|
|
370
372
|
} else {
|
|
@@ -380,7 +382,7 @@ class Archetype {
|
|
|
380
382
|
for (let i = 0;i < this.entities.length; i++) {
|
|
381
383
|
const components = new Map;
|
|
382
384
|
for (const componentType of this.componentTypes) {
|
|
383
|
-
const data = this.
|
|
385
|
+
const data = this.getComponentData(componentType)[i];
|
|
384
386
|
components.set(componentType, data === MISSING_COMPONENT ? undefined : data);
|
|
385
387
|
}
|
|
386
388
|
callback(this.entities[i], components);
|