@flare-engine/ecs 0.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.d.mts +216 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +349 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Grzegorz Otto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @flare-engine/ecs
|
|
2
|
+
|
|
3
|
+
Archetype-bitmask ECS — `World`, `Query` with `onEntityAdded` / `onEntityRemoved` signals, `defineComponent`, `defineSystem`, `definePrefab`, `FSM`. Built-in `Position` / `Velocity` / `Rotation` / `Scale` / `Parent` components. Max 32 component types per world.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/ecs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { World, defineComponent, Position, Velocity } from '@flare-engine/ecs';
|
|
15
|
+
|
|
16
|
+
const Health = defineComponent<{ hp: number }>('Health', { hp: 100 });
|
|
17
|
+
|
|
18
|
+
const world = new World();
|
|
19
|
+
const e = world.spawn();
|
|
20
|
+
world.add(e, Position, { x: 0, y: 0 });
|
|
21
|
+
world.add(e, Velocity, { x: 1, y: 0 });
|
|
22
|
+
world.add(e, Health);
|
|
23
|
+
|
|
24
|
+
const movers = world.query(Position, Velocity);
|
|
25
|
+
for (const id of movers) { /* ... */ }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
See [API spec](../../docs/design/api-specs.md#flare-engineecs--8kb-gzip) and [skill reference](../../.github/skills/flare-ecs/SKILL.md).
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Signal } from '@flare-engine/events';
|
|
2
|
+
import { Vec2 } from '@flare-engine/math';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Component definition and factory.
|
|
6
|
+
*
|
|
7
|
+
* Components are plain data objects. Each component type gets a unique
|
|
8
|
+
* bit for archetype-based query matching.
|
|
9
|
+
*/
|
|
10
|
+
/** A unique component definition. */
|
|
11
|
+
interface ComponentDef<T> {
|
|
12
|
+
/** Internal unique ID (auto-assigned). */
|
|
13
|
+
readonly id: number;
|
|
14
|
+
/** Bitmask for this component (1 << id). */
|
|
15
|
+
readonly bit: number;
|
|
16
|
+
/** Component name for debugging. */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Create a new instance with default values. */
|
|
19
|
+
create(): T;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Define a new component type.
|
|
23
|
+
*
|
|
24
|
+
* @param name Debug name for the component.
|
|
25
|
+
* @param defaults Factory function returning default values, or undefined for tag components.
|
|
26
|
+
*/
|
|
27
|
+
declare function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Reset the component ID counter. Only for testing.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
declare function _resetComponentIds(): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Query matches entities based on component archetypes.
|
|
36
|
+
*
|
|
37
|
+
* Uses bitmask matching: entity archetype & requiredMask === requiredMask
|
|
38
|
+
* and entity archetype & excludedMask === 0.
|
|
39
|
+
*/
|
|
40
|
+
declare class Query {
|
|
41
|
+
/** Bitmask of required components. */
|
|
42
|
+
readonly requiredMask: number;
|
|
43
|
+
/** Bitmask of excluded components. */
|
|
44
|
+
readonly excludedMask: number;
|
|
45
|
+
/** Fires when an entity is added to this query's results. */
|
|
46
|
+
readonly onEntityAdded: Signal<number>;
|
|
47
|
+
/** Fires when an entity is removed from this query's results. */
|
|
48
|
+
readonly onEntityRemoved: Signal<number>;
|
|
49
|
+
/** Sorted array of matching entity IDs. */
|
|
50
|
+
private entities;
|
|
51
|
+
/** Set for O(1) membership check. */
|
|
52
|
+
private entitySet;
|
|
53
|
+
constructor(requiredMask: number, excludedMask: number);
|
|
54
|
+
/** Check if an archetype matches this query. */
|
|
55
|
+
matches(archetype: number): boolean;
|
|
56
|
+
/** @internal — called by World when an entity's archetype changes. */
|
|
57
|
+
_check(entityId: number, archetype: number): void;
|
|
58
|
+
/** @internal — called by World when an entity is removed entirely. */
|
|
59
|
+
_remove(entityId: number): void;
|
|
60
|
+
/** Iterate matching entity IDs. */
|
|
61
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
62
|
+
/** Number of matching entities. */
|
|
63
|
+
get count(): number;
|
|
64
|
+
/** Check if an entity matches this query. */
|
|
65
|
+
has(entityId: number): boolean;
|
|
66
|
+
}
|
|
67
|
+
/** Builder for creating queries with .with() / .without() chaining. */
|
|
68
|
+
declare class QueryBuilder {
|
|
69
|
+
private required;
|
|
70
|
+
private excluded;
|
|
71
|
+
with(...components: ComponentDef<unknown>[]): this;
|
|
72
|
+
without(...components: ComponentDef<unknown>[]): this;
|
|
73
|
+
/** Build the query (called internally by World). */
|
|
74
|
+
build(): Query;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* World is the central ECS container.
|
|
79
|
+
*
|
|
80
|
+
* Entities are integer IDs. Components are stored in per-component Maps.
|
|
81
|
+
* Archetype bitmasks enable fast query matching.
|
|
82
|
+
*/
|
|
83
|
+
declare class World {
|
|
84
|
+
private nextId;
|
|
85
|
+
private archetypes;
|
|
86
|
+
private componentStores;
|
|
87
|
+
private queries;
|
|
88
|
+
private systems;
|
|
89
|
+
private systemsSorted;
|
|
90
|
+
/** Create a new entity. Returns the entity ID. */
|
|
91
|
+
spawn(): number;
|
|
92
|
+
/** Remove an entity and all its components. */
|
|
93
|
+
destroy(entityId: number): void;
|
|
94
|
+
/** Add a component to an entity. */
|
|
95
|
+
add<T>(entityId: number, def: ComponentDef<T>, data?: T): void;
|
|
96
|
+
/** Remove a component from an entity. */
|
|
97
|
+
remove<T>(entityId: number, def: ComponentDef<T>): void;
|
|
98
|
+
/** Get component data for an entity. */
|
|
99
|
+
get<T>(entityId: number, def: ComponentDef<T>): T | undefined;
|
|
100
|
+
/** Check if entity has a component. */
|
|
101
|
+
has(entityId: number, def: ComponentDef<unknown>): boolean;
|
|
102
|
+
/** Check if entity exists. */
|
|
103
|
+
exists(entityId: number): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Create a query. Queries auto-update as entities change.
|
|
106
|
+
* Use the QueryBuilder-style chaining:
|
|
107
|
+
* world.query(Position, Velocity)
|
|
108
|
+
* Or use the builder:
|
|
109
|
+
* world.queryBuilder().with(Position).without(Dead).build()
|
|
110
|
+
*/
|
|
111
|
+
query(...components: ComponentDef<unknown>[]): Query;
|
|
112
|
+
/** Create a QueryBuilder for complex queries (with/without). */
|
|
113
|
+
queryBuilder(): QueryBuilder;
|
|
114
|
+
/** Register a system function. Lower priority runs first. */
|
|
115
|
+
addSystem(fn: (world: World, dt: number) => void, priority?: number): void;
|
|
116
|
+
/** Remove a system. */
|
|
117
|
+
removeSystem(fn: (world: World, dt: number) => void): void;
|
|
118
|
+
/** Run all systems in priority order. */
|
|
119
|
+
step(dt: number): void;
|
|
120
|
+
/** @internal Register a query for auto-update. */
|
|
121
|
+
_registerQuery(q: Query): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A system function that processes entities matching a query. */
|
|
125
|
+
type SystemFn = (entities: Query, dt: number, world: World) => void;
|
|
126
|
+
/** A defined system with its query and function. */
|
|
127
|
+
interface SystemDef {
|
|
128
|
+
readonly query: Query;
|
|
129
|
+
readonly fn: SystemFn;
|
|
130
|
+
/** The wrapper registered on the World (used for removal). */
|
|
131
|
+
readonly _worldFn: (world: World, dt: number) => void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Define a system that processes entities matching a query.
|
|
135
|
+
*
|
|
136
|
+
* Returns a SystemDef that can be added to a World via world.addSystem().
|
|
137
|
+
* The system function receives the query's matching entities, dt, and world.
|
|
138
|
+
*
|
|
139
|
+
* Usage:
|
|
140
|
+
* const q = world.query(Position, Velocity);
|
|
141
|
+
* const moveSys = defineSystem(q, (entities, dt, world) => {
|
|
142
|
+
* for (const id of entities) { ... }
|
|
143
|
+
* });
|
|
144
|
+
* world.addSystem(moveSys._worldFn);
|
|
145
|
+
*/
|
|
146
|
+
declare function defineSystem(query: Query, fn: SystemFn): SystemDef;
|
|
147
|
+
|
|
148
|
+
/** A prefab factory that spawns entities with pre-defined components. */
|
|
149
|
+
interface Prefab {
|
|
150
|
+
readonly name: string;
|
|
151
|
+
/** Spawn an entity with this prefab's components. */
|
|
152
|
+
spawn(world: World, overrides?: Record<string, unknown>): number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Define a prefab — a template for spawning entities with a fixed set of components.
|
|
156
|
+
*
|
|
157
|
+
* @param name Debug name.
|
|
158
|
+
* @param entries Array of [componentDef, data?] tuples.
|
|
159
|
+
*/
|
|
160
|
+
declare function definePrefab(name: string, ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]): Prefab;
|
|
161
|
+
|
|
162
|
+
/** A state in the FSM. */
|
|
163
|
+
interface State<C = undefined> {
|
|
164
|
+
readonly name: string;
|
|
165
|
+
onEnter?(context: C): void;
|
|
166
|
+
onExit?(context: C): void;
|
|
167
|
+
onUpdate?(dt: number, context: C): void;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Lightweight finite state machine. ~100 LOC.
|
|
171
|
+
*
|
|
172
|
+
* Manages named states with onEnter/onExit/onUpdate hooks
|
|
173
|
+
* and string-keyed transitions.
|
|
174
|
+
*/
|
|
175
|
+
declare class FSM<C = undefined> {
|
|
176
|
+
private _current;
|
|
177
|
+
private _states;
|
|
178
|
+
private _transitions;
|
|
179
|
+
private _context;
|
|
180
|
+
constructor(...args: C extends undefined ? [] : [context: C]);
|
|
181
|
+
/** The currently active state, or undefined if none. */
|
|
182
|
+
get current(): State<C> | undefined;
|
|
183
|
+
/** Register a state. */
|
|
184
|
+
addState(state: State<C>): this;
|
|
185
|
+
/**
|
|
186
|
+
* Register a transition.
|
|
187
|
+
* When `trigger` fires in `fromState`, transition to `toState`.
|
|
188
|
+
*/
|
|
189
|
+
addTransition(fromState: string, trigger: string, toState: string): this;
|
|
190
|
+
/** Set the initial state (calls onEnter). */
|
|
191
|
+
start(stateName: string): void;
|
|
192
|
+
/** Fire a trigger. If a matching transition exists, switch states. */
|
|
193
|
+
trigger(name: string): void;
|
|
194
|
+
/** Update the current state. */
|
|
195
|
+
update(dt: number): void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Built-in ECS components using @flare-engine/math types.
|
|
200
|
+
*/
|
|
201
|
+
/** 2D position component. */
|
|
202
|
+
declare const Position: ComponentDef<Vec2>;
|
|
203
|
+
/** 2D velocity component. */
|
|
204
|
+
declare const Velocity: ComponentDef<Vec2>;
|
|
205
|
+
/** Rotation in radians. */
|
|
206
|
+
declare const Rotation: ComponentDef<{
|
|
207
|
+
angle: number;
|
|
208
|
+
}>;
|
|
209
|
+
/** 2D scale component. */
|
|
210
|
+
declare const Scale: ComponentDef<Vec2>;
|
|
211
|
+
/** Parent entity reference. */
|
|
212
|
+
declare const Parent: ComponentDef<{
|
|
213
|
+
entity: number;
|
|
214
|
+
}>;
|
|
215
|
+
|
|
216
|
+
export { type ComponentDef, FSM, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, defineComponent, definePrefab, defineSystem };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Signal } from '@flare-engine/events';
|
|
2
|
+
import { Vec2 } from '@flare-engine/math';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Component definition and factory.
|
|
6
|
+
*
|
|
7
|
+
* Components are plain data objects. Each component type gets a unique
|
|
8
|
+
* bit for archetype-based query matching.
|
|
9
|
+
*/
|
|
10
|
+
/** A unique component definition. */
|
|
11
|
+
interface ComponentDef<T> {
|
|
12
|
+
/** Internal unique ID (auto-assigned). */
|
|
13
|
+
readonly id: number;
|
|
14
|
+
/** Bitmask for this component (1 << id). */
|
|
15
|
+
readonly bit: number;
|
|
16
|
+
/** Component name for debugging. */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Create a new instance with default values. */
|
|
19
|
+
create(): T;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Define a new component type.
|
|
23
|
+
*
|
|
24
|
+
* @param name Debug name for the component.
|
|
25
|
+
* @param defaults Factory function returning default values, or undefined for tag components.
|
|
26
|
+
*/
|
|
27
|
+
declare function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Reset the component ID counter. Only for testing.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
declare function _resetComponentIds(): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Query matches entities based on component archetypes.
|
|
36
|
+
*
|
|
37
|
+
* Uses bitmask matching: entity archetype & requiredMask === requiredMask
|
|
38
|
+
* and entity archetype & excludedMask === 0.
|
|
39
|
+
*/
|
|
40
|
+
declare class Query {
|
|
41
|
+
/** Bitmask of required components. */
|
|
42
|
+
readonly requiredMask: number;
|
|
43
|
+
/** Bitmask of excluded components. */
|
|
44
|
+
readonly excludedMask: number;
|
|
45
|
+
/** Fires when an entity is added to this query's results. */
|
|
46
|
+
readonly onEntityAdded: Signal<number>;
|
|
47
|
+
/** Fires when an entity is removed from this query's results. */
|
|
48
|
+
readonly onEntityRemoved: Signal<number>;
|
|
49
|
+
/** Sorted array of matching entity IDs. */
|
|
50
|
+
private entities;
|
|
51
|
+
/** Set for O(1) membership check. */
|
|
52
|
+
private entitySet;
|
|
53
|
+
constructor(requiredMask: number, excludedMask: number);
|
|
54
|
+
/** Check if an archetype matches this query. */
|
|
55
|
+
matches(archetype: number): boolean;
|
|
56
|
+
/** @internal — called by World when an entity's archetype changes. */
|
|
57
|
+
_check(entityId: number, archetype: number): void;
|
|
58
|
+
/** @internal — called by World when an entity is removed entirely. */
|
|
59
|
+
_remove(entityId: number): void;
|
|
60
|
+
/** Iterate matching entity IDs. */
|
|
61
|
+
[Symbol.iterator](): IterableIterator<number>;
|
|
62
|
+
/** Number of matching entities. */
|
|
63
|
+
get count(): number;
|
|
64
|
+
/** Check if an entity matches this query. */
|
|
65
|
+
has(entityId: number): boolean;
|
|
66
|
+
}
|
|
67
|
+
/** Builder for creating queries with .with() / .without() chaining. */
|
|
68
|
+
declare class QueryBuilder {
|
|
69
|
+
private required;
|
|
70
|
+
private excluded;
|
|
71
|
+
with(...components: ComponentDef<unknown>[]): this;
|
|
72
|
+
without(...components: ComponentDef<unknown>[]): this;
|
|
73
|
+
/** Build the query (called internally by World). */
|
|
74
|
+
build(): Query;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* World is the central ECS container.
|
|
79
|
+
*
|
|
80
|
+
* Entities are integer IDs. Components are stored in per-component Maps.
|
|
81
|
+
* Archetype bitmasks enable fast query matching.
|
|
82
|
+
*/
|
|
83
|
+
declare class World {
|
|
84
|
+
private nextId;
|
|
85
|
+
private archetypes;
|
|
86
|
+
private componentStores;
|
|
87
|
+
private queries;
|
|
88
|
+
private systems;
|
|
89
|
+
private systemsSorted;
|
|
90
|
+
/** Create a new entity. Returns the entity ID. */
|
|
91
|
+
spawn(): number;
|
|
92
|
+
/** Remove an entity and all its components. */
|
|
93
|
+
destroy(entityId: number): void;
|
|
94
|
+
/** Add a component to an entity. */
|
|
95
|
+
add<T>(entityId: number, def: ComponentDef<T>, data?: T): void;
|
|
96
|
+
/** Remove a component from an entity. */
|
|
97
|
+
remove<T>(entityId: number, def: ComponentDef<T>): void;
|
|
98
|
+
/** Get component data for an entity. */
|
|
99
|
+
get<T>(entityId: number, def: ComponentDef<T>): T | undefined;
|
|
100
|
+
/** Check if entity has a component. */
|
|
101
|
+
has(entityId: number, def: ComponentDef<unknown>): boolean;
|
|
102
|
+
/** Check if entity exists. */
|
|
103
|
+
exists(entityId: number): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Create a query. Queries auto-update as entities change.
|
|
106
|
+
* Use the QueryBuilder-style chaining:
|
|
107
|
+
* world.query(Position, Velocity)
|
|
108
|
+
* Or use the builder:
|
|
109
|
+
* world.queryBuilder().with(Position).without(Dead).build()
|
|
110
|
+
*/
|
|
111
|
+
query(...components: ComponentDef<unknown>[]): Query;
|
|
112
|
+
/** Create a QueryBuilder for complex queries (with/without). */
|
|
113
|
+
queryBuilder(): QueryBuilder;
|
|
114
|
+
/** Register a system function. Lower priority runs first. */
|
|
115
|
+
addSystem(fn: (world: World, dt: number) => void, priority?: number): void;
|
|
116
|
+
/** Remove a system. */
|
|
117
|
+
removeSystem(fn: (world: World, dt: number) => void): void;
|
|
118
|
+
/** Run all systems in priority order. */
|
|
119
|
+
step(dt: number): void;
|
|
120
|
+
/** @internal Register a query for auto-update. */
|
|
121
|
+
_registerQuery(q: Query): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A system function that processes entities matching a query. */
|
|
125
|
+
type SystemFn = (entities: Query, dt: number, world: World) => void;
|
|
126
|
+
/** A defined system with its query and function. */
|
|
127
|
+
interface SystemDef {
|
|
128
|
+
readonly query: Query;
|
|
129
|
+
readonly fn: SystemFn;
|
|
130
|
+
/** The wrapper registered on the World (used for removal). */
|
|
131
|
+
readonly _worldFn: (world: World, dt: number) => void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Define a system that processes entities matching a query.
|
|
135
|
+
*
|
|
136
|
+
* Returns a SystemDef that can be added to a World via world.addSystem().
|
|
137
|
+
* The system function receives the query's matching entities, dt, and world.
|
|
138
|
+
*
|
|
139
|
+
* Usage:
|
|
140
|
+
* const q = world.query(Position, Velocity);
|
|
141
|
+
* const moveSys = defineSystem(q, (entities, dt, world) => {
|
|
142
|
+
* for (const id of entities) { ... }
|
|
143
|
+
* });
|
|
144
|
+
* world.addSystem(moveSys._worldFn);
|
|
145
|
+
*/
|
|
146
|
+
declare function defineSystem(query: Query, fn: SystemFn): SystemDef;
|
|
147
|
+
|
|
148
|
+
/** A prefab factory that spawns entities with pre-defined components. */
|
|
149
|
+
interface Prefab {
|
|
150
|
+
readonly name: string;
|
|
151
|
+
/** Spawn an entity with this prefab's components. */
|
|
152
|
+
spawn(world: World, overrides?: Record<string, unknown>): number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Define a prefab — a template for spawning entities with a fixed set of components.
|
|
156
|
+
*
|
|
157
|
+
* @param name Debug name.
|
|
158
|
+
* @param entries Array of [componentDef, data?] tuples.
|
|
159
|
+
*/
|
|
160
|
+
declare function definePrefab(name: string, ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]): Prefab;
|
|
161
|
+
|
|
162
|
+
/** A state in the FSM. */
|
|
163
|
+
interface State<C = undefined> {
|
|
164
|
+
readonly name: string;
|
|
165
|
+
onEnter?(context: C): void;
|
|
166
|
+
onExit?(context: C): void;
|
|
167
|
+
onUpdate?(dt: number, context: C): void;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Lightweight finite state machine. ~100 LOC.
|
|
171
|
+
*
|
|
172
|
+
* Manages named states with onEnter/onExit/onUpdate hooks
|
|
173
|
+
* and string-keyed transitions.
|
|
174
|
+
*/
|
|
175
|
+
declare class FSM<C = undefined> {
|
|
176
|
+
private _current;
|
|
177
|
+
private _states;
|
|
178
|
+
private _transitions;
|
|
179
|
+
private _context;
|
|
180
|
+
constructor(...args: C extends undefined ? [] : [context: C]);
|
|
181
|
+
/** The currently active state, or undefined if none. */
|
|
182
|
+
get current(): State<C> | undefined;
|
|
183
|
+
/** Register a state. */
|
|
184
|
+
addState(state: State<C>): this;
|
|
185
|
+
/**
|
|
186
|
+
* Register a transition.
|
|
187
|
+
* When `trigger` fires in `fromState`, transition to `toState`.
|
|
188
|
+
*/
|
|
189
|
+
addTransition(fromState: string, trigger: string, toState: string): this;
|
|
190
|
+
/** Set the initial state (calls onEnter). */
|
|
191
|
+
start(stateName: string): void;
|
|
192
|
+
/** Fire a trigger. If a matching transition exists, switch states. */
|
|
193
|
+
trigger(name: string): void;
|
|
194
|
+
/** Update the current state. */
|
|
195
|
+
update(dt: number): void;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Built-in ECS components using @flare-engine/math types.
|
|
200
|
+
*/
|
|
201
|
+
/** 2D position component. */
|
|
202
|
+
declare const Position: ComponentDef<Vec2>;
|
|
203
|
+
/** 2D velocity component. */
|
|
204
|
+
declare const Velocity: ComponentDef<Vec2>;
|
|
205
|
+
/** Rotation in radians. */
|
|
206
|
+
declare const Rotation: ComponentDef<{
|
|
207
|
+
angle: number;
|
|
208
|
+
}>;
|
|
209
|
+
/** 2D scale component. */
|
|
210
|
+
declare const Scale: ComponentDef<Vec2>;
|
|
211
|
+
/** Parent entity reference. */
|
|
212
|
+
declare const Parent: ComponentDef<{
|
|
213
|
+
entity: number;
|
|
214
|
+
}>;
|
|
215
|
+
|
|
216
|
+
export { type ComponentDef, FSM, Parent, Position, type Prefab, Query, QueryBuilder, Rotation, Scale, type State, type SystemDef, type SystemFn, Velocity, World, _resetComponentIds, defineComponent, definePrefab, defineSystem };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
FSM: () => FSM,
|
|
24
|
+
Parent: () => Parent,
|
|
25
|
+
Position: () => Position,
|
|
26
|
+
Query: () => Query,
|
|
27
|
+
QueryBuilder: () => QueryBuilder,
|
|
28
|
+
Rotation: () => Rotation,
|
|
29
|
+
Scale: () => Scale,
|
|
30
|
+
Velocity: () => Velocity,
|
|
31
|
+
World: () => World,
|
|
32
|
+
_resetComponentIds: () => _resetComponentIds,
|
|
33
|
+
defineComponent: () => defineComponent,
|
|
34
|
+
definePrefab: () => definePrefab,
|
|
35
|
+
defineSystem: () => defineSystem
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/component.ts
|
|
40
|
+
var nextComponentId = 0;
|
|
41
|
+
function defineComponent(name, defaults) {
|
|
42
|
+
const id = nextComponentId++;
|
|
43
|
+
if (id >= 32) {
|
|
44
|
+
throw new Error(`Maximum 32 component types exceeded (defining "${name}")`);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
id,
|
|
48
|
+
bit: 1 << id,
|
|
49
|
+
name,
|
|
50
|
+
create: defaults ?? (() => void 0)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function _resetComponentIds() {
|
|
54
|
+
nextComponentId = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/query.ts
|
|
58
|
+
var import_events = require("@flare-engine/events");
|
|
59
|
+
var Query = class {
|
|
60
|
+
/** Bitmask of required components. */
|
|
61
|
+
requiredMask;
|
|
62
|
+
/** Bitmask of excluded components. */
|
|
63
|
+
excludedMask;
|
|
64
|
+
/** Fires when an entity is added to this query's results. */
|
|
65
|
+
onEntityAdded = new import_events.Signal();
|
|
66
|
+
/** Fires when an entity is removed from this query's results. */
|
|
67
|
+
onEntityRemoved = new import_events.Signal();
|
|
68
|
+
/** Sorted array of matching entity IDs. */
|
|
69
|
+
entities = [];
|
|
70
|
+
/** Set for O(1) membership check. */
|
|
71
|
+
entitySet = /* @__PURE__ */ new Set();
|
|
72
|
+
constructor(requiredMask, excludedMask) {
|
|
73
|
+
this.requiredMask = requiredMask;
|
|
74
|
+
this.excludedMask = excludedMask;
|
|
75
|
+
}
|
|
76
|
+
/** Check if an archetype matches this query. */
|
|
77
|
+
matches(archetype) {
|
|
78
|
+
return (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0;
|
|
79
|
+
}
|
|
80
|
+
/** @internal — called by World when an entity's archetype changes. */
|
|
81
|
+
_check(entityId, archetype) {
|
|
82
|
+
const isMatch = this.matches(archetype);
|
|
83
|
+
const wasMatch = this.entitySet.has(entityId);
|
|
84
|
+
if (isMatch && !wasMatch) {
|
|
85
|
+
this.entitySet.add(entityId);
|
|
86
|
+
this.entities.push(entityId);
|
|
87
|
+
this.onEntityAdded.emit(entityId);
|
|
88
|
+
} else if (!isMatch && wasMatch) {
|
|
89
|
+
this.entitySet.delete(entityId);
|
|
90
|
+
const idx = this.entities.indexOf(entityId);
|
|
91
|
+
if (idx !== -1) this.entities.splice(idx, 1);
|
|
92
|
+
this.onEntityRemoved.emit(entityId);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** @internal — called by World when an entity is removed entirely. */
|
|
96
|
+
_remove(entityId) {
|
|
97
|
+
if (this.entitySet.has(entityId)) {
|
|
98
|
+
this.entitySet.delete(entityId);
|
|
99
|
+
const idx = this.entities.indexOf(entityId);
|
|
100
|
+
if (idx !== -1) this.entities.splice(idx, 1);
|
|
101
|
+
this.onEntityRemoved.emit(entityId);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Iterate matching entity IDs. */
|
|
105
|
+
[Symbol.iterator]() {
|
|
106
|
+
return this.entities[Symbol.iterator]();
|
|
107
|
+
}
|
|
108
|
+
/** Number of matching entities. */
|
|
109
|
+
get count() {
|
|
110
|
+
return this.entities.length;
|
|
111
|
+
}
|
|
112
|
+
/** Check if an entity matches this query. */
|
|
113
|
+
has(entityId) {
|
|
114
|
+
return this.entitySet.has(entityId);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var QueryBuilder = class {
|
|
118
|
+
required = 0;
|
|
119
|
+
excluded = 0;
|
|
120
|
+
with(...components) {
|
|
121
|
+
for (const c of components) {
|
|
122
|
+
this.required |= c.bit;
|
|
123
|
+
}
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
without(...components) {
|
|
127
|
+
for (const c of components) {
|
|
128
|
+
this.excluded |= c.bit;
|
|
129
|
+
}
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/** Build the query (called internally by World). */
|
|
133
|
+
build() {
|
|
134
|
+
return new Query(this.required, this.excluded);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/world.ts
|
|
139
|
+
var World = class {
|
|
140
|
+
nextId = 1;
|
|
141
|
+
archetypes = /* @__PURE__ */ new Map();
|
|
142
|
+
// entityId → bitmask
|
|
143
|
+
componentStores = /* @__PURE__ */ new Map();
|
|
144
|
+
// componentId → (entityId → data)
|
|
145
|
+
queries = [];
|
|
146
|
+
systems = [];
|
|
147
|
+
systemsSorted = false;
|
|
148
|
+
/** Create a new entity. Returns the entity ID. */
|
|
149
|
+
spawn() {
|
|
150
|
+
const id = this.nextId++;
|
|
151
|
+
this.archetypes.set(id, 0);
|
|
152
|
+
return id;
|
|
153
|
+
}
|
|
154
|
+
/** Remove an entity and all its components. */
|
|
155
|
+
destroy(entityId) {
|
|
156
|
+
const arch = this.archetypes.get(entityId);
|
|
157
|
+
if (arch === void 0) return;
|
|
158
|
+
for (const [, store] of this.componentStores) {
|
|
159
|
+
store.delete(entityId);
|
|
160
|
+
}
|
|
161
|
+
this.archetypes.delete(entityId);
|
|
162
|
+
for (const query of this.queries) {
|
|
163
|
+
query._remove(entityId);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Add a component to an entity. */
|
|
167
|
+
add(entityId, def, data) {
|
|
168
|
+
const arch = this.archetypes.get(entityId);
|
|
169
|
+
if (arch === void 0) return;
|
|
170
|
+
let store = this.componentStores.get(def.id);
|
|
171
|
+
if (!store) {
|
|
172
|
+
store = /* @__PURE__ */ new Map();
|
|
173
|
+
this.componentStores.set(def.id, store);
|
|
174
|
+
}
|
|
175
|
+
store.set(entityId, data !== void 0 ? data : def.create());
|
|
176
|
+
const newArch = arch | def.bit;
|
|
177
|
+
this.archetypes.set(entityId, newArch);
|
|
178
|
+
for (const query of this.queries) {
|
|
179
|
+
query._check(entityId, newArch);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Remove a component from an entity. */
|
|
183
|
+
remove(entityId, def) {
|
|
184
|
+
const arch = this.archetypes.get(entityId);
|
|
185
|
+
if (arch === void 0) return;
|
|
186
|
+
const store = this.componentStores.get(def.id);
|
|
187
|
+
if (store) store.delete(entityId);
|
|
188
|
+
const newArch = arch & ~def.bit;
|
|
189
|
+
this.archetypes.set(entityId, newArch);
|
|
190
|
+
for (const query of this.queries) {
|
|
191
|
+
query._check(entityId, newArch);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Get component data for an entity. */
|
|
195
|
+
get(entityId, def) {
|
|
196
|
+
const store = this.componentStores.get(def.id);
|
|
197
|
+
return store?.get(entityId);
|
|
198
|
+
}
|
|
199
|
+
/** Check if entity has a component. */
|
|
200
|
+
has(entityId, def) {
|
|
201
|
+
const arch = this.archetypes.get(entityId);
|
|
202
|
+
return arch !== void 0 && (arch & def.bit) !== 0;
|
|
203
|
+
}
|
|
204
|
+
/** Check if entity exists. */
|
|
205
|
+
exists(entityId) {
|
|
206
|
+
return this.archetypes.has(entityId);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a query. Queries auto-update as entities change.
|
|
210
|
+
* Use the QueryBuilder-style chaining:
|
|
211
|
+
* world.query(Position, Velocity)
|
|
212
|
+
* Or use the builder:
|
|
213
|
+
* world.queryBuilder().with(Position).without(Dead).build()
|
|
214
|
+
*/
|
|
215
|
+
query(...components) {
|
|
216
|
+
let mask = 0;
|
|
217
|
+
for (const c of components) {
|
|
218
|
+
mask |= c.bit;
|
|
219
|
+
}
|
|
220
|
+
const q = new Query(mask, 0);
|
|
221
|
+
this.queries.push(q);
|
|
222
|
+
for (const [entityId, arch] of this.archetypes) {
|
|
223
|
+
q._check(entityId, arch);
|
|
224
|
+
}
|
|
225
|
+
return q;
|
|
226
|
+
}
|
|
227
|
+
/** Create a QueryBuilder for complex queries (with/without). */
|
|
228
|
+
queryBuilder() {
|
|
229
|
+
return new _WorldQueryBuilder(this);
|
|
230
|
+
}
|
|
231
|
+
/** Register a system function. Lower priority runs first. */
|
|
232
|
+
addSystem(fn, priority = 0) {
|
|
233
|
+
this.systems.push({ fn, priority });
|
|
234
|
+
this.systemsSorted = false;
|
|
235
|
+
}
|
|
236
|
+
/** Remove a system. */
|
|
237
|
+
removeSystem(fn) {
|
|
238
|
+
const idx = this.systems.findIndex((s) => s.fn === fn);
|
|
239
|
+
if (idx !== -1) this.systems.splice(idx, 1);
|
|
240
|
+
}
|
|
241
|
+
/** Run all systems in priority order. */
|
|
242
|
+
step(dt) {
|
|
243
|
+
if (!this.systemsSorted) {
|
|
244
|
+
this.systems.sort((a, b) => a.priority - b.priority);
|
|
245
|
+
this.systemsSorted = true;
|
|
246
|
+
}
|
|
247
|
+
for (const sys of this.systems) {
|
|
248
|
+
sys.fn(this, dt);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** @internal Register a query for auto-update. */
|
|
252
|
+
_registerQuery(q) {
|
|
253
|
+
this.queries.push(q);
|
|
254
|
+
for (const [entityId, arch] of this.archetypes) {
|
|
255
|
+
q._check(entityId, arch);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
var _WorldQueryBuilder = class extends QueryBuilder {
|
|
260
|
+
world;
|
|
261
|
+
constructor(world) {
|
|
262
|
+
super();
|
|
263
|
+
this.world = world;
|
|
264
|
+
}
|
|
265
|
+
build() {
|
|
266
|
+
const q = super.build();
|
|
267
|
+
this.world._registerQuery(q);
|
|
268
|
+
return q;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/system.ts
|
|
273
|
+
function defineSystem(query, fn) {
|
|
274
|
+
const worldFn = (world, dt) => {
|
|
275
|
+
fn(query, dt, world);
|
|
276
|
+
};
|
|
277
|
+
return { query, fn, _worldFn: worldFn };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/prefab.ts
|
|
281
|
+
function definePrefab(name, ...entries) {
|
|
282
|
+
const components = entries.map(([def, data]) => ({
|
|
283
|
+
def,
|
|
284
|
+
data
|
|
285
|
+
}));
|
|
286
|
+
return {
|
|
287
|
+
name,
|
|
288
|
+
spawn(world) {
|
|
289
|
+
const entity = world.spawn();
|
|
290
|
+
for (const entry of components) {
|
|
291
|
+
const data = typeof entry.data === "function" ? entry.data() : entry.data;
|
|
292
|
+
world.add(entity, entry.def, data);
|
|
293
|
+
}
|
|
294
|
+
return entity;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/fsm.ts
|
|
300
|
+
var FSM = class {
|
|
301
|
+
_current;
|
|
302
|
+
_states = /* @__PURE__ */ new Map();
|
|
303
|
+
_transitions = /* @__PURE__ */ new Map();
|
|
304
|
+
_context;
|
|
305
|
+
constructor(...args) {
|
|
306
|
+
this._context = args[0];
|
|
307
|
+
}
|
|
308
|
+
/** The currently active state, or undefined if none. */
|
|
309
|
+
get current() {
|
|
310
|
+
return this._current;
|
|
311
|
+
}
|
|
312
|
+
/** Register a state. */
|
|
313
|
+
addState(state) {
|
|
314
|
+
this._states.set(state.name, state);
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Register a transition.
|
|
319
|
+
* When `trigger` fires in `fromState`, transition to `toState`.
|
|
320
|
+
*/
|
|
321
|
+
addTransition(fromState, trigger, toState) {
|
|
322
|
+
let map = this._transitions.get(fromState);
|
|
323
|
+
if (!map) {
|
|
324
|
+
map = /* @__PURE__ */ new Map();
|
|
325
|
+
this._transitions.set(fromState, map);
|
|
326
|
+
}
|
|
327
|
+
map.set(trigger, toState);
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
/** Set the initial state (calls onEnter). */
|
|
331
|
+
start(stateName) {
|
|
332
|
+
const state = this._states.get(stateName);
|
|
333
|
+
if (!state) return;
|
|
334
|
+
this._current = state;
|
|
335
|
+
state.onEnter?.(this._context);
|
|
336
|
+
}
|
|
337
|
+
/** Fire a trigger. If a matching transition exists, switch states. */
|
|
338
|
+
trigger(name) {
|
|
339
|
+
if (!this._current) return;
|
|
340
|
+
const transitions = this._transitions.get(this._current.name);
|
|
341
|
+
if (!transitions) return;
|
|
342
|
+
const target = transitions.get(name);
|
|
343
|
+
if (target === void 0) return;
|
|
344
|
+
const next = this._states.get(target);
|
|
345
|
+
if (!next) return;
|
|
346
|
+
this._current.onExit?.(this._context);
|
|
347
|
+
this._current = next;
|
|
348
|
+
next.onEnter?.(this._context);
|
|
349
|
+
}
|
|
350
|
+
/** Update the current state. */
|
|
351
|
+
update(dt) {
|
|
352
|
+
this._current?.onUpdate?.(dt, this._context);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
// src/components.ts
|
|
357
|
+
var Position = defineComponent("Position", () => ({
|
|
358
|
+
x: 0,
|
|
359
|
+
y: 0
|
|
360
|
+
}));
|
|
361
|
+
var Velocity = defineComponent("Velocity", () => ({
|
|
362
|
+
x: 0,
|
|
363
|
+
y: 0
|
|
364
|
+
}));
|
|
365
|
+
var Rotation = defineComponent("Rotation", () => ({
|
|
366
|
+
angle: 0
|
|
367
|
+
}));
|
|
368
|
+
var Scale = defineComponent("Scale", () => ({ x: 1, y: 1 }));
|
|
369
|
+
var Parent = defineComponent("Parent", () => ({
|
|
370
|
+
entity: 0
|
|
371
|
+
}));
|
|
372
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
373
|
+
0 && (module.exports = {
|
|
374
|
+
FSM,
|
|
375
|
+
Parent,
|
|
376
|
+
Position,
|
|
377
|
+
Query,
|
|
378
|
+
QueryBuilder,
|
|
379
|
+
Rotation,
|
|
380
|
+
Scale,
|
|
381
|
+
Velocity,
|
|
382
|
+
World,
|
|
383
|
+
_resetComponentIds,
|
|
384
|
+
defineComponent,
|
|
385
|
+
definePrefab,
|
|
386
|
+
defineSystem
|
|
387
|
+
});
|
|
388
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts"],"sourcesContent":["export { defineComponent, _resetComponentIds } from './component.js';\nexport type { ComponentDef } from './component.js';\n\nexport { World } from './world.js';\n\nexport { Query, QueryBuilder } from './query.js';\n\nexport { defineSystem } from './system.js';\nexport type { SystemFn, SystemDef } from './system.js';\n\nexport { definePrefab } from './prefab.js';\nexport type { Prefab } from './prefab.js';\n\nexport { FSM } from './fsm.js';\nexport type { State } from './fsm.js';\n\nexport { Position, Velocity, Rotation, Scale, Parent } from './components.js';\n","/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBA,IAAI,kBAAkB;AAQf,SAAS,gBAA+B,MAAc,UAAqC;AAChG,QAAM,KAAK;AACX,MAAI,MAAM,IAAI;AACZ,UAAM,IAAI,MAAM,kDAAkD,IAAI,IAAI;AAAA,EAC5E;AACA,SAAO;AAAA,IACL;AAAA,IACA,KAAK,KAAK;AAAA,IACV;AAAA,IACA,QAAQ,aAAa,MAAM;AAAA,EAC7B;AACF;AAMO,SAAS,qBAA2B;AACzC,oBAAkB;AACpB;;;AC9CA,oBAAuB;AAShB,IAAM,QAAN,MAAY;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAGA,gBAAgB,IAAI,qBAAe;AAAA;AAAA,EAEnC,kBAAkB,IAAI,qBAAe;AAAA;AAAA,EAGtC,WAAqB,CAAC;AAAA;AAA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I,CAAC,YAAa;AAClB,UAAM,SAAS,YAAY,IAAI,IAAI;AACnC,QAAI,WAAW,OAAW;AAC1B,UAAM,OAAO,KAAK,QAAQ,IAAI,MAAM;AACpC,QAAI,CAAC,KAAM;AACX,SAAK,SAAS,SAAS,KAAK,QAAQ;AACpC,SAAK,WAAW;AAChB,SAAK,UAAU,KAAK,QAAQ;AAAA,EAC9B;AAAA;AAAA,EAGA,OAAO,IAAkB;AACvB,SAAK,UAAU,WAAW,IAAI,KAAK,QAAQ;AAAA,EAC7C;AACF;;;ACnEO,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAmC,YAAY,OAAO;AAAA,EAC5E,OAAO;AACT,EAAE;AAGK,IAAM,QAAQ,gBAAsB,SAAS,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE;AAGnE,IAAM,SAAS,gBAAoC,UAAU,OAAO;AAAA,EACzE,QAAQ;AACV,EAAE;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// src/component.ts
|
|
2
|
+
var nextComponentId = 0;
|
|
3
|
+
function defineComponent(name, defaults) {
|
|
4
|
+
const id = nextComponentId++;
|
|
5
|
+
if (id >= 32) {
|
|
6
|
+
throw new Error(`Maximum 32 component types exceeded (defining "${name}")`);
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
id,
|
|
10
|
+
bit: 1 << id,
|
|
11
|
+
name,
|
|
12
|
+
create: defaults ?? (() => void 0)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function _resetComponentIds() {
|
|
16
|
+
nextComponentId = 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/query.ts
|
|
20
|
+
import { Signal } from "@flare-engine/events";
|
|
21
|
+
var Query = class {
|
|
22
|
+
/** Bitmask of required components. */
|
|
23
|
+
requiredMask;
|
|
24
|
+
/** Bitmask of excluded components. */
|
|
25
|
+
excludedMask;
|
|
26
|
+
/** Fires when an entity is added to this query's results. */
|
|
27
|
+
onEntityAdded = new Signal();
|
|
28
|
+
/** Fires when an entity is removed from this query's results. */
|
|
29
|
+
onEntityRemoved = new Signal();
|
|
30
|
+
/** Sorted array of matching entity IDs. */
|
|
31
|
+
entities = [];
|
|
32
|
+
/** Set for O(1) membership check. */
|
|
33
|
+
entitySet = /* @__PURE__ */ new Set();
|
|
34
|
+
constructor(requiredMask, excludedMask) {
|
|
35
|
+
this.requiredMask = requiredMask;
|
|
36
|
+
this.excludedMask = excludedMask;
|
|
37
|
+
}
|
|
38
|
+
/** Check if an archetype matches this query. */
|
|
39
|
+
matches(archetype) {
|
|
40
|
+
return (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0;
|
|
41
|
+
}
|
|
42
|
+
/** @internal — called by World when an entity's archetype changes. */
|
|
43
|
+
_check(entityId, archetype) {
|
|
44
|
+
const isMatch = this.matches(archetype);
|
|
45
|
+
const wasMatch = this.entitySet.has(entityId);
|
|
46
|
+
if (isMatch && !wasMatch) {
|
|
47
|
+
this.entitySet.add(entityId);
|
|
48
|
+
this.entities.push(entityId);
|
|
49
|
+
this.onEntityAdded.emit(entityId);
|
|
50
|
+
} else if (!isMatch && wasMatch) {
|
|
51
|
+
this.entitySet.delete(entityId);
|
|
52
|
+
const idx = this.entities.indexOf(entityId);
|
|
53
|
+
if (idx !== -1) this.entities.splice(idx, 1);
|
|
54
|
+
this.onEntityRemoved.emit(entityId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** @internal — called by World when an entity is removed entirely. */
|
|
58
|
+
_remove(entityId) {
|
|
59
|
+
if (this.entitySet.has(entityId)) {
|
|
60
|
+
this.entitySet.delete(entityId);
|
|
61
|
+
const idx = this.entities.indexOf(entityId);
|
|
62
|
+
if (idx !== -1) this.entities.splice(idx, 1);
|
|
63
|
+
this.onEntityRemoved.emit(entityId);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Iterate matching entity IDs. */
|
|
67
|
+
[Symbol.iterator]() {
|
|
68
|
+
return this.entities[Symbol.iterator]();
|
|
69
|
+
}
|
|
70
|
+
/** Number of matching entities. */
|
|
71
|
+
get count() {
|
|
72
|
+
return this.entities.length;
|
|
73
|
+
}
|
|
74
|
+
/** Check if an entity matches this query. */
|
|
75
|
+
has(entityId) {
|
|
76
|
+
return this.entitySet.has(entityId);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var QueryBuilder = class {
|
|
80
|
+
required = 0;
|
|
81
|
+
excluded = 0;
|
|
82
|
+
with(...components) {
|
|
83
|
+
for (const c of components) {
|
|
84
|
+
this.required |= c.bit;
|
|
85
|
+
}
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
without(...components) {
|
|
89
|
+
for (const c of components) {
|
|
90
|
+
this.excluded |= c.bit;
|
|
91
|
+
}
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/** Build the query (called internally by World). */
|
|
95
|
+
build() {
|
|
96
|
+
return new Query(this.required, this.excluded);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/world.ts
|
|
101
|
+
var World = class {
|
|
102
|
+
nextId = 1;
|
|
103
|
+
archetypes = /* @__PURE__ */ new Map();
|
|
104
|
+
// entityId → bitmask
|
|
105
|
+
componentStores = /* @__PURE__ */ new Map();
|
|
106
|
+
// componentId → (entityId → data)
|
|
107
|
+
queries = [];
|
|
108
|
+
systems = [];
|
|
109
|
+
systemsSorted = false;
|
|
110
|
+
/** Create a new entity. Returns the entity ID. */
|
|
111
|
+
spawn() {
|
|
112
|
+
const id = this.nextId++;
|
|
113
|
+
this.archetypes.set(id, 0);
|
|
114
|
+
return id;
|
|
115
|
+
}
|
|
116
|
+
/** Remove an entity and all its components. */
|
|
117
|
+
destroy(entityId) {
|
|
118
|
+
const arch = this.archetypes.get(entityId);
|
|
119
|
+
if (arch === void 0) return;
|
|
120
|
+
for (const [, store] of this.componentStores) {
|
|
121
|
+
store.delete(entityId);
|
|
122
|
+
}
|
|
123
|
+
this.archetypes.delete(entityId);
|
|
124
|
+
for (const query of this.queries) {
|
|
125
|
+
query._remove(entityId);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Add a component to an entity. */
|
|
129
|
+
add(entityId, def, data) {
|
|
130
|
+
const arch = this.archetypes.get(entityId);
|
|
131
|
+
if (arch === void 0) return;
|
|
132
|
+
let store = this.componentStores.get(def.id);
|
|
133
|
+
if (!store) {
|
|
134
|
+
store = /* @__PURE__ */ new Map();
|
|
135
|
+
this.componentStores.set(def.id, store);
|
|
136
|
+
}
|
|
137
|
+
store.set(entityId, data !== void 0 ? data : def.create());
|
|
138
|
+
const newArch = arch | def.bit;
|
|
139
|
+
this.archetypes.set(entityId, newArch);
|
|
140
|
+
for (const query of this.queries) {
|
|
141
|
+
query._check(entityId, newArch);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Remove a component from an entity. */
|
|
145
|
+
remove(entityId, def) {
|
|
146
|
+
const arch = this.archetypes.get(entityId);
|
|
147
|
+
if (arch === void 0) return;
|
|
148
|
+
const store = this.componentStores.get(def.id);
|
|
149
|
+
if (store) store.delete(entityId);
|
|
150
|
+
const newArch = arch & ~def.bit;
|
|
151
|
+
this.archetypes.set(entityId, newArch);
|
|
152
|
+
for (const query of this.queries) {
|
|
153
|
+
query._check(entityId, newArch);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Get component data for an entity. */
|
|
157
|
+
get(entityId, def) {
|
|
158
|
+
const store = this.componentStores.get(def.id);
|
|
159
|
+
return store?.get(entityId);
|
|
160
|
+
}
|
|
161
|
+
/** Check if entity has a component. */
|
|
162
|
+
has(entityId, def) {
|
|
163
|
+
const arch = this.archetypes.get(entityId);
|
|
164
|
+
return arch !== void 0 && (arch & def.bit) !== 0;
|
|
165
|
+
}
|
|
166
|
+
/** Check if entity exists. */
|
|
167
|
+
exists(entityId) {
|
|
168
|
+
return this.archetypes.has(entityId);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a query. Queries auto-update as entities change.
|
|
172
|
+
* Use the QueryBuilder-style chaining:
|
|
173
|
+
* world.query(Position, Velocity)
|
|
174
|
+
* Or use the builder:
|
|
175
|
+
* world.queryBuilder().with(Position).without(Dead).build()
|
|
176
|
+
*/
|
|
177
|
+
query(...components) {
|
|
178
|
+
let mask = 0;
|
|
179
|
+
for (const c of components) {
|
|
180
|
+
mask |= c.bit;
|
|
181
|
+
}
|
|
182
|
+
const q = new Query(mask, 0);
|
|
183
|
+
this.queries.push(q);
|
|
184
|
+
for (const [entityId, arch] of this.archetypes) {
|
|
185
|
+
q._check(entityId, arch);
|
|
186
|
+
}
|
|
187
|
+
return q;
|
|
188
|
+
}
|
|
189
|
+
/** Create a QueryBuilder for complex queries (with/without). */
|
|
190
|
+
queryBuilder() {
|
|
191
|
+
return new _WorldQueryBuilder(this);
|
|
192
|
+
}
|
|
193
|
+
/** Register a system function. Lower priority runs first. */
|
|
194
|
+
addSystem(fn, priority = 0) {
|
|
195
|
+
this.systems.push({ fn, priority });
|
|
196
|
+
this.systemsSorted = false;
|
|
197
|
+
}
|
|
198
|
+
/** Remove a system. */
|
|
199
|
+
removeSystem(fn) {
|
|
200
|
+
const idx = this.systems.findIndex((s) => s.fn === fn);
|
|
201
|
+
if (idx !== -1) this.systems.splice(idx, 1);
|
|
202
|
+
}
|
|
203
|
+
/** Run all systems in priority order. */
|
|
204
|
+
step(dt) {
|
|
205
|
+
if (!this.systemsSorted) {
|
|
206
|
+
this.systems.sort((a, b) => a.priority - b.priority);
|
|
207
|
+
this.systemsSorted = true;
|
|
208
|
+
}
|
|
209
|
+
for (const sys of this.systems) {
|
|
210
|
+
sys.fn(this, dt);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** @internal Register a query for auto-update. */
|
|
214
|
+
_registerQuery(q) {
|
|
215
|
+
this.queries.push(q);
|
|
216
|
+
for (const [entityId, arch] of this.archetypes) {
|
|
217
|
+
q._check(entityId, arch);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var _WorldQueryBuilder = class extends QueryBuilder {
|
|
222
|
+
world;
|
|
223
|
+
constructor(world) {
|
|
224
|
+
super();
|
|
225
|
+
this.world = world;
|
|
226
|
+
}
|
|
227
|
+
build() {
|
|
228
|
+
const q = super.build();
|
|
229
|
+
this.world._registerQuery(q);
|
|
230
|
+
return q;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/system.ts
|
|
235
|
+
function defineSystem(query, fn) {
|
|
236
|
+
const worldFn = (world, dt) => {
|
|
237
|
+
fn(query, dt, world);
|
|
238
|
+
};
|
|
239
|
+
return { query, fn, _worldFn: worldFn };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/prefab.ts
|
|
243
|
+
function definePrefab(name, ...entries) {
|
|
244
|
+
const components = entries.map(([def, data]) => ({
|
|
245
|
+
def,
|
|
246
|
+
data
|
|
247
|
+
}));
|
|
248
|
+
return {
|
|
249
|
+
name,
|
|
250
|
+
spawn(world) {
|
|
251
|
+
const entity = world.spawn();
|
|
252
|
+
for (const entry of components) {
|
|
253
|
+
const data = typeof entry.data === "function" ? entry.data() : entry.data;
|
|
254
|
+
world.add(entity, entry.def, data);
|
|
255
|
+
}
|
|
256
|
+
return entity;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/fsm.ts
|
|
262
|
+
var FSM = class {
|
|
263
|
+
_current;
|
|
264
|
+
_states = /* @__PURE__ */ new Map();
|
|
265
|
+
_transitions = /* @__PURE__ */ new Map();
|
|
266
|
+
_context;
|
|
267
|
+
constructor(...args) {
|
|
268
|
+
this._context = args[0];
|
|
269
|
+
}
|
|
270
|
+
/** The currently active state, or undefined if none. */
|
|
271
|
+
get current() {
|
|
272
|
+
return this._current;
|
|
273
|
+
}
|
|
274
|
+
/** Register a state. */
|
|
275
|
+
addState(state) {
|
|
276
|
+
this._states.set(state.name, state);
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Register a transition.
|
|
281
|
+
* When `trigger` fires in `fromState`, transition to `toState`.
|
|
282
|
+
*/
|
|
283
|
+
addTransition(fromState, trigger, toState) {
|
|
284
|
+
let map = this._transitions.get(fromState);
|
|
285
|
+
if (!map) {
|
|
286
|
+
map = /* @__PURE__ */ new Map();
|
|
287
|
+
this._transitions.set(fromState, map);
|
|
288
|
+
}
|
|
289
|
+
map.set(trigger, toState);
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
292
|
+
/** Set the initial state (calls onEnter). */
|
|
293
|
+
start(stateName) {
|
|
294
|
+
const state = this._states.get(stateName);
|
|
295
|
+
if (!state) return;
|
|
296
|
+
this._current = state;
|
|
297
|
+
state.onEnter?.(this._context);
|
|
298
|
+
}
|
|
299
|
+
/** Fire a trigger. If a matching transition exists, switch states. */
|
|
300
|
+
trigger(name) {
|
|
301
|
+
if (!this._current) return;
|
|
302
|
+
const transitions = this._transitions.get(this._current.name);
|
|
303
|
+
if (!transitions) return;
|
|
304
|
+
const target = transitions.get(name);
|
|
305
|
+
if (target === void 0) return;
|
|
306
|
+
const next = this._states.get(target);
|
|
307
|
+
if (!next) return;
|
|
308
|
+
this._current.onExit?.(this._context);
|
|
309
|
+
this._current = next;
|
|
310
|
+
next.onEnter?.(this._context);
|
|
311
|
+
}
|
|
312
|
+
/** Update the current state. */
|
|
313
|
+
update(dt) {
|
|
314
|
+
this._current?.onUpdate?.(dt, this._context);
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/components.ts
|
|
319
|
+
var Position = defineComponent("Position", () => ({
|
|
320
|
+
x: 0,
|
|
321
|
+
y: 0
|
|
322
|
+
}));
|
|
323
|
+
var Velocity = defineComponent("Velocity", () => ({
|
|
324
|
+
x: 0,
|
|
325
|
+
y: 0
|
|
326
|
+
}));
|
|
327
|
+
var Rotation = defineComponent("Rotation", () => ({
|
|
328
|
+
angle: 0
|
|
329
|
+
}));
|
|
330
|
+
var Scale = defineComponent("Scale", () => ({ x: 1, y: 1 }));
|
|
331
|
+
var Parent = defineComponent("Parent", () => ({
|
|
332
|
+
entity: 0
|
|
333
|
+
}));
|
|
334
|
+
export {
|
|
335
|
+
FSM,
|
|
336
|
+
Parent,
|
|
337
|
+
Position,
|
|
338
|
+
Query,
|
|
339
|
+
QueryBuilder,
|
|
340
|
+
Rotation,
|
|
341
|
+
Scale,
|
|
342
|
+
Velocity,
|
|
343
|
+
World,
|
|
344
|
+
_resetComponentIds,
|
|
345
|
+
defineComponent,
|
|
346
|
+
definePrefab,
|
|
347
|
+
defineSystem
|
|
348
|
+
};
|
|
349
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/component.ts","../src/query.ts","../src/world.ts","../src/system.ts","../src/prefab.ts","../src/fsm.ts","../src/components.ts"],"sourcesContent":["/**\n * Component definition and factory.\n *\n * Components are plain data objects. Each component type gets a unique\n * bit for archetype-based query matching.\n */\n\n/** A unique component definition. */\nexport interface ComponentDef<T> {\n /** Internal unique ID (auto-assigned). */\n readonly id: number;\n /** Bitmask for this component (1 << id). */\n readonly bit: number;\n /** Component name for debugging. */\n readonly name: string;\n /** Create a new instance with default values. */\n create(): T;\n}\n\nlet nextComponentId = 0;\n\n/**\n * Define a new component type.\n *\n * @param name Debug name for the component.\n * @param defaults Factory function returning default values, or undefined for tag components.\n */\nexport function defineComponent<T = undefined>(name: string, defaults?: () => T): ComponentDef<T> {\n const id = nextComponentId++;\n if (id >= 32) {\n throw new Error(`Maximum 32 component types exceeded (defining \"${name}\")`);\n }\n return {\n id,\n bit: 1 << id,\n name,\n create: defaults ?? (() => undefined as T),\n };\n}\n\n/**\n * Reset the component ID counter. Only for testing.\n * @internal\n */\nexport function _resetComponentIds(): void {\n nextComponentId = 0;\n}\n","import { Signal } from '@flare-engine/events';\nimport type { ComponentDef } from './component.js';\n\n/**\n * Query matches entities based on component archetypes.\n *\n * Uses bitmask matching: entity archetype & requiredMask === requiredMask\n * and entity archetype & excludedMask === 0.\n */\nexport class Query {\n /** Bitmask of required components. */\n readonly requiredMask: number;\n /** Bitmask of excluded components. */\n readonly excludedMask: number;\n\n /** Fires when an entity is added to this query's results. */\n readonly onEntityAdded = new Signal<number>();\n /** Fires when an entity is removed from this query's results. */\n readonly onEntityRemoved = new Signal<number>();\n\n /** Sorted array of matching entity IDs. */\n private entities: number[] = [];\n /** Set for O(1) membership check. */\n private entitySet = new Set<number>();\n\n constructor(requiredMask: number, excludedMask: number) {\n this.requiredMask = requiredMask;\n this.excludedMask = excludedMask;\n }\n\n /** Check if an archetype matches this query. */\n matches(archetype: number): boolean {\n return (\n (archetype & this.requiredMask) === this.requiredMask && (archetype & this.excludedMask) === 0\n );\n }\n\n /** @internal — called by World when an entity's archetype changes. */\n _check(entityId: number, archetype: number): void {\n const isMatch = this.matches(archetype);\n const wasMatch = this.entitySet.has(entityId);\n\n if (isMatch && !wasMatch) {\n this.entitySet.add(entityId);\n this.entities.push(entityId);\n this.onEntityAdded.emit(entityId);\n } else if (!isMatch && wasMatch) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** @internal — called by World when an entity is removed entirely. */\n _remove(entityId: number): void {\n if (this.entitySet.has(entityId)) {\n this.entitySet.delete(entityId);\n const idx = this.entities.indexOf(entityId);\n if (idx !== -1) this.entities.splice(idx, 1);\n this.onEntityRemoved.emit(entityId);\n }\n }\n\n /** Iterate matching entity IDs. */\n [Symbol.iterator](): IterableIterator<number> {\n return this.entities[Symbol.iterator]();\n }\n\n /** Number of matching entities. */\n get count(): number {\n return this.entities.length;\n }\n\n /** Check if an entity matches this query. */\n has(entityId: number): boolean {\n return this.entitySet.has(entityId);\n }\n}\n\n/** Builder for creating queries with .with() / .without() chaining. */\nexport class QueryBuilder {\n private required = 0;\n private excluded = 0;\n\n with(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.required |= c.bit;\n }\n return this;\n }\n\n without(...components: ComponentDef<unknown>[]): this {\n for (const c of components) {\n this.excluded |= c.bit;\n }\n return this;\n }\n\n /** Build the query (called internally by World). */\n build(): Query {\n return new Query(this.required, this.excluded);\n }\n}\n","import type { ComponentDef } from './component.js';\nimport { Query, QueryBuilder } from './query.js';\n\n/**\n * World is the central ECS container.\n *\n * Entities are integer IDs. Components are stored in per-component Maps.\n * Archetype bitmasks enable fast query matching.\n */\nexport class World {\n private nextId = 1;\n private archetypes = new Map<number, number>(); // entityId → bitmask\n private componentStores = new Map<number, Map<number, unknown>>(); // componentId → (entityId → data)\n private queries: Query[] = [];\n private systems: {\n fn: (world: World, dt: number) => void;\n priority: number;\n }[] = [];\n private systemsSorted = false;\n\n /** Create a new entity. Returns the entity ID. */\n spawn(): number {\n const id = this.nextId++;\n this.archetypes.set(id, 0);\n return id;\n }\n\n /** Remove an entity and all its components. */\n destroy(entityId: number): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Remove from all component stores\n for (const [, store] of this.componentStores) {\n store.delete(entityId);\n }\n\n this.archetypes.delete(entityId);\n\n // Notify queries\n for (const query of this.queries) {\n query._remove(entityId);\n }\n }\n\n /** Add a component to an entity. */\n add<T>(entityId: number, def: ComponentDef<T>, data?: T): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n // Store component data\n let store = this.componentStores.get(def.id);\n if (!store) {\n store = new Map();\n this.componentStores.set(def.id, store);\n }\n store.set(entityId, data !== undefined ? data : def.create());\n\n // Update archetype\n const newArch = arch | def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Remove a component from an entity. */\n remove<T>(entityId: number, def: ComponentDef<T>): void {\n const arch = this.archetypes.get(entityId);\n if (arch === undefined) return;\n\n const store = this.componentStores.get(def.id);\n if (store) store.delete(entityId);\n\n const newArch = arch & ~def.bit;\n this.archetypes.set(entityId, newArch);\n\n // Notify queries\n for (const query of this.queries) {\n query._check(entityId, newArch);\n }\n }\n\n /** Get component data for an entity. */\n get<T>(entityId: number, def: ComponentDef<T>): T | undefined {\n const store = this.componentStores.get(def.id);\n return store?.get(entityId) as T | undefined;\n }\n\n /** Check if entity has a component. */\n has(entityId: number, def: ComponentDef<unknown>): boolean {\n const arch = this.archetypes.get(entityId);\n return arch !== undefined && (arch & def.bit) !== 0;\n }\n\n /** Check if entity exists. */\n exists(entityId: number): boolean {\n return this.archetypes.has(entityId);\n }\n\n /**\n * Create a query. Queries auto-update as entities change.\n * Use the QueryBuilder-style chaining:\n * world.query(Position, Velocity)\n * Or use the builder:\n * world.queryBuilder().with(Position).without(Dead).build()\n */\n query(...components: ComponentDef<unknown>[]): Query {\n let mask = 0;\n for (const c of components) {\n mask |= c.bit;\n }\n const q = new Query(mask, 0);\n this.queries.push(q);\n\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n\n return q;\n }\n\n /** Create a QueryBuilder for complex queries (with/without). */\n queryBuilder(): QueryBuilder {\n return new _WorldQueryBuilder(this);\n }\n\n /** Register a system function. Lower priority runs first. */\n addSystem(fn: (world: World, dt: number) => void, priority = 0): void {\n this.systems.push({ fn, priority });\n this.systemsSorted = false;\n }\n\n /** Remove a system. */\n removeSystem(fn: (world: World, dt: number) => void): void {\n const idx = this.systems.findIndex((s) => s.fn === fn);\n if (idx !== -1) this.systems.splice(idx, 1);\n }\n\n /** Run all systems in priority order. */\n step(dt: number): void {\n if (!this.systemsSorted) {\n this.systems.sort((a, b) => a.priority - b.priority);\n this.systemsSorted = true;\n }\n for (const sys of this.systems) {\n sys.fn(this, dt);\n }\n }\n\n /** @internal Register a query for auto-update. */\n _registerQuery(q: Query): void {\n this.queries.push(q);\n // Populate with existing entities\n for (const [entityId, arch] of this.archetypes) {\n q._check(entityId, arch);\n }\n }\n}\n\n/**\n * Internal query builder that auto-registers with a World.\n */\nclass _WorldQueryBuilder extends QueryBuilder {\n private world: World;\n\n constructor(world: World) {\n super();\n this.world = world;\n }\n\n override build(): Query {\n const q = super.build();\n this.world._registerQuery(q);\n return q;\n }\n}\n","import type { Query } from './query.js';\nimport type { World } from './world.js';\n\n/** A system function that processes entities matching a query. */\nexport type SystemFn = (entities: Query, dt: number, world: World) => void;\n\n/** A defined system with its query and function. */\nexport interface SystemDef {\n readonly query: Query;\n readonly fn: SystemFn;\n /** The wrapper registered on the World (used for removal). */\n readonly _worldFn: (world: World, dt: number) => void;\n}\n\n/**\n * Define a system that processes entities matching a query.\n *\n * Returns a SystemDef that can be added to a World via world.addSystem().\n * The system function receives the query's matching entities, dt, and world.\n *\n * Usage:\n * const q = world.query(Position, Velocity);\n * const moveSys = defineSystem(q, (entities, dt, world) => {\n * for (const id of entities) { ... }\n * });\n * world.addSystem(moveSys._worldFn);\n */\nexport function defineSystem(query: Query, fn: SystemFn): SystemDef {\n const worldFn = (world: World, dt: number) => {\n fn(query, dt, world);\n };\n return { query, fn, _worldFn: worldFn };\n}\n","import type { ComponentDef } from './component.js';\nimport type { World } from './world.js';\n\n/** A component entry in a prefab definition. */\ninterface PrefabEntry<T> {\n def: ComponentDef<T>;\n data?: T | (() => T);\n}\n\n/** A prefab factory that spawns entities with pre-defined components. */\nexport interface Prefab {\n readonly name: string;\n /** Spawn an entity with this prefab's components. */\n spawn(world: World, overrides?: Record<string, unknown>): number;\n}\n\n/**\n * Define a prefab — a template for spawning entities with a fixed set of components.\n *\n * @param name Debug name.\n * @param entries Array of [componentDef, data?] tuples.\n */\nexport function definePrefab(\n name: string,\n ...entries: [ComponentDef<unknown>, (unknown | (() => unknown))?][]\n): Prefab {\n const components: PrefabEntry<unknown>[] = entries.map(([def, data]) => ({\n def,\n data,\n }));\n\n return {\n name,\n spawn(world: World): number {\n const entity = world.spawn();\n for (const entry of components) {\n const data =\n typeof entry.data === 'function' ? (entry.data as () => unknown)() : entry.data;\n world.add(entity, entry.def, data);\n }\n return entity;\n },\n };\n}\n","/** A state in the FSM. */\nexport interface State<C = undefined> {\n readonly name: string;\n onEnter?(context: C): void;\n onExit?(context: C): void;\n onUpdate?(dt: number, context: C): void;\n}\n\n/**\n * Lightweight finite state machine. ~100 LOC.\n *\n * Manages named states with onEnter/onExit/onUpdate hooks\n * and string-keyed transitions.\n */\nexport class FSM<C = undefined> {\n private _current: State<C> | undefined;\n private _states = new Map<string, State<C>>();\n private _transitions = new Map<string, Map<string, string>>();\n private _context: C;\n\n constructor(...args: C extends undefined ? [] : [context: C]) {\n this._context = args[0] as C;\n }\n\n /** The currently active state, or undefined if none. */\n get current(): State<C> | undefined {\n return this._current;\n }\n\n /** Register a state. */\n addState(state: State<C>): this {\n this._states.set(state.name, state);\n return this;\n }\n\n /**\n * Register a transition.\n * When `trigger` fires in `fromState`, transition to `toState`.\n */\n addTransition(fromState: string, trigger: string, toState: string): this {\n let map = this._transitions.get(fromState);\n if (!map) {\n map = new Map();\n this._transitions.set(fromState, map);\n }\n map.set(trigger, toState);\n return this;\n }\n\n /** Set the initial state (calls onEnter). */\n start(stateName: string): void {\n const state = this._states.get(stateName);\n if (!state) return;\n this._current = state;\n state.onEnter?.(this._context);\n }\n\n /** Fire a trigger. If a matching transition exists, switch states. */\n trigger(name: string): void {\n if (!this._current) return;\n const transitions = this._transitions.get(this._current.name);\n if (!transitions) return;\n const target = transitions.get(name);\n if (target === undefined) return;\n const next = this._states.get(target);\n if (!next) return;\n this._current.onExit?.(this._context);\n this._current = next;\n next.onEnter?.(this._context);\n }\n\n /** Update the current state. */\n update(dt: number): void {\n this._current?.onUpdate?.(dt, this._context);\n }\n}\n","import type { Vec2 } from '@flare-engine/math';\nimport { defineComponent } from './component.js';\n\n/**\n * Built-in ECS components using @flare-engine/math types.\n */\n\n/** 2D position component. */\nexport const Position = defineComponent<Vec2>('Position', () => ({\n x: 0,\n y: 0,\n}));\n\n/** 2D velocity component. */\nexport const Velocity = defineComponent<Vec2>('Velocity', () => ({\n x: 0,\n y: 0,\n}));\n\n/** Rotation in radians. */\nexport const Rotation = defineComponent<{ angle: number }>('Rotation', () => ({\n angle: 0,\n}));\n\n/** 2D scale component. */\nexport const Scale = defineComponent<Vec2>('Scale', () => ({ x: 1, y: 1 }));\n\n/** Parent entity reference. */\nexport const Parent = defineComponent<{ entity: number }>('Parent', () => ({\n entity: 0,\n}));\n"],"mappings":";AAmBA,IAAI,kBAAkB;AAQf,SAAS,gBAA+B,MAAc,UAAqC;AAChG,QAAM,KAAK;AACX,MAAI,MAAM,IAAI;AACZ,UAAM,IAAI,MAAM,kDAAkD,IAAI,IAAI;AAAA,EAC5E;AACA,SAAO;AAAA,IACL;AAAA,IACA,KAAK,KAAK;AAAA,IACV;AAAA,IACA,QAAQ,aAAa,MAAM;AAAA,EAC7B;AACF;AAMO,SAAS,qBAA2B;AACzC,oBAAkB;AACpB;;;AC9CA,SAAS,cAAc;AAShB,IAAM,QAAN,MAAY;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAGA,gBAAgB,IAAI,OAAe;AAAA;AAAA,EAEnC,kBAAkB,IAAI,OAAe;AAAA;AAAA,EAGtC,WAAqB,CAAC;AAAA;AAAA,EAEtB,YAAY,oBAAI,IAAY;AAAA,EAEpC,YAAY,cAAsB,cAAsB;AACtD,SAAK,eAAe;AACpB,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,QAAQ,WAA4B;AAClC,YACG,YAAY,KAAK,kBAAkB,KAAK,iBAAiB,YAAY,KAAK,kBAAkB;AAAA,EAEjG;AAAA;AAAA,EAGA,OAAO,UAAkB,WAAyB;AAChD,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AAkB;AACvB,SAAK,UAAU,WAAW,IAAI,KAAK,QAAQ;AAAA,EAC7C;AACF;;;ACnEO,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAsB,YAAY,OAAO;AAAA,EAC/D,GAAG;AAAA,EACH,GAAG;AACL,EAAE;AAGK,IAAM,WAAW,gBAAmC,YAAY,OAAO;AAAA,EAC5E,OAAO;AACT,EAAE;AAGK,IAAM,QAAQ,gBAAsB,SAAS,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE;AAGnE,IAAM,SAAS,gBAAoC,UAAU,OAAO;AAAA,EACzE,QAAQ;AACV,EAAE;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flare-engine/ecs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Entity-Component-System with archetype queries",
|
|
5
|
+
"keywords": ["flare-engine", "ecs", "entity-component-system"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Grzegorz Otto",
|
|
8
|
+
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/grzott/flare-engine/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/grzott/flare-engine.git",
|
|
15
|
+
"directory": "packages/ecs"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"lint": "biome check src/",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@flare-engine/events": "^0.1.0",
|
|
36
|
+
"@flare-engine/math": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "restricted",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false
|
|
43
|
+
}
|