@driftengine/entities 4.7.0 → 4.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/dist/system.d.ts CHANGED
@@ -45,6 +45,18 @@ export interface SystemView {
45
45
  read(entity: Entity, type: ComponentType, field: string): unknown;
46
46
  write(entity: Entity, type: ComponentType, field: string, value: unknown): void;
47
47
  has(entity: Entity, type: ComponentType): boolean;
48
+ /**
49
+ * How many entities carry a component, and the one at an index among them; both reads, so both
50
+ * checked. A script's `ecs.count` and `ecs.at` reach these, and a view without them made each
51
+ * throw the moment a system called it.
52
+ */
53
+ count(type: ComponentType): number;
54
+ at(type: ComponentType, index: number): Entity;
55
+ /**
56
+ * Whether a handle names a live entity. It asks nothing of any component, so nothing is checked;
57
+ * an entity this system destroyed is still alive until the system returns.
58
+ */
59
+ alive(entity: Entity): boolean;
48
60
  create(): Entity;
49
61
  add(entity: Entity, type: ComponentType, values?: Readonly<Record<string, unknown>>): void;
50
62
  /** Deferred to after this system runs. See the header. */
@@ -105,6 +117,9 @@ export declare class BoundSystem implements SystemView {
105
117
  read(entity: Entity, type: ComponentType, field: string): unknown;
106
118
  write(entity: Entity, type: ComponentType, field: string, value: unknown): void;
107
119
  has(entity: Entity, type: ComponentType): boolean;
120
+ count(type: ComponentType): number;
121
+ at(type: ComponentType, index: number): Entity;
122
+ alive(entity: Entity): boolean;
108
123
  create(): Entity;
109
124
  add(entity: Entity, type: ComponentType, values?: Readonly<Record<string, unknown>>): void;
110
125
  destroy(entity: Entity): void;
package/dist/system.js CHANGED
@@ -72,6 +72,17 @@ export class BoundSystem {
72
72
  this.requireReadable(type);
73
73
  return this.world.has(entity, type);
74
74
  }
75
+ count(type) {
76
+ this.requireReadable(type);
77
+ return this.world.count(type);
78
+ }
79
+ at(type, index) {
80
+ this.requireReadable(type);
81
+ return this.world.at(type, index);
82
+ }
83
+ alive(entity) {
84
+ return this.world.alive(entity);
85
+ }
75
86
  create() {
76
87
  return this.world.create();
77
88
  }
package/dist/world.d.ts CHANGED
@@ -73,6 +73,15 @@ export declare class World implements CursorHost {
73
73
  * number of component *types* rather than of entities.
74
74
  */
75
75
  destroy(entity: Entity): boolean;
76
+ /** How many entities carry a component. */
77
+ count(type: ComponentType): number;
78
+ /**
79
+ * The entity at `index` among those carrying a component, or `-1` past the end.
80
+ *
81
+ * The order is the store's: insertion, modified by swap-removal, so it is a walk and not an
82
+ * identity, and an index held across a removal names a different entity.
83
+ */
84
+ at(type: ComponentType, index: number): Entity;
76
85
  /** The store for a component type, made on first ask. */
77
86
  store(type: ComponentType): ComponentStore;
78
87
  /**
package/dist/world.js CHANGED
@@ -60,6 +60,20 @@ export class World {
60
60
  store.remove(entity);
61
61
  return this.entities.destroy(entity);
62
62
  }
63
+ /** How many entities carry a component. */
64
+ count(type) {
65
+ return this.store(type).size;
66
+ }
67
+ /**
68
+ * The entity at `index` among those carrying a component, or `-1` past the end.
69
+ *
70
+ * The order is the store's: insertion, modified by swap-removal, so it is a walk and not an
71
+ * identity, and an index held across a removal names a different entity.
72
+ */
73
+ at(type, index) {
74
+ const store = this.store(type);
75
+ return index >= 0 && index < store.size ? store.dense[index] : -1;
76
+ }
63
77
  /** The store for a component type, made on first ask. */
64
78
  store(type) {
65
79
  const existing = this.stores.get(type.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftengine/entities",
3
- "version": "4.7.0",
3
+ "version": "4.7.2",
4
4
  "description": "Entities with generational identity, component storage, systems and scenes",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
- "driftscript": "1.13.0"
30
+ "driftscript": "1.13.1"
31
31
  },
32
32
  "author": "Drift Technologies",
33
33
  "repository": {
package/src/system.ts CHANGED
@@ -46,6 +46,18 @@ export interface SystemView {
46
46
  read(entity: Entity, type: ComponentType, field: string): unknown;
47
47
  write(entity: Entity, type: ComponentType, field: string, value: unknown): void;
48
48
  has(entity: Entity, type: ComponentType): boolean;
49
+ /**
50
+ * How many entities carry a component, and the one at an index among them; both reads, so both
51
+ * checked. A script's `ecs.count` and `ecs.at` reach these, and a view without them made each
52
+ * throw the moment a system called it.
53
+ */
54
+ count(type: ComponentType): number;
55
+ at(type: ComponentType, index: number): Entity;
56
+ /**
57
+ * Whether a handle names a live entity. It asks nothing of any component, so nothing is checked;
58
+ * an entity this system destroyed is still alive until the system returns.
59
+ */
60
+ alive(entity: Entity): boolean;
49
61
  create(): Entity;
50
62
  add(entity: Entity, type: ComponentType, values?: Readonly<Record<string, unknown>>): void;
51
63
  /** Deferred to after this system runs. See the header. */
@@ -147,6 +159,20 @@ export class BoundSystem implements SystemView {
147
159
  return this.world.has(entity, type);
148
160
  }
149
161
 
162
+ count(type: ComponentType): number {
163
+ this.requireReadable(type);
164
+ return this.world.count(type);
165
+ }
166
+
167
+ at(type: ComponentType, index: number): Entity {
168
+ this.requireReadable(type);
169
+ return this.world.at(type, index);
170
+ }
171
+
172
+ alive(entity: Entity): boolean {
173
+ return this.world.alive(entity);
174
+ }
175
+
150
176
  create(): Entity {
151
177
  return this.world.create();
152
178
  }
package/src/world.ts CHANGED
@@ -110,6 +110,22 @@ export class World implements CursorHost {
110
110
  return this.entities.destroy(entity);
111
111
  }
112
112
 
113
+ /** How many entities carry a component. */
114
+ count(type: ComponentType): number {
115
+ return this.store(type).size;
116
+ }
117
+
118
+ /**
119
+ * The entity at `index` among those carrying a component, or `-1` past the end.
120
+ *
121
+ * The order is the store's: insertion, modified by swap-removal, so it is a walk and not an
122
+ * identity, and an index held across a removal names a different entity.
123
+ */
124
+ at(type: ComponentType, index: number): Entity {
125
+ const store = this.store(type);
126
+ return index >= 0 && index < store.size ? (store.dense[index] as number) : -1;
127
+ }
128
+
113
129
  /** The store for a component type, made on first ask. */
114
130
  store(type: ComponentType): ComponentStore {
115
131
  const existing = this.stores.get(type.id);