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.
@@ -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[]): (_method: Function, context: ClassMethodDecoratorContext) => void;
4
- export declare function OnRemoved(...types: ComponentDef[]): (_method: Function, context: ClassMethodDecoratorContext) => void;
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;
@@ -1,17 +1,17 @@
1
1
  // ── Decorators (TC39 Stage 3) ────────────────────────────
2
2
  export function OnAdded(...types) {
3
- return function (_method, context) {
4
- context.addInitializer(function () {
3
+ return function (method, _context) {
4
+ _context.addInitializer(function () {
5
5
  const self = this;
6
- self._registerHook('add', types, self[context.name].bind(self));
6
+ self._registerHook('add', types, method.bind(self));
7
7
  });
8
8
  };
9
9
  }
10
10
  export function OnRemoved(...types) {
11
- return function (_method, context) {
12
- context.addInitializer(function () {
11
+ return function (method, _context) {
12
+ _context.addInitializer(function () {
13
13
  const self = this;
14
- self._registerHook('remove', types, self[context.name].bind(self));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archetype-ecs",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Lightweight archetype-based Entity Component System",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
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 (_method: Function, context: ClassMethodDecoratorContext) {
8
- context.addInitializer(function () {
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, (self as any)[context.name].bind(self));
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 (_method: Function, context: ClassMethodDecoratorContext) {
17
- context.addInitializer(function () {
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, (self as any)[context.name].bind(self));
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 ((Entry as any).prototype instanceof System) {
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);