archetype-ecs 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/System.d.ts +2 -2
- package/dist/src/System.js +7 -7
- package/package.json +1 -1
- package/src/System.ts +7 -7
package/dist/src/System.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentDef } from './ComponentRegistry.js';
|
|
2
2
|
import type { EntityId, EntityManager, ArchetypeView } from './EntityManager.js';
|
|
3
|
-
export declare function OnAdded(...types: ComponentDef[]): (
|
|
4
|
-
export declare function OnRemoved(...types: ComponentDef[]): (
|
|
3
|
+
export declare function OnAdded(...types: ComponentDef[]): (method: (id: EntityId) => void, _context: ClassMethodDecoratorContext) => void;
|
|
4
|
+
export declare function OnRemoved(...types: ComponentDef[]): (method: (id: EntityId) => void, _context: ClassMethodDecoratorContext) => void;
|
|
5
5
|
interface Hook {
|
|
6
6
|
buffer: Set<EntityId>;
|
|
7
7
|
handler: (id: EntityId) => void;
|
package/dist/src/System.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// ── Decorators (TC39 Stage 3) ────────────────────────────
|
|
2
2
|
export function OnAdded(...types) {
|
|
3
|
-
return function (
|
|
4
|
-
|
|
3
|
+
return function (method, _context) {
|
|
4
|
+
_context.addInitializer(function () {
|
|
5
5
|
const self = this;
|
|
6
|
-
self._registerHook('add', types,
|
|
6
|
+
self._registerHook('add', types, method.bind(self));
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
export function OnRemoved(...types) {
|
|
11
|
-
return function (
|
|
12
|
-
|
|
11
|
+
return function (method, _context) {
|
|
12
|
+
_context.addInitializer(function () {
|
|
13
13
|
const self = this;
|
|
14
|
-
self._registerHook('remove', types,
|
|
14
|
+
self._registerHook('remove', types, method.bind(self));
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
}
|
|
@@ -121,7 +121,7 @@ export function createSystem(em, constructor) {
|
|
|
121
121
|
}
|
|
122
122
|
export function createSystems(em, entries) {
|
|
123
123
|
const systems = entries.map(Entry => {
|
|
124
|
-
if (Entry.prototype instanceof System) {
|
|
124
|
+
if ('prototype' in Entry && Entry.prototype instanceof System) {
|
|
125
125
|
return new Entry(em);
|
|
126
126
|
}
|
|
127
127
|
const sys = createSystem(em, Entry);
|
package/package.json
CHANGED
package/src/System.ts
CHANGED
|
@@ -4,19 +4,19 @@ import type { EntityId, EntityManager, ArchetypeView } from './EntityManager.js'
|
|
|
4
4
|
// ── Decorators (TC39 Stage 3) ────────────────────────────
|
|
5
5
|
|
|
6
6
|
export function OnAdded(...types: ComponentDef[]) {
|
|
7
|
-
return function (
|
|
8
|
-
|
|
7
|
+
return function (method: (id: EntityId) => void, _context: ClassMethodDecoratorContext) {
|
|
8
|
+
_context.addInitializer(function () {
|
|
9
9
|
const self = this as unknown as System;
|
|
10
|
-
self._registerHook('add', types,
|
|
10
|
+
self._registerHook('add', types, method.bind(self));
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function OnRemoved(...types: ComponentDef[]) {
|
|
16
|
-
return function (
|
|
17
|
-
|
|
16
|
+
return function (method: (id: EntityId) => void, _context: ClassMethodDecoratorContext) {
|
|
17
|
+
_context.addInitializer(function () {
|
|
18
18
|
const self = this as unknown as System;
|
|
19
|
-
self._registerHook('remove', types,
|
|
19
|
+
self._registerHook('remove', types, method.bind(self));
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
}
|
|
@@ -182,7 +182,7 @@ export interface Pipeline {
|
|
|
182
182
|
|
|
183
183
|
export function createSystems(em: EntityManager, entries: (FunctionalSystemConstructor | (new (em: EntityManager) => System))[]): Pipeline {
|
|
184
184
|
const systems: Runnable[] = entries.map(Entry => {
|
|
185
|
-
if (
|
|
185
|
+
if ('prototype' in Entry && Entry.prototype instanceof System) {
|
|
186
186
|
return new (Entry as new (em: EntityManager) => System)(em);
|
|
187
187
|
}
|
|
188
188
|
const sys = createSystem(em, Entry as FunctionalSystemConstructor);
|