dino-ge 1.2.0 → 1.2.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/GameObject.d.ts +34 -6
- package/dist/GameObject.js +38 -4
- package/dist/GameObject.js.map +1 -1
- package/dist/TagComponent.d.ts +11 -0
- package/dist/TagComponent.js +12 -0
- package/dist/TagComponent.js.map +1 -0
- package/dist/VisibilityComponent.d.ts +8 -0
- package/dist/VisibilityComponent.js +12 -0
- package/dist/VisibilityComponent.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/GameObject.ts +47 -11
- package/src/TagComponent.ts +17 -0
- package/src/VisibilityComponent.ts +9 -0
- package/src/index.ts +2 -0
package/dist/GameObject.d.ts
CHANGED
|
@@ -6,18 +6,32 @@ import Component from './Component.js';
|
|
|
6
6
|
* Acts as the 'Entity' in our evolving Entity Component System.
|
|
7
7
|
*/
|
|
8
8
|
export default abstract class GameObject {
|
|
9
|
-
/** A unique identifier for the object type. */
|
|
10
|
-
tag: string;
|
|
11
|
-
/** Rendering order (lower is background, higher is foreground). */
|
|
12
|
-
zIndex: number;
|
|
13
9
|
/** Collection of components attached to this entity. */
|
|
14
10
|
private _components;
|
|
15
|
-
/** Whether the object should be rendered. */
|
|
16
|
-
visible: boolean;
|
|
17
11
|
/** Internal components for backward compatibility and core logic. */
|
|
18
12
|
private _physics;
|
|
19
13
|
private _transform;
|
|
14
|
+
private _tag;
|
|
15
|
+
private _visibility;
|
|
20
16
|
constructor(tag: string, zIndex: number);
|
|
17
|
+
/**
|
|
18
|
+
* A unique identifier for the object type.
|
|
19
|
+
* @deprecated Use getComponent(TagComponent).tag
|
|
20
|
+
*/
|
|
21
|
+
get tag(): string;
|
|
22
|
+
set tag(val: string);
|
|
23
|
+
/**
|
|
24
|
+
* Rendering order (lower is background, higher is foreground).
|
|
25
|
+
* @deprecated Use getComponent(TagComponent).zIndex
|
|
26
|
+
*/
|
|
27
|
+
get zIndex(): number;
|
|
28
|
+
set zIndex(val: number);
|
|
29
|
+
/**
|
|
30
|
+
* Whether the object should be rendered.
|
|
31
|
+
* @deprecated Use getComponent(VisibilityComponent).visible
|
|
32
|
+
*/
|
|
33
|
+
get visible(): boolean;
|
|
34
|
+
set visible(val: boolean);
|
|
21
35
|
/**
|
|
22
36
|
* The world-space position of the object.
|
|
23
37
|
* Proxies to the TransformComponent.
|
|
@@ -53,6 +67,20 @@ export default abstract class GameObject {
|
|
|
53
67
|
* @param component The component to add.
|
|
54
68
|
*/
|
|
55
69
|
addComponent(component: Component): void;
|
|
70
|
+
/**
|
|
71
|
+
* Removes a component from this entity by its class.
|
|
72
|
+
* @param componentClass The class of the component to remove.
|
|
73
|
+
*/
|
|
74
|
+
removeComponent<T extends Component>(componentClass: {
|
|
75
|
+
new (...args: any[]): T;
|
|
76
|
+
}): void;
|
|
77
|
+
/**
|
|
78
|
+
* Checks if this entity has a component of the specified class.
|
|
79
|
+
* @param componentClass The class of the component to check for.
|
|
80
|
+
*/
|
|
81
|
+
hasComponent<T extends Component>(componentClass: {
|
|
82
|
+
new (...args: any[]): T;
|
|
83
|
+
}): boolean;
|
|
56
84
|
/** Gets a component from this entity by its class.
|
|
57
85
|
* @param componentClass The class of the component to retrieve.
|
|
58
86
|
*/
|
package/dist/GameObject.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Engine from './Engine.js';
|
|
2
2
|
import PhysicsComponent from './PhysicsComponent.js';
|
|
3
3
|
import TransformComponent from './TransformComponent.js';
|
|
4
|
+
import TagComponent from './TagComponent.js';
|
|
5
|
+
import VisibilityComponent from './VisibilityComponent.js';
|
|
4
6
|
/**
|
|
5
7
|
* Base class for all entities in the game world.
|
|
6
8
|
* Provides properties for physics, rendering, and lifecycle management.
|
|
@@ -10,17 +12,35 @@ export default class GameObject {
|
|
|
10
12
|
constructor(tag, zIndex) {
|
|
11
13
|
/** Collection of components attached to this entity. */
|
|
12
14
|
this._components = new Map();
|
|
13
|
-
/** Whether the object should be rendered. */
|
|
14
|
-
this.visible = true;
|
|
15
|
-
this.tag = tag;
|
|
16
|
-
this.zIndex = zIndex;
|
|
17
15
|
// Initialize with core components for now to maintain backward compatibility.
|
|
18
16
|
// In a pure ECS, components would be added as needed.
|
|
17
|
+
this._tag = new TagComponent(tag, zIndex);
|
|
18
|
+
this.addComponent(this._tag);
|
|
19
|
+
this._visibility = new VisibilityComponent();
|
|
20
|
+
this.addComponent(this._visibility);
|
|
19
21
|
this._physics = new PhysicsComponent();
|
|
20
22
|
this.addComponent(this._physics);
|
|
21
23
|
this._transform = new TransformComponent();
|
|
22
24
|
this.addComponent(this._transform);
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A unique identifier for the object type.
|
|
28
|
+
* @deprecated Use getComponent(TagComponent).tag
|
|
29
|
+
*/
|
|
30
|
+
get tag() { return this._tag.tag; }
|
|
31
|
+
set tag(val) { this._tag.tag = val; }
|
|
32
|
+
/**
|
|
33
|
+
* Rendering order (lower is background, higher is foreground).
|
|
34
|
+
* @deprecated Use getComponent(TagComponent).zIndex
|
|
35
|
+
*/
|
|
36
|
+
get zIndex() { return this._tag.zIndex; }
|
|
37
|
+
set zIndex(val) { this._tag.zIndex = val; }
|
|
38
|
+
/**
|
|
39
|
+
* Whether the object should be rendered.
|
|
40
|
+
* @deprecated Use getComponent(VisibilityComponent).visible
|
|
41
|
+
*/
|
|
42
|
+
get visible() { return this._visibility.visible; }
|
|
43
|
+
set visible(val) { this._visibility.visible = val; }
|
|
24
44
|
/**
|
|
25
45
|
* The world-space position of the object.
|
|
26
46
|
* Proxies to the TransformComponent.
|
|
@@ -60,6 +80,20 @@ export default class GameObject {
|
|
|
60
80
|
this._components.set(key, component);
|
|
61
81
|
component.gameObject = this;
|
|
62
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Removes a component from this entity by its class.
|
|
85
|
+
* @param componentClass The class of the component to remove.
|
|
86
|
+
*/
|
|
87
|
+
removeComponent(componentClass) {
|
|
88
|
+
this._components.delete(componentClass.name);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Checks if this entity has a component of the specified class.
|
|
92
|
+
* @param componentClass The class of the component to check for.
|
|
93
|
+
*/
|
|
94
|
+
hasComponent(componentClass) {
|
|
95
|
+
return this._components.has(componentClass.name);
|
|
96
|
+
}
|
|
63
97
|
/** Gets a component from this entity by its class.
|
|
64
98
|
* @param componentClass The class of the component to retrieve.
|
|
65
99
|
*/
|
package/dist/GameObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GameObject.js","sourceRoot":"","sources":["../src/GameObject.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"GameObject.js","sourceRoot":"","sources":["../src/GameObject.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAUtC,YAAY,GAAW,EAAE,MAAc;QATvC,wDAAwD;QAChD,gBAAW,GAA2B,IAAI,GAAG,EAAE,CAAC;QAStD,8EAA8E;QAC9E,sDAAsD;QACtD,IAAI,CAAC,IAAI,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE7B,IAAI,CAAC,WAAW,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC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D;;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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component that holds metadata like tags and rendering order.
|
|
4
|
+
*/
|
|
5
|
+
export default class TagComponent extends Component {
|
|
6
|
+
/** A unique identifier for the object type. */
|
|
7
|
+
tag: string;
|
|
8
|
+
/** Rendering order (lower is background, higher is foreground). */
|
|
9
|
+
zIndex: number;
|
|
10
|
+
constructor(tag?: string, zIndex?: number);
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component that holds metadata like tags and rendering order.
|
|
4
|
+
*/
|
|
5
|
+
export default class TagComponent extends Component {
|
|
6
|
+
constructor(tag = 'obj', zIndex = 0) {
|
|
7
|
+
super();
|
|
8
|
+
this.tag = tag;
|
|
9
|
+
this.zIndex = zIndex;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=TagComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TagComponent.js","sourceRoot":"","sources":["../src/TagComponent.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IAMjD,YAAY,MAAc,KAAK,EAAE,SAAiB,CAAC;QACjD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
/**
|
|
3
|
+
* Component that determines whether an object should be rendered.
|
|
4
|
+
*/
|
|
5
|
+
export default class VisibilityComponent extends Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
/** Whether the object should be rendered. */
|
|
9
|
+
this.visible = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=VisibilityComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisibilityComponent.js","sourceRoot":"","sources":["../src/VisibilityComponent.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,SAAS;IAA1D;;QACE,6CAA6C;QAC7C,YAAO,GAAY,IAAI,CAAC;IAC1B,CAAC;CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { default as GameObject } from './GameObject.js';
|
|
|
4
4
|
export { default as Component } from './Component.js';
|
|
5
5
|
export { default as PhysicsComponent } from './PhysicsComponent.js';
|
|
6
6
|
export { default as TransformComponent } from './TransformComponent.js';
|
|
7
|
+
export { default as TagComponent } from './TagComponent.js';
|
|
8
|
+
export { default as VisibilityComponent } from './VisibilityComponent.js';
|
|
7
9
|
export { default as Sprite } from './Sprite.js';
|
|
8
10
|
export { default as Vector2 } from './Vector2.js';
|
|
9
11
|
export { default as Camera } from './Camera.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ export { default as GameObject } from './GameObject.js';
|
|
|
4
4
|
export { default as Component } from './Component.js';
|
|
5
5
|
export { default as PhysicsComponent } from './PhysicsComponent.js';
|
|
6
6
|
export { default as TransformComponent } from './TransformComponent.js';
|
|
7
|
+
export { default as TagComponent } from './TagComponent.js';
|
|
8
|
+
export { default as VisibilityComponent } from './VisibilityComponent.js';
|
|
7
9
|
export { default as Sprite } from './Sprite.js';
|
|
8
10
|
export { default as Vector2 } from './Vector2.js';
|
|
9
11
|
export { default as Camera } from './Camera.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,OAAO,EA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AI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
CHANGED
package/src/GameObject.ts
CHANGED
|
@@ -3,6 +3,8 @@ import Vector2 from './Vector2.js';
|
|
|
3
3
|
import Component from './Component.js';
|
|
4
4
|
import PhysicsComponent from './PhysicsComponent.js';
|
|
5
5
|
import TransformComponent from './TransformComponent.js';
|
|
6
|
+
import TagComponent from './TagComponent.js';
|
|
7
|
+
import VisibilityComponent from './VisibilityComponent.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Base class for all entities in the game world.
|
|
@@ -10,27 +12,24 @@ import TransformComponent from './TransformComponent.js';
|
|
|
10
12
|
* Acts as the 'Entity' in our evolving Entity Component System.
|
|
11
13
|
*/
|
|
12
14
|
export default abstract class GameObject {
|
|
13
|
-
/** A unique identifier for the object type. */
|
|
14
|
-
tag: string;
|
|
15
|
-
/** Rendering order (lower is background, higher is foreground). */
|
|
16
|
-
zIndex: number;
|
|
17
|
-
|
|
18
15
|
/** Collection of components attached to this entity. */
|
|
19
16
|
private _components: Map<string, Component> = new Map();
|
|
20
17
|
|
|
21
|
-
/** Whether the object should be rendered. */
|
|
22
|
-
visible: boolean = true;
|
|
23
|
-
|
|
24
18
|
/** Internal components for backward compatibility and core logic. */
|
|
25
19
|
private _physics: PhysicsComponent;
|
|
26
20
|
private _transform: TransformComponent;
|
|
21
|
+
private _tag: TagComponent;
|
|
22
|
+
private _visibility: VisibilityComponent;
|
|
27
23
|
|
|
28
24
|
constructor(tag: string, zIndex: number) {
|
|
29
|
-
this.tag = tag;
|
|
30
|
-
this.zIndex = zIndex;
|
|
31
|
-
|
|
32
25
|
// Initialize with core components for now to maintain backward compatibility.
|
|
33
26
|
// In a pure ECS, components would be added as needed.
|
|
27
|
+
this._tag = new TagComponent(tag, zIndex);
|
|
28
|
+
this.addComponent(this._tag);
|
|
29
|
+
|
|
30
|
+
this._visibility = new VisibilityComponent();
|
|
31
|
+
this.addComponent(this._visibility);
|
|
32
|
+
|
|
34
33
|
this._physics = new PhysicsComponent();
|
|
35
34
|
this.addComponent(this._physics);
|
|
36
35
|
|
|
@@ -38,6 +37,27 @@ export default abstract class GameObject {
|
|
|
38
37
|
this.addComponent(this._transform);
|
|
39
38
|
}
|
|
40
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A unique identifier for the object type.
|
|
42
|
+
* @deprecated Use getComponent(TagComponent).tag
|
|
43
|
+
*/
|
|
44
|
+
get tag(): string { return this._tag.tag; }
|
|
45
|
+
set tag(val: string) { this._tag.tag = val; }
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Rendering order (lower is background, higher is foreground).
|
|
49
|
+
* @deprecated Use getComponent(TagComponent).zIndex
|
|
50
|
+
*/
|
|
51
|
+
get zIndex(): number { return this._tag.zIndex; }
|
|
52
|
+
set zIndex(val: number) { this._tag.zIndex = val; }
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether the object should be rendered.
|
|
56
|
+
* @deprecated Use getComponent(VisibilityComponent).visible
|
|
57
|
+
*/
|
|
58
|
+
get visible(): boolean { return this._visibility.visible; }
|
|
59
|
+
set visible(val: boolean) { this._visibility.visible = val; }
|
|
60
|
+
|
|
41
61
|
/**
|
|
42
62
|
* The world-space position of the object.
|
|
43
63
|
* Proxies to the TransformComponent.
|
|
@@ -83,6 +103,22 @@ export default abstract class GameObject {
|
|
|
83
103
|
component.gameObject = this;
|
|
84
104
|
}
|
|
85
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Removes a component from this entity by its class.
|
|
108
|
+
* @param componentClass The class of the component to remove.
|
|
109
|
+
*/
|
|
110
|
+
removeComponent<T extends Component>(componentClass: { new (...args: any[]): T }) {
|
|
111
|
+
this._components.delete(componentClass.name);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Checks if this entity has a component of the specified class.
|
|
116
|
+
* @param componentClass The class of the component to check for.
|
|
117
|
+
*/
|
|
118
|
+
hasComponent<T extends Component>(componentClass: { new (...args: any[]): T }): boolean {
|
|
119
|
+
return this._components.has(componentClass.name);
|
|
120
|
+
}
|
|
121
|
+
|
|
86
122
|
/** Gets a component from this entity by its class.
|
|
87
123
|
* @param componentClass The class of the component to retrieve.
|
|
88
124
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Component from './Component.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component that holds metadata like tags and rendering order.
|
|
5
|
+
*/
|
|
6
|
+
export default class TagComponent extends Component {
|
|
7
|
+
/** A unique identifier for the object type. */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** Rendering order (lower is background, higher is foreground). */
|
|
10
|
+
zIndex: number;
|
|
11
|
+
|
|
12
|
+
constructor(tag: string = 'obj', zIndex: number = 0) {
|
|
13
|
+
super();
|
|
14
|
+
this.tag = tag;
|
|
15
|
+
this.zIndex = zIndex;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { default as GameObject } from './GameObject.js';
|
|
|
4
4
|
export { default as Component } from './Component.js';
|
|
5
5
|
export { default as PhysicsComponent } from './PhysicsComponent.js';
|
|
6
6
|
export { default as TransformComponent } from './TransformComponent.js';
|
|
7
|
+
export { default as TagComponent } from './TagComponent.js';
|
|
8
|
+
export { default as VisibilityComponent } from './VisibilityComponent.js';
|
|
7
9
|
export { default as Sprite } from './Sprite.js';
|
|
8
10
|
export { default as Vector2 } from './Vector2.js';
|
|
9
11
|
export { default as Camera } from './Camera.js';
|