dino-ge 1.5.0 → 1.6.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.
@@ -52,12 +52,15 @@ export default class GameObject {
52
52
  * @param component The component to add.
53
53
  */
54
54
  addComponent(component) {
55
- const key = component.constructor.name;
56
- this._components.set(key, component);
57
- // Also index by RenderComponent if it is one, to allow abstract querying.
58
- // Use flag instead of instanceof to work across potential module duplications.
59
- if (component.isRenderComponent) {
60
- this._components.set('RenderComponent', component);
55
+ // Index the component by its class name and all base class names up to Component.
56
+ let proto = Object.getPrototypeOf(component);
57
+ while (proto && proto.constructor.name !== 'Object') {
58
+ const key = proto.constructor.name;
59
+ this._components.set(key, component);
60
+ // Stop walking once we've indexed up to the base Component class.
61
+ if (key === 'Component')
62
+ break;
63
+ proto = Object.getPrototypeOf(proto);
61
64
  }
62
65
  component.gameObject = this;
63
66
  }
@@ -66,7 +69,15 @@ export default class GameObject {
66
69
  * @param componentClass The class of the component to remove.
67
70
  */
68
71
  removeComponent(componentClass) {
69
- this._components.delete(componentClass.name);
72
+ const component = this.getComponent(componentClass);
73
+ if (!component)
74
+ return;
75
+ // Remove all keys that point to this specific component instance.
76
+ for (const [key, value] of this._components.entries()) {
77
+ if (value === component) {
78
+ this._components.delete(key);
79
+ }
80
+ }
70
81
  }
71
82
  /**
72
83
  * Checks if this entity has a component of the specified class.
@@ -1 +1 @@
1
- {"version":3,"file":"GameObject.js","sourceRoot":"","sources":["../src/GameObject.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAE7C,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAWtC,YAAY,GAAW,EAAE,MAAc;QAVvC,wDAAwD;QAChD,gBAAW,GAA2B,IAA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vC,CAAC;QAED,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,eAAe,CAAsB,cAA+C;QAClF,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QACpD,IAAI,CAAC,SAAS;YAAE,OAAO;QAEvB,kEAAkE;QAClE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACtD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,sEAAsE;IACtE,YAAY,CAAsB,cAA4C;QAC5E,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,sEAAsE;IACtE,YAAY,CAAsB,cAA4C;QAC5E,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAM,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,YAAY;QACV,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -3,8 +3,6 @@ import Component from './Component.js';
3
3
  * Base class for all rendering-related components.
4
4
  */
5
5
  export default abstract class RenderComponent extends Component {
6
- /** Internal flag to identify rendering components across module instances. */
7
- readonly isRenderComponent: boolean;
8
6
  /**
9
7
  * The actual rendering logic.
10
8
  * @param ctx The canvas 2D rendering context.
@@ -3,10 +3,5 @@ import Component from './Component.js';
3
3
  * Base class for all rendering-related components.
4
4
  */
5
5
  export default class RenderComponent extends Component {
6
- constructor() {
7
- super(...arguments);
8
- /** Internal flag to identify rendering components across module instances. */
9
- this.isRenderComponent = true;
10
- }
11
6
  }
12
7
  //# sourceMappingURL=RenderComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RenderComponent.js","sourceRoot":"","sources":["../src/RenderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAgB,eAAgB,SAAQ,SAAS;IAA/D;;QACE,8EAA8E;QAC9D,sBAAiB,GAAY,IAAI,CAAC;IAOpD,CAAC;CAAA"}
1
+ {"version":3,"file":"RenderComponent.js","sourceRoot":"","sources":["../src/RenderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAgB,eAAgB,SAAQ,SAAS;CAM9D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dino-ge",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Lightweight, performant 2D game engine built with TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",