@jael-ecs/core 1.0.2 → 1.1.0
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/README.md +74 -35
- package/dist/ComponentManager.d.ts +10 -8
- package/dist/EntityManager.d.ts +8 -9
- package/dist/EventRegistry.d.ts +9 -6
- package/dist/Query.d.ts +16 -6
- package/dist/World.d.ts +9 -7
- package/dist/index.d.ts +2 -2
- package/dist/jael-build.cjs +1 -1
- package/dist/jael-build.js +198 -150
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,13 +60,19 @@ interface Velocity {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// Create entities
|
|
63
|
-
const
|
|
64
|
-
world.addComponent(
|
|
65
|
-
world.addComponent(
|
|
63
|
+
const playerId = world.create();
|
|
64
|
+
world.addComponent(playerId, "position", { x: 0, y: 0 });
|
|
65
|
+
world.addComponent(playerId, "velocity", { dx: 1, dy: 1 });
|
|
66
66
|
|
|
67
|
-
const
|
|
68
|
-
world.addComponent(
|
|
69
|
-
world.addComponent(
|
|
67
|
+
const enemyId = world.create();
|
|
68
|
+
world.addComponent(enemyId, "position", { x: 10, y: 10 });
|
|
69
|
+
world.addComponent(enemyId, "velocity", { dx: -1, dy: 0 });
|
|
70
|
+
|
|
71
|
+
// Using Entity Proxy
|
|
72
|
+
const playerId = world.create();
|
|
73
|
+
const player = world.getEntity(playerId);
|
|
74
|
+
player.add("position", { x: 0, y: 0 });
|
|
75
|
+
player.add("velocity", { dx: 1, dy: 1 });
|
|
70
76
|
|
|
71
77
|
// Create a system
|
|
72
78
|
const movementSystem: System = {
|
|
@@ -74,10 +80,20 @@ const movementSystem: System = {
|
|
|
74
80
|
update() {
|
|
75
81
|
const query = world.include("position", "velocity");
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
// Get direct proxy access
|
|
84
|
+
query.entities.forEach((entity) => {
|
|
78
85
|
const position = entity.get<Position>("position");
|
|
79
86
|
const velocity = entity.get<Velocity>("velocity");
|
|
80
87
|
|
|
88
|
+
position.x += velocity.dx * (Time.delta || 0.016);
|
|
89
|
+
position.y += velocity.dy * (Time.delta || 0.016);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Get entity ids from query
|
|
93
|
+
for (const entityId of query.ids) {
|
|
94
|
+
const position = this.world.getComponent<Position>(entityId, "position");
|
|
95
|
+
const velocity = this.world.getComponent<Velocity>(entityId, "velocity");
|
|
96
|
+
|
|
81
97
|
position.x += velocity.dx * (Time.delta || 0.016);
|
|
82
98
|
position.y += velocity.dy * (Time.delta || 0.016);
|
|
83
99
|
}
|
|
@@ -111,29 +127,26 @@ The central hub that manages entities, components, and systems.
|
|
|
111
127
|
|
|
112
128
|
```typescript
|
|
113
129
|
// Create a new entity
|
|
114
|
-
const
|
|
130
|
+
const entityId = world.create();
|
|
115
131
|
|
|
116
132
|
// Destroy an entity
|
|
117
|
-
world.destroy(
|
|
133
|
+
world.destroy(entityId);
|
|
118
134
|
|
|
119
135
|
// Check if entity exists
|
|
120
|
-
const exists = world.exist(
|
|
136
|
+
const exists = world.exist(entityId);
|
|
121
137
|
```
|
|
122
138
|
|
|
123
139
|
#### Component Management
|
|
124
140
|
|
|
125
141
|
```typescript
|
|
126
142
|
// Add component
|
|
127
|
-
world.addComponent(
|
|
143
|
+
world.addComponent(entityId, "position", { x: 0, y: 0 });
|
|
128
144
|
|
|
129
145
|
// Remove component
|
|
130
|
-
world.removeComponent(
|
|
146
|
+
world.removeComponent(entityId, "position");
|
|
131
147
|
|
|
132
148
|
// Get component
|
|
133
|
-
const position =
|
|
134
|
-
|
|
135
|
-
// Check if entity has component
|
|
136
|
-
const hasPosition = entity.has("position");
|
|
149
|
+
const position = world.getComponent<Position>(entityId, "position");
|
|
137
150
|
```
|
|
138
151
|
|
|
139
152
|
#### System Management
|
|
@@ -149,7 +162,7 @@ world.removeSystem(yourSystem);
|
|
|
149
162
|
#### Events
|
|
150
163
|
|
|
151
164
|
```typescript
|
|
152
|
-
// Listen to world events
|
|
165
|
+
// Listen to world events ( returns entity proxy for easy reading )
|
|
153
166
|
world.on("entityCreated", ({ entity }) => {
|
|
154
167
|
console.log("Entity created:", entity);
|
|
155
168
|
});
|
|
@@ -173,11 +186,12 @@ world.on("updated", () => {
|
|
|
173
186
|
|
|
174
187
|
### Entity
|
|
175
188
|
|
|
176
|
-
Base entity class for intuitive component management
|
|
189
|
+
Base entity class for intuitive component management as proxy around id
|
|
177
190
|
|
|
178
191
|
```typescript
|
|
179
192
|
// Create entity
|
|
180
|
-
const
|
|
193
|
+
const entityId = world.create();
|
|
194
|
+
const entity = world.getEntity(entityId); // Returns Entity class proxy
|
|
181
195
|
|
|
182
196
|
// Add component
|
|
183
197
|
entity.add("position", { x: 0, y: 0 });
|
|
@@ -190,6 +204,9 @@ const posExist = entity.has("position");
|
|
|
190
204
|
|
|
191
205
|
// Get curren value of the component
|
|
192
206
|
const compSchema = entity.get("position");
|
|
207
|
+
|
|
208
|
+
entity.id // Returns unique entity id from proxy
|
|
209
|
+
|
|
193
210
|
```
|
|
194
211
|
|
|
195
212
|
### System
|
|
@@ -199,7 +216,7 @@ Systems contain the game logic that processes entities with specific components.
|
|
|
199
216
|
```typescript
|
|
200
217
|
interface System {
|
|
201
218
|
priority: number; // Execution order (lower = earlier)
|
|
202
|
-
init?(): void // Runs when added to the world
|
|
219
|
+
init?(): void; // Runs when added to the world
|
|
203
220
|
exit?(): void; // Cleanup when removed
|
|
204
221
|
update(): void; // Main update logic
|
|
205
222
|
}
|
|
@@ -218,13 +235,13 @@ const renderSystem: System = {
|
|
|
218
235
|
update(dt) {
|
|
219
236
|
const renderableQuery = world.include("position", "sprite");
|
|
220
237
|
|
|
221
|
-
|
|
238
|
+
renderableQuery.entities.forEach((entity) => {
|
|
222
239
|
const position = entity.get<Position>("position");
|
|
223
240
|
const sprite = entity.get<Sprite>("sprite");
|
|
224
241
|
|
|
225
242
|
// Render entity
|
|
226
243
|
drawSprite(sprite, position.x, position.y);
|
|
227
|
-
}
|
|
244
|
+
})
|
|
228
245
|
},
|
|
229
246
|
|
|
230
247
|
exit() {
|
|
@@ -266,19 +283,36 @@ const complexQuery2 = world.include("position", "health").exclude("static");
|
|
|
266
283
|
#### Accessing Results
|
|
267
284
|
|
|
268
285
|
```typescript
|
|
269
|
-
// Iterate through entities
|
|
270
|
-
|
|
271
|
-
// Process
|
|
286
|
+
// Iterate through entities as proxy
|
|
287
|
+
query.entities.forEach((entity) => {
|
|
288
|
+
// Process Entity proxy
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
// Iterate through entities ids
|
|
292
|
+
for(const entityId of query.ids){
|
|
293
|
+
// Process Entity id
|
|
272
294
|
}
|
|
273
295
|
|
|
296
|
+
|
|
297
|
+
|
|
274
298
|
// Get the first value of the query
|
|
275
|
-
const first = query.entities
|
|
299
|
+
const first = query.entities[0];
|
|
300
|
+
const firstId = query.ids.first()
|
|
276
301
|
|
|
277
302
|
// Check query size
|
|
278
|
-
const count = query.
|
|
303
|
+
const count = query.size();
|
|
279
304
|
|
|
280
305
|
// Check if query has any entities
|
|
281
|
-
const isEmpty = query.
|
|
306
|
+
const isEmpty = query.size() === 0;
|
|
307
|
+
|
|
308
|
+
// Subscribe to query events
|
|
309
|
+
query.on("added", (entityId: number) => {
|
|
310
|
+
// Entity added
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
query.on("removed", (entityId: number) => {
|
|
314
|
+
// Entity removed
|
|
315
|
+
});
|
|
282
316
|
```
|
|
283
317
|
|
|
284
318
|
### SparseSet
|
|
@@ -315,7 +349,7 @@ sparseSet.clear();
|
|
|
315
349
|
Utility singleton class for managing time and delta time calculations.
|
|
316
350
|
|
|
317
351
|
```typescript
|
|
318
|
-
import { Time } from "@jael/core";
|
|
352
|
+
import { Time } from "@jael-ecs/core";
|
|
319
353
|
|
|
320
354
|
Time.start();
|
|
321
355
|
|
|
@@ -342,6 +376,11 @@ interface WorldEvents {
|
|
|
342
376
|
updated: void;
|
|
343
377
|
}
|
|
344
378
|
|
|
379
|
+
interface QueryEvents {
|
|
380
|
+
added: number; //EntityId added to query entities
|
|
381
|
+
removed: number; //EntityId removed to query entities
|
|
382
|
+
}
|
|
383
|
+
|
|
345
384
|
// Listen to events
|
|
346
385
|
world.on("entityCreated", (data) => {
|
|
347
386
|
// Handle event
|
|
@@ -354,7 +393,7 @@ world.emit("entityCreated", { entity: someEntity });
|
|
|
354
393
|
world.off("entityCreated", handler);
|
|
355
394
|
|
|
356
395
|
// Romeve all listeners of a type
|
|
357
|
-
world.clearEvent(
|
|
396
|
+
world.clearEvent("type");
|
|
358
397
|
|
|
359
398
|
// Remove all listeners
|
|
360
399
|
world.clearAllEvents();
|
|
@@ -410,8 +449,8 @@ class MovementSystem implements System {
|
|
|
410
449
|
}
|
|
411
450
|
|
|
412
451
|
update() {
|
|
413
|
-
for
|
|
414
|
-
// Process movement
|
|
452
|
+
for(const entityId of this.movementQuery.ids){
|
|
453
|
+
// Process movement using entityId
|
|
415
454
|
}
|
|
416
455
|
}
|
|
417
456
|
}
|
|
@@ -423,13 +462,13 @@ type MovementSystem = { movementQuery: Query | null } & System;
|
|
|
423
462
|
const movementSystem: MovementSystem = {
|
|
424
463
|
movementQuery: null;
|
|
425
464
|
priority: 1;
|
|
426
|
-
|
|
465
|
+
|
|
427
466
|
init(){
|
|
428
467
|
this.movementQuery = world.include('position', 'velocity');
|
|
429
468
|
}
|
|
430
469
|
|
|
431
470
|
update(){
|
|
432
|
-
for (const
|
|
471
|
+
for (const entityId of this.movementQuery.ids) {
|
|
433
472
|
// Process movement
|
|
434
473
|
}
|
|
435
474
|
}
|
|
@@ -446,7 +485,7 @@ update() {
|
|
|
446
485
|
|
|
447
486
|
```typescript
|
|
448
487
|
// Remember to clean up when removing entities
|
|
449
|
-
world.destroy(
|
|
488
|
+
world.destroy(entityId); // Automatically removes all components
|
|
450
489
|
|
|
451
490
|
// Clean up systems if they have resources
|
|
452
491
|
system.exit?.(); // Called automatically when removed from world
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { Entity } from './EntityManager';
|
|
2
1
|
import { default as EventRegistry } from './EventRegistry';
|
|
3
2
|
import { default as World } from './World';
|
|
4
3
|
export type ComponentSchema = Record<string, any>;
|
|
5
4
|
export interface ComponentManagerEvents {
|
|
6
5
|
add: {
|
|
7
|
-
|
|
6
|
+
entityId: number;
|
|
8
7
|
component: keyof ComponentSchema;
|
|
9
8
|
};
|
|
10
9
|
remove: {
|
|
11
|
-
|
|
10
|
+
entityId: number;
|
|
12
11
|
component: keyof ComponentSchema;
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
export declare class ComponentManager extends EventRegistry<ComponentManagerEvents> {
|
|
16
|
-
componentSet:
|
|
15
|
+
componentSet: {
|
|
16
|
+
[k: number]: ComponentSchema;
|
|
17
|
+
};
|
|
17
18
|
world: World;
|
|
18
19
|
constructor(world: World);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
clearComponentSchema(entityId: number): void;
|
|
21
|
+
addComponent<K extends keyof ComponentSchema>(entityId: number, key: K, value: ComponentSchema[K]): void;
|
|
22
|
+
getComponent<K extends keyof ComponentSchema>(entityId: number, key: K): ComponentSchema[K] | undefined;
|
|
23
|
+
hasComponent<K extends keyof ComponentSchema>(entityId: number, key: K): boolean;
|
|
24
|
+
removeComponent<K extends keyof ComponentSchema>(entityId: number, key: K): void;
|
|
23
25
|
}
|
package/dist/EntityManager.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as EventRegistry } from './EventRegistry';
|
|
2
2
|
import { SparseSet } from './SparseSet';
|
|
3
3
|
import { default as World } from './World';
|
|
4
|
-
declare class Entity {
|
|
4
|
+
export declare class Entity {
|
|
5
5
|
readonly id: number;
|
|
6
6
|
private _world;
|
|
7
7
|
constructor(world: World, id: number);
|
|
@@ -30,18 +30,17 @@ declare class Entity {
|
|
|
30
30
|
get<T = any>(compType: string): T;
|
|
31
31
|
}
|
|
32
32
|
export declare class EntityManager extends EventRegistry<EntityManagerEvents> {
|
|
33
|
-
entityMap: SparseSet<
|
|
33
|
+
entityMap: SparseSet<number>;
|
|
34
34
|
nextId: number;
|
|
35
35
|
_world: World;
|
|
36
36
|
constructor(world: World);
|
|
37
|
-
get entities(): SparseSet<
|
|
38
|
-
create():
|
|
39
|
-
exist(
|
|
37
|
+
get entities(): SparseSet<number>;
|
|
38
|
+
create(): number;
|
|
39
|
+
exist(id: number): boolean;
|
|
40
40
|
size(): number;
|
|
41
|
-
destroy(
|
|
41
|
+
destroy(id: number): number;
|
|
42
42
|
}
|
|
43
43
|
export interface EntityManagerEvents {
|
|
44
|
-
create:
|
|
45
|
-
destroy:
|
|
44
|
+
create: number;
|
|
45
|
+
destroy: number;
|
|
46
46
|
}
|
|
47
|
-
export { type Entity };
|
package/dist/EventRegistry.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
export type Event<
|
|
2
|
-
|
|
1
|
+
export type Event<V> = {
|
|
2
|
+
[key: string]: V;
|
|
3
|
+
};
|
|
4
|
+
export type EventCallback<V> = (event: V[keyof V]) => void;
|
|
5
|
+
export default class EventRegistry<E extends Event<any> = {}> {
|
|
3
6
|
private _listeners;
|
|
4
|
-
on(type: keyof E, callback:
|
|
5
|
-
off(type: keyof E, callback:
|
|
6
|
-
once(type: keyof E, callback:
|
|
7
|
+
on(type: keyof E, callback: EventCallback<E>): void;
|
|
8
|
+
off(type: keyof E, callback: EventCallback<E>): void;
|
|
9
|
+
once(type: keyof E, callback: EventCallback<E>): void;
|
|
7
10
|
clearEvent(type: keyof E): void;
|
|
8
11
|
clearAllEvents(): void;
|
|
9
|
-
contains(type: keyof E, callback:
|
|
12
|
+
contains(type: keyof E, callback: EventCallback<E>): boolean;
|
|
10
13
|
emit(type: keyof E, data: E[keyof E]): void;
|
|
11
14
|
}
|
package/dist/Query.d.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { Entity } from './EntityManager';
|
|
2
|
+
import { default as EventRegistry } from './EventRegistry';
|
|
2
3
|
import { SparseSet } from './SparseSet';
|
|
3
4
|
import { default as World } from './World';
|
|
4
5
|
export interface QueryConfig {
|
|
5
6
|
include: string[];
|
|
6
7
|
exclude: string[];
|
|
7
8
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export interface QueryEvents {
|
|
10
|
+
added: number;
|
|
11
|
+
removed: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class Query extends EventRegistry<QueryEvents> {
|
|
14
|
+
private config;
|
|
15
|
+
private entityMap;
|
|
16
|
+
private entityInstancesCache;
|
|
17
|
+
private world;
|
|
12
18
|
constructor(config: QueryConfig, world: World);
|
|
13
|
-
hasComponents(
|
|
14
|
-
|
|
19
|
+
hasComponents(entityId: number): boolean;
|
|
20
|
+
size(): number;
|
|
21
|
+
get hash(): number;
|
|
22
|
+
get ids(): SparseSet<number>;
|
|
23
|
+
private getCachedEntity;
|
|
24
|
+
get entities(): Entity[];
|
|
15
25
|
include(...comps: string[]): Query;
|
|
16
26
|
exclude(...comps: string[]): Query;
|
|
17
27
|
private _checkExistingEntities;
|
package/dist/World.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentManager, ComponentSchema } from './ComponentManager';
|
|
2
|
-
import {
|
|
2
|
+
import { Entity, EntityManager } from './EntityManager';
|
|
3
3
|
import { default as EventRegistry } from './EventRegistry';
|
|
4
4
|
import { Query, QueryConfig } from './Query';
|
|
5
5
|
import { SparseSet } from './SparseSet';
|
|
@@ -27,17 +27,19 @@ export default class World extends EventRegistry<WorldEvents> {
|
|
|
27
27
|
systemManager: SystemManager;
|
|
28
28
|
queries: Map<number, Query>;
|
|
29
29
|
constructor();
|
|
30
|
-
|
|
30
|
+
getEntity(id: number): Entity | undefined;
|
|
31
|
+
get entityIds(): SparseSet<number>;
|
|
31
32
|
query(config: QueryConfig): Query;
|
|
32
33
|
private _updateQueries;
|
|
33
|
-
exist(
|
|
34
|
+
exist(entityId: number): boolean;
|
|
34
35
|
include(...comps: string[]): Query;
|
|
35
36
|
exclude(...comps: string[]): Query;
|
|
36
|
-
create():
|
|
37
|
-
destroy(
|
|
37
|
+
create(): number;
|
|
38
|
+
destroy(entityId: number): void;
|
|
38
39
|
addSystem(sys: System): void;
|
|
39
40
|
removeSystem(sys: System): void;
|
|
40
|
-
addComponent(
|
|
41
|
-
|
|
41
|
+
addComponent(entityId: number, compKey: string, compValue: any): void;
|
|
42
|
+
getComponent<T>(entityId: number, compKey: string): T;
|
|
43
|
+
removeComponent(entityId: number, compKey: string): void;
|
|
42
44
|
update(): void;
|
|
43
45
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { default as EventRegistry } from './EventRegistry';
|
|
|
2
2
|
import { System, SystemManager } from './SystemManager';
|
|
3
3
|
import { Entity, EntityManager, EntityManagerEvents } from './EntityManager';
|
|
4
4
|
import { ComponentSchema, ComponentManager, ComponentManagerEvents } from './ComponentManager';
|
|
5
|
-
import { Query, QueryConfig } from './Query';
|
|
5
|
+
import { Query, QueryConfig, QueryEvents } from './Query';
|
|
6
6
|
import { SparseSet } from './SparseSet';
|
|
7
7
|
import { Time, TimeEvents } from './Time';
|
|
8
8
|
import { default as World, WorldEvents } from './World';
|
|
9
|
-
export { type System, type Entity, type EntityManagerEvents, type ComponentManagerEvents, type ComponentSchema, type QueryConfig, type TimeEvents, type WorldEvents, Query, World, Time, SparseSet, EventRegistry, SystemManager, EntityManager, ComponentManager, };
|
|
9
|
+
export { type System, type Entity, type EntityManagerEvents, type ComponentManagerEvents, type ComponentSchema, type QueryConfig, type QueryEvents, type TimeEvents, type WorldEvents, Query, World, Time, SparseSet, EventRegistry, SystemManager, EntityManager, ComponentManager, };
|
package/dist/jael-build.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o{_listeners=new Map;on(e,t){if(this.contains(e,t))return;const s=this._listeners.get(e);s?s.add(t):this._listeners.set(e,new Set([t]))}off(e,t){if(!this.contains(e,t))return;const s=this._listeners.get(e);s&&s.delete(t)}once(e,t){const s=(n=>{t(n),this.off(e,s)});this.on(e,s)}clearEvent(e){this._listeners.get(e)&&this._listeners.get(e)?.clear()}clearAllEvents(){this._listeners.forEach(e=>e.clear()),this._listeners.clear()}contains(e,t){return this._listeners.get(e)?this._listeners.get(e).has(t):!1}emit(e,t){this._listeners.get(e)&&this._listeners.get(e)?.forEach(s=>{s(t)})}}class d{systemList=[];addSystem(e){this.systemList.push(e),e.init?.(),this.reorder()}reorder(){this.systemList.sort((e,t)=>e.priority-t.priority)}has(e){return this.systemList.indexOf(e)>0}removeSystem(e){if(!this.has(e))return;const t=this.systemList.indexOf(e);t>=0&&(this.systemList.splice(t,1),e.exit?.(),this.reorder())}}class c{denseValues=[];sparse=new Map;[Symbol.iterator](){let e=this.values.length;const t={value:void 0,done:!1};return{next:()=>(t.value=this.values[--e],t.done=e<0,t)}}get values(){return this.denseValues}first(){return this.denseValues[0]}add(e){this.has(e)||(this.denseValues.push(e),this.sparse.set(e,this.denseValues.length-1))}indexOf(e){const t=this.sparse.get(e);return t!==void 0?t:-1}remove(e){if(!this.has(e))return;const t=this.sparse.get(e);this.sparse.delete(e);const s=this.denseValues[this.denseValues.length-1];s!==e&&(this.denseValues[t]=s,this.sparse.set(s,t)),this.denseValues.pop()}forEach(e){for(let t of this)e(t)}size(){return this.denseValues.length}clear(){for(let e of this)this.remove(e)}has(e){return this.sparse.has(e)}}class m{id;_world;constructor(e,t){this.id=t,this._world=e}add(e,t){this._world.addComponent(this.id,e,t)}remove(e){this._world.removeComponent(this.id,e)}has(e){return this._world.componentManager.hasComponent(this.id,e)}get(e){return this._world.componentManager.getComponent(this.id,e)}}class u extends o{entityMap=new c;nextId=0;_world;constructor(e){super(),this._world=e}get entities(){return this.entityMap}create(){const e=this.nextId++;return this.entities.add(e),this.emit("create",e),e}exist(e){return this.entities.has(e)}size(){return this.entities.size()}destroy(e){return this.entities.remove(e),this.emit("destroy",e),e}}class l extends o{componentSet={};world;constructor(e){super(),this.world=e}clearComponentSchema(e){this.componentSet[e]&&delete this.componentSet[e]}addComponent(e,t,s){const n=this.componentSet[e];n?n[t]=s:this.componentSet[e]={[t]:s},this.emit("add",{entityId:e,component:t})}getComponent(e,t){if(this.hasComponent(e,t))return this.componentSet[e][t]}hasComponent(e,t){const s=this.componentSet[e];return s?t in s:!1}removeComponent(e,t){if(!this.componentSet[e])return;const s=this.componentSet[e];s&&s[t]!==void 0&&(delete s[t],Object.keys(s).length===0&&delete this.componentSet[e],this.emit("remove",{entityId:e,component:t}))}}class a extends o{config;entityMap;entityInstancesCache;world;constructor(e,t){super(),this.config=e,this.world=t,this.entityInstancesCache=new Map,this.entityMap=new c,this.on("removed",s=>{this.entityInstancesCache.delete(s)})}hasComponents(e){const t=this.world.componentManager;return this.config.include?.every(s=>t.getComponent(e,s))&&this.config.exclude?.every(s=>!t.getComponent(e,s))}size(){return this.ids.size()}get hash(){return a.getHash(this.config)}get ids(){return this.entityMap}getCachedEntity(e){const t=this.entityInstancesCache.get(e);if(t)return t;{const s=this.world.getEntity(e);return s?(this.entityInstancesCache.set(e,s),s):void 0}}get entities(){const e=[],t=this.entityMap.size()>100;return this.entityMap.forEach(s=>{if(t){const n=this.getCachedEntity(s);n&&e.push(n)}else{const n=this.world.getEntity(s);n&&e.push(n)}}),e}include(...e){return this.world.include(...e)}exclude(...e){return this.world.exclude(...e)}_checkExistingEntities(){for(let e of this.ids)this.world.exist(e)||(this.emit("removed",e),this.entityMap.remove(e))}checkEntities(){this.entityInstancesCache.clear();for(let e of this.world.entityIds)this.hasComponents(e)&&(this.entityMap.add(e),this.emit("added",e));this._checkExistingEntities()}static getHash(e){const t=e.include?.map(i=>i.trim()).filter(i=>i).join("_"),s=e.exclude?.map(i=>i.trim()).filter(i=>i).join("_"),n="in_"+t+"_out_"+s;let h=0;for(const i of n)h=(h<<5)-h+i.charCodeAt(0),h|=0;return h}}class p extends o{_startTime=0;_oldTime=0;_requestId=0;running=!1;delta=0;elapsed=0;constructor(){super()}_loop(){let e=0;if(this.running){const t=performance.now();e=(t-this._oldTime)/1e3,this._oldTime=t,this.elapsed+=e}this.delta=e,this.emit("update"),this._requestId=requestAnimationFrame(this._loop.bind(this))}start(){this._startTime=performance.now(),this._oldTime=this._startTime,this.elapsed=0,this.delta=0,this.running=!0,this._loop()}stop(){this.running=!1,cancelAnimationFrame(this._requestId),this._requestId=0}}let g=new p;class f extends o{entityManager;componentManager;systemManager;queries;constructor(){super(),this.entityManager=new u(this),this.componentManager=new l(this),this.systemManager=new d,this.entityManager.on("create",e=>{const t=this.getEntity(e);t&&(this.emit("entityCreated",{entity:t}),this._updateQueries())}),this.entityManager.on("destroy",e=>{const t=this.getEntity(e);t&&(this.emit("entityCreated",{entity:t}),this._updateQueries(),this.componentManager.clearComponentSchema(e))}),this.componentManager.on("add",e=>{const t=this.getEntity(e.entityId);t&&(this.emit("componentAdded",{entity:t,component:e.component}),this._updateQueries())}),this.componentManager.on("remove",e=>{const t=this.getEntity(e.entityId);t&&(this.emit("componentRemoved",{entity:t,component:e.component}),this._updateQueries())}),this.queries=new Map}getEntity(e){if(this.entityManager.exist(e))return new m(this,e)}get entityIds(){return this.entityManager.entities}query(e){const t=a.getHash(e);let n=this.queries.get(t);return n||(n=new a(e,this),this.queries.set(t,n),this._updateQueries()),n}_updateQueries(){this.queries.forEach(e=>e.checkEntities())}exist(e){return this.entityManager.exist(e)}include(...e){return this.query({include:e,exclude:[]})}exclude(...e){return this.query({include:[],exclude:e})}create(){return this.entityManager.create()}destroy(e){this.entityManager.destroy(e)}addSystem(e){this.systemManager.addSystem(e)}removeSystem(e){this.systemManager.removeSystem(e)}addComponent(e,t,s){this.componentManager.addComponent(e,t,s)}getComponent(e,t){return this.componentManager.getComponent(e,t)}removeComponent(e,t){this.componentManager.removeComponent(e,t)}update(){this.systemManager.systemList.forEach(e=>{e.update()}),this.emit("updated")}}exports.ComponentManager=l;exports.EntityManager=u;exports.EventRegistry=o;exports.Query=a;exports.SparseSet=c;exports.SystemManager=d;exports.Time=g;exports.World=f;
|
package/dist/jael-build.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
1
|
class h {
|
|
2
2
|
_listeners = /* @__PURE__ */ new Map();
|
|
3
|
-
on(
|
|
4
|
-
if (this.contains(
|
|
3
|
+
on(t, e) {
|
|
4
|
+
if (this.contains(t, e))
|
|
5
5
|
return;
|
|
6
|
-
const s = this._listeners.get(
|
|
7
|
-
s ? s.add(
|
|
6
|
+
const s = this._listeners.get(t);
|
|
7
|
+
s ? s.add(e) : this._listeners.set(t, /* @__PURE__ */ new Set([e]));
|
|
8
8
|
}
|
|
9
|
-
off(
|
|
10
|
-
if (!this.contains(
|
|
9
|
+
off(t, e) {
|
|
10
|
+
if (!this.contains(t, e))
|
|
11
11
|
return;
|
|
12
|
-
const s = this._listeners.get(
|
|
13
|
-
s && s.delete(
|
|
12
|
+
const s = this._listeners.get(t);
|
|
13
|
+
s && s.delete(e);
|
|
14
14
|
}
|
|
15
|
-
once(
|
|
16
|
-
const s = ((
|
|
17
|
-
|
|
15
|
+
once(t, e) {
|
|
16
|
+
const s = ((n) => {
|
|
17
|
+
e(n), this.off(t, s);
|
|
18
18
|
});
|
|
19
|
-
this.on(
|
|
19
|
+
this.on(t, s);
|
|
20
20
|
}
|
|
21
|
-
clearEvent(
|
|
22
|
-
this._listeners.get(
|
|
21
|
+
clearEvent(t) {
|
|
22
|
+
this._listeners.get(t) && this._listeners.get(t)?.clear();
|
|
23
23
|
}
|
|
24
24
|
clearAllEvents() {
|
|
25
|
-
this._listeners.forEach((
|
|
25
|
+
this._listeners.forEach((t) => t.clear()), this._listeners.clear();
|
|
26
26
|
}
|
|
27
|
-
contains(
|
|
28
|
-
return this._listeners.get(
|
|
27
|
+
contains(t, e) {
|
|
28
|
+
return this._listeners.get(t) ? this._listeners.get(t).has(e) : !1;
|
|
29
29
|
}
|
|
30
|
-
emit(
|
|
31
|
-
this._listeners.get(
|
|
32
|
-
s(
|
|
30
|
+
emit(t, e) {
|
|
31
|
+
this._listeners.get(t) && this._listeners.get(t)?.forEach((s) => {
|
|
32
|
+
s(e);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class
|
|
36
|
+
class d {
|
|
37
37
|
systemList = [];
|
|
38
|
-
addSystem(
|
|
39
|
-
this.systemList.push(
|
|
38
|
+
addSystem(t) {
|
|
39
|
+
this.systemList.push(t), t.init?.(), this.reorder();
|
|
40
40
|
}
|
|
41
41
|
reorder() {
|
|
42
|
-
this.systemList.sort((
|
|
42
|
+
this.systemList.sort((t, e) => t.priority - e.priority);
|
|
43
43
|
}
|
|
44
|
-
has(
|
|
45
|
-
return this.systemList.indexOf(
|
|
44
|
+
has(t) {
|
|
45
|
+
return this.systemList.indexOf(t) > 0;
|
|
46
46
|
}
|
|
47
|
-
removeSystem(
|
|
48
|
-
if (!this.has(
|
|
49
|
-
const
|
|
50
|
-
|
|
47
|
+
removeSystem(t) {
|
|
48
|
+
if (!this.has(t)) return;
|
|
49
|
+
const e = this.systemList.indexOf(t);
|
|
50
|
+
e >= 0 && (this.systemList.splice(e, 1), t.exit?.(), this.reorder());
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
class
|
|
53
|
+
class c {
|
|
54
54
|
denseValues = [];
|
|
55
55
|
sparse = /* @__PURE__ */ new Map();
|
|
56
56
|
[Symbol.iterator]() {
|
|
57
|
-
let
|
|
58
|
-
const
|
|
57
|
+
let t = this.values.length;
|
|
58
|
+
const e = {
|
|
59
59
|
value: void 0,
|
|
60
60
|
done: !1
|
|
61
61
|
};
|
|
62
62
|
return {
|
|
63
|
-
next: () => (
|
|
63
|
+
next: () => (e.value = this.values[--t], e.done = t < 0, e)
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
get values() {
|
|
@@ -69,156 +69,193 @@ class d {
|
|
|
69
69
|
first() {
|
|
70
70
|
return this.denseValues[0];
|
|
71
71
|
}
|
|
72
|
-
add(
|
|
73
|
-
this.has(
|
|
72
|
+
add(t) {
|
|
73
|
+
this.has(t) || (this.denseValues.push(t), this.sparse.set(t, this.denseValues.length - 1));
|
|
74
74
|
}
|
|
75
|
-
indexOf(
|
|
76
|
-
|
|
75
|
+
indexOf(t) {
|
|
76
|
+
const e = this.sparse.get(t);
|
|
77
|
+
return e !== void 0 ? e : -1;
|
|
77
78
|
}
|
|
78
|
-
remove(
|
|
79
|
-
if (!this.has(
|
|
80
|
-
const
|
|
81
|
-
this.sparse.delete(
|
|
79
|
+
remove(t) {
|
|
80
|
+
if (!this.has(t)) return;
|
|
81
|
+
const e = this.sparse.get(t);
|
|
82
|
+
this.sparse.delete(t);
|
|
82
83
|
const s = this.denseValues[this.denseValues.length - 1];
|
|
83
|
-
s !==
|
|
84
|
+
s !== t && (this.denseValues[e] = s, this.sparse.set(s, e)), this.denseValues.pop();
|
|
84
85
|
}
|
|
85
|
-
forEach(
|
|
86
|
-
for (let
|
|
87
|
-
e
|
|
86
|
+
forEach(t) {
|
|
87
|
+
for (let e of this)
|
|
88
|
+
t(e);
|
|
88
89
|
}
|
|
89
90
|
size() {
|
|
90
91
|
return this.denseValues.length;
|
|
91
92
|
}
|
|
92
93
|
clear() {
|
|
93
|
-
for (let
|
|
94
|
-
this.remove(
|
|
94
|
+
for (let t of this)
|
|
95
|
+
this.remove(t);
|
|
95
96
|
}
|
|
96
|
-
has(
|
|
97
|
-
return this.sparse.has(
|
|
97
|
+
has(t) {
|
|
98
|
+
return this.sparse.has(t);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
class
|
|
101
|
+
class u {
|
|
101
102
|
id;
|
|
102
103
|
_world;
|
|
103
|
-
constructor(
|
|
104
|
-
this.id =
|
|
104
|
+
constructor(t, e) {
|
|
105
|
+
this.id = e, this._world = t;
|
|
105
106
|
}
|
|
106
107
|
/**
|
|
107
108
|
* Add component to current entity.
|
|
108
109
|
* @param compType Component name
|
|
109
110
|
* @param compValue Component value
|
|
110
111
|
*/
|
|
111
|
-
add(
|
|
112
|
-
this._world.addComponent(this,
|
|
112
|
+
add(t, e) {
|
|
113
|
+
this._world.addComponent(this.id, t, e);
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Remove component of current entity.
|
|
116
117
|
* @param compType Component name
|
|
117
118
|
*/
|
|
118
|
-
remove(
|
|
119
|
-
this._world.removeComponent(this,
|
|
119
|
+
remove(t) {
|
|
120
|
+
this._world.removeComponent(this.id, t);
|
|
120
121
|
}
|
|
121
122
|
/**
|
|
122
123
|
* Check if current entity has a component.
|
|
123
124
|
* @param compType Component name
|
|
124
125
|
* @returns boolean
|
|
125
126
|
*/
|
|
126
|
-
has(
|
|
127
|
-
return this._world.componentManager.hasComponent(this,
|
|
127
|
+
has(t) {
|
|
128
|
+
return this._world.componentManager.hasComponent(this.id, t);
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Get passed component schema of current entity.
|
|
131
132
|
* @param compType Component name
|
|
132
133
|
* @returns Return component schema with T(any as default) as type
|
|
133
134
|
*/
|
|
134
|
-
get(
|
|
135
|
-
return this._world.componentManager.getComponent(this,
|
|
135
|
+
get(t) {
|
|
136
|
+
return this._world.componentManager.getComponent(this.id, t);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
class l extends h {
|
|
139
|
-
entityMap = new
|
|
140
|
+
entityMap = new c();
|
|
140
141
|
nextId = 0;
|
|
141
142
|
_world;
|
|
142
|
-
constructor(
|
|
143
|
-
super(), this._world =
|
|
143
|
+
constructor(t) {
|
|
144
|
+
super(), this._world = t;
|
|
144
145
|
}
|
|
145
146
|
get entities() {
|
|
146
147
|
return this.entityMap;
|
|
147
148
|
}
|
|
148
149
|
create() {
|
|
149
|
-
const
|
|
150
|
+
const t = this.nextId++;
|
|
150
151
|
return this.entities.add(t), this.emit("create", t), t;
|
|
151
152
|
}
|
|
152
|
-
exist(
|
|
153
|
-
return this.entities.has(
|
|
153
|
+
exist(t) {
|
|
154
|
+
return this.entities.has(t);
|
|
154
155
|
}
|
|
155
156
|
size() {
|
|
156
157
|
return this.entities.size();
|
|
157
158
|
}
|
|
158
|
-
destroy(
|
|
159
|
-
return this.entities.remove(
|
|
159
|
+
destroy(t) {
|
|
160
|
+
return this.entities.remove(t), this.emit("destroy", t), t;
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
class m extends h {
|
|
163
|
-
componentSet =
|
|
164
|
+
componentSet = {};
|
|
164
165
|
world;
|
|
165
|
-
constructor(
|
|
166
|
-
super(), this.world =
|
|
167
|
-
t && t.entity && this.componentSet.get(t.entity.id) && this.componentSet.delete(t.entity.id);
|
|
168
|
-
});
|
|
166
|
+
constructor(t) {
|
|
167
|
+
super(), this.world = t;
|
|
169
168
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
clearComponentSchema(t) {
|
|
170
|
+
this.componentSet[t] && delete this.componentSet[t];
|
|
171
|
+
}
|
|
172
|
+
addComponent(t, e, s) {
|
|
173
|
+
const n = this.componentSet[t];
|
|
174
|
+
n ? n[e] = s : this.componentSet[t] = { [e]: s }, this.emit("add", { entityId: t, component: e });
|
|
175
175
|
}
|
|
176
|
-
getComponent(
|
|
177
|
-
|
|
176
|
+
getComponent(t, e) {
|
|
177
|
+
if (this.hasComponent(t, e))
|
|
178
|
+
return this.componentSet[t][e];
|
|
178
179
|
}
|
|
179
|
-
hasComponent(
|
|
180
|
-
const s = this.componentSet
|
|
181
|
-
return s ?
|
|
180
|
+
hasComponent(t, e) {
|
|
181
|
+
const s = this.componentSet[t];
|
|
182
|
+
return s ? e in s : !1;
|
|
182
183
|
}
|
|
183
|
-
removeComponent(
|
|
184
|
-
if (!this.componentSet
|
|
185
|
-
const s = this.componentSet
|
|
186
|
-
s && s[
|
|
184
|
+
removeComponent(t, e) {
|
|
185
|
+
if (!this.componentSet[t]) return;
|
|
186
|
+
const s = this.componentSet[t];
|
|
187
|
+
s && s[e] !== void 0 && (delete s[e], Object.keys(s).length === 0 && delete this.componentSet[t], this.emit("remove", { entityId: t, component: e }));
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
class a {
|
|
190
|
+
class a extends h {
|
|
190
191
|
config;
|
|
191
192
|
entityMap;
|
|
193
|
+
entityInstancesCache;
|
|
192
194
|
world;
|
|
193
|
-
constructor(
|
|
194
|
-
this.config =
|
|
195
|
+
constructor(t, e) {
|
|
196
|
+
super(), this.config = t, this.world = e, this.entityInstancesCache = /* @__PURE__ */ new Map(), this.entityMap = new c(), this.on("removed", (s) => {
|
|
197
|
+
this.entityInstancesCache.delete(s);
|
|
198
|
+
});
|
|
195
199
|
}
|
|
196
|
-
hasComponents(
|
|
197
|
-
|
|
200
|
+
hasComponents(t) {
|
|
201
|
+
const e = this.world.componentManager;
|
|
202
|
+
return this.config.include?.every(
|
|
203
|
+
(s) => e.getComponent(t, s)
|
|
204
|
+
) && this.config.exclude?.every(
|
|
205
|
+
(s) => !e.getComponent(t, s)
|
|
206
|
+
);
|
|
198
207
|
}
|
|
199
|
-
|
|
208
|
+
size() {
|
|
209
|
+
return this.ids.size();
|
|
210
|
+
}
|
|
211
|
+
get hash() {
|
|
212
|
+
return a.getHash(this.config);
|
|
213
|
+
}
|
|
214
|
+
get ids() {
|
|
200
215
|
return this.entityMap;
|
|
201
216
|
}
|
|
202
|
-
|
|
203
|
-
|
|
217
|
+
getCachedEntity(t) {
|
|
218
|
+
const e = this.entityInstancesCache.get(t);
|
|
219
|
+
if (e)
|
|
220
|
+
return e;
|
|
221
|
+
{
|
|
222
|
+
const s = this.world.getEntity(t);
|
|
223
|
+
return s ? (this.entityInstancesCache.set(t, s), s) : void 0;
|
|
224
|
+
}
|
|
204
225
|
}
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
get entities() {
|
|
227
|
+
const t = [], e = this.entityMap.size() > 100;
|
|
228
|
+
return this.entityMap.forEach((s) => {
|
|
229
|
+
if (e) {
|
|
230
|
+
const n = this.getCachedEntity(s);
|
|
231
|
+
n && t.push(n);
|
|
232
|
+
} else {
|
|
233
|
+
const n = this.world.getEntity(s);
|
|
234
|
+
n && t.push(n);
|
|
235
|
+
}
|
|
236
|
+
}), t;
|
|
237
|
+
}
|
|
238
|
+
include(...t) {
|
|
239
|
+
return this.world.include(...t);
|
|
240
|
+
}
|
|
241
|
+
exclude(...t) {
|
|
242
|
+
return this.world.exclude(...t);
|
|
207
243
|
}
|
|
208
244
|
_checkExistingEntities() {
|
|
209
|
-
for (let
|
|
210
|
-
this.world.exist(
|
|
245
|
+
for (let t of this.ids)
|
|
246
|
+
this.world.exist(t) || (this.emit("removed", t), this.entityMap.remove(t));
|
|
211
247
|
}
|
|
212
248
|
checkEntities() {
|
|
213
|
-
|
|
214
|
-
|
|
249
|
+
this.entityInstancesCache.clear();
|
|
250
|
+
for (let t of this.world.entityIds)
|
|
251
|
+
this.hasComponents(t) && (this.entityMap.add(t), this.emit("added", t));
|
|
215
252
|
this._checkExistingEntities();
|
|
216
253
|
}
|
|
217
|
-
static getHash(
|
|
218
|
-
const
|
|
254
|
+
static getHash(t) {
|
|
255
|
+
const e = t.include?.map((i) => i.trim()).filter((i) => i).join("_"), s = t.exclude?.map((i) => i.trim()).filter((i) => i).join("_"), n = "in_" + e + "_out_" + s;
|
|
219
256
|
let o = 0;
|
|
220
|
-
for (const
|
|
221
|
-
o = (o << 5) - o +
|
|
257
|
+
for (const i of n)
|
|
258
|
+
o = (o << 5) - o + i.charCodeAt(0), o |= 0;
|
|
222
259
|
return o;
|
|
223
260
|
}
|
|
224
261
|
}
|
|
@@ -233,12 +270,12 @@ class p extends h {
|
|
|
233
270
|
super();
|
|
234
271
|
}
|
|
235
272
|
_loop() {
|
|
236
|
-
let
|
|
273
|
+
let t = 0;
|
|
237
274
|
if (this.running) {
|
|
238
|
-
const
|
|
239
|
-
|
|
275
|
+
const e = performance.now();
|
|
276
|
+
t = (e - this._oldTime) / 1e3, this._oldTime = e, this.elapsed += t;
|
|
240
277
|
}
|
|
241
|
-
this.delta =
|
|
278
|
+
this.delta = t, this.emit("update"), this._requestId = requestAnimationFrame(this._loop.bind(this));
|
|
242
279
|
}
|
|
243
280
|
start() {
|
|
244
281
|
this._startTime = performance.now(), this._oldTime = this._startTime, this.elapsed = 0, this.delta = 0, this.running = !0, this._loop();
|
|
@@ -254,69 +291,80 @@ class f extends h {
|
|
|
254
291
|
systemManager;
|
|
255
292
|
queries;
|
|
256
293
|
constructor() {
|
|
257
|
-
super(), this.entityManager = new l(this), this.componentManager = new m(this), this.systemManager = new
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
294
|
+
super(), this.entityManager = new l(this), this.componentManager = new m(this), this.systemManager = new d(), this.entityManager.on("create", (t) => {
|
|
295
|
+
const e = this.getEntity(t);
|
|
296
|
+
e && (this.emit("entityCreated", { entity: e }), this._updateQueries());
|
|
297
|
+
}), this.entityManager.on("destroy", (t) => {
|
|
298
|
+
const e = this.getEntity(t);
|
|
299
|
+
e && (this.emit("entityCreated", { entity: e }), this._updateQueries(), this.componentManager.clearComponentSchema(t));
|
|
261
300
|
}), this.componentManager.on(
|
|
262
301
|
"add",
|
|
263
|
-
(
|
|
264
|
-
this.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
302
|
+
(t) => {
|
|
303
|
+
const e = this.getEntity(t.entityId);
|
|
304
|
+
e && (this.emit("componentAdded", {
|
|
305
|
+
entity: e,
|
|
306
|
+
component: t.component
|
|
307
|
+
}), this._updateQueries());
|
|
268
308
|
}
|
|
269
309
|
), this.componentManager.on(
|
|
270
310
|
"remove",
|
|
271
|
-
(
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
311
|
+
(t) => {
|
|
312
|
+
const e = this.getEntity(t.entityId);
|
|
313
|
+
e && (this.emit("componentRemoved", {
|
|
314
|
+
entity: e,
|
|
315
|
+
component: t.component
|
|
316
|
+
}), this._updateQueries());
|
|
276
317
|
}
|
|
277
318
|
), this.queries = /* @__PURE__ */ new Map();
|
|
278
319
|
}
|
|
279
|
-
|
|
320
|
+
getEntity(t) {
|
|
321
|
+
if (this.entityManager.exist(t))
|
|
322
|
+
return new u(this, t);
|
|
323
|
+
}
|
|
324
|
+
get entityIds() {
|
|
280
325
|
return this.entityManager.entities;
|
|
281
326
|
}
|
|
282
|
-
query(
|
|
283
|
-
const
|
|
284
|
-
let
|
|
285
|
-
return
|
|
327
|
+
query(t) {
|
|
328
|
+
const e = a.getHash(t);
|
|
329
|
+
let n = this.queries.get(e);
|
|
330
|
+
return n || (n = new a(t, this), this.queries.set(e, n), this._updateQueries()), n;
|
|
286
331
|
}
|
|
287
332
|
_updateQueries() {
|
|
288
|
-
this.queries.forEach((
|
|
333
|
+
this.queries.forEach((t) => t.checkEntities());
|
|
289
334
|
}
|
|
290
|
-
exist(
|
|
291
|
-
return this.entityManager.exist(
|
|
335
|
+
exist(t) {
|
|
336
|
+
return this.entityManager.exist(t);
|
|
292
337
|
}
|
|
293
|
-
include(...
|
|
294
|
-
return this.query({ include:
|
|
338
|
+
include(...t) {
|
|
339
|
+
return this.query({ include: t, exclude: [] });
|
|
295
340
|
}
|
|
296
|
-
exclude(...
|
|
297
|
-
return this.query({ include: [], exclude:
|
|
341
|
+
exclude(...t) {
|
|
342
|
+
return this.query({ include: [], exclude: t });
|
|
298
343
|
}
|
|
299
344
|
create() {
|
|
300
345
|
return this.entityManager.create();
|
|
301
346
|
}
|
|
302
|
-
destroy(
|
|
303
|
-
this.entityManager.destroy(
|
|
347
|
+
destroy(t) {
|
|
348
|
+
this.entityManager.destroy(t);
|
|
349
|
+
}
|
|
350
|
+
addSystem(t) {
|
|
351
|
+
this.systemManager.addSystem(t);
|
|
304
352
|
}
|
|
305
|
-
|
|
306
|
-
this.systemManager.
|
|
353
|
+
removeSystem(t) {
|
|
354
|
+
this.systemManager.removeSystem(t);
|
|
307
355
|
}
|
|
308
|
-
|
|
309
|
-
this.
|
|
356
|
+
addComponent(t, e, s) {
|
|
357
|
+
this.componentManager.addComponent(t, e, s);
|
|
310
358
|
}
|
|
311
|
-
|
|
312
|
-
this.componentManager.
|
|
359
|
+
getComponent(t, e) {
|
|
360
|
+
return this.componentManager.getComponent(t, e);
|
|
313
361
|
}
|
|
314
|
-
removeComponent(
|
|
315
|
-
this.componentManager.removeComponent(
|
|
362
|
+
removeComponent(t, e) {
|
|
363
|
+
this.componentManager.removeComponent(t, e);
|
|
316
364
|
}
|
|
317
365
|
update() {
|
|
318
|
-
this.systemManager.systemList.forEach((
|
|
319
|
-
|
|
366
|
+
this.systemManager.systemList.forEach((t) => {
|
|
367
|
+
t.update();
|
|
320
368
|
}), this.emit("updated");
|
|
321
369
|
}
|
|
322
370
|
}
|
|
@@ -325,8 +373,8 @@ export {
|
|
|
325
373
|
l as EntityManager,
|
|
326
374
|
h as EventRegistry,
|
|
327
375
|
a as Query,
|
|
328
|
-
|
|
329
|
-
|
|
376
|
+
c as SparseSet,
|
|
377
|
+
d as SystemManager,
|
|
330
378
|
g as Time,
|
|
331
379
|
f as World
|
|
332
380
|
};
|