emeraldengine 2.0.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/README.md +968 -0
- package/dist/types/imports/BitmapText.d.ts +79 -0
- package/dist/types/imports/Color.d.ts +17 -0
- package/dist/types/imports/Drawable.d.ts +157 -0
- package/dist/types/imports/Emerald.d.ts +73 -0
- package/dist/types/imports/FPSCounter.d.ts +19 -0
- package/dist/types/imports/GLUtils.d.ts +6 -0
- package/dist/types/imports/Instance.d.ts +87 -0
- package/dist/types/imports/InstancedTexture.d.ts +230 -0
- package/dist/types/imports/Physics.d.ts +139 -0
- package/dist/types/imports/Scene.d.ts +39 -0
- package/dist/types/imports/Shaders.d.ts +4 -0
- package/dist/types/imports/Shapes.d.ts +25 -0
- package/dist/types/imports/Storage.d.ts +46 -0
- package/dist/types/imports/Texture.d.ts +19 -0
- package/dist/types/imports/Time.d.ts +22 -0
- package/dist/types/imports/Transform.d.ts +41 -0
- package/dist/types/imports/components/BoxCollider.d.ts +41 -0
- package/dist/types/imports/components/BoxColliderDebug.d.ts +19 -0
- package/dist/types/imports/components/CircleCollider.d.ts +39 -0
- package/dist/types/imports/components/CircleColliderDebug.d.ts +19 -0
- package/dist/types/imports/components/Collider.d.ts +53 -0
- package/dist/types/imports/components/GameObject.d.ts +72 -0
- package/dist/types/imports/components/RigidBody.d.ts +104 -0
- package/dist/types/imports/lights/DirectionalLight.d.ts +26 -0
- package/dist/types/imports/lights/PointLight.d.ts +18 -0
- package/dist/types/imports/managers/AudioManager.d.ts +60 -0
- package/dist/types/imports/managers/CameraManager.d.ts +35 -0
- package/dist/types/imports/managers/EventManager.d.ts +187 -0
- package/dist/types/imports/managers/GLManager.d.ts +47 -0
- package/dist/types/imports/managers/IDManager.d.ts +21 -0
- package/dist/types/imports/managers/SceneManager.d.ts +22 -0
- package/dist/types/imports/particlesystem/Particle.d.ts +42 -0
- package/dist/types/imports/particlesystem/ParticleSettings.d.ts +49 -0
- package/dist/types/imports/particlesystem/Particles.d.ts +71 -0
- package/dist/types/index.d.ts +32 -0
- package/imports/BitmapText.js +245 -0
- package/imports/Color.js +18 -0
- package/imports/Drawable.js +550 -0
- package/imports/Emerald.js +459 -0
- package/imports/FPSCounter.js +43 -0
- package/imports/GLUtils.js +67 -0
- package/imports/Instance.js +187 -0
- package/imports/InstancedTexture.js +856 -0
- package/imports/Physics.js +242 -0
- package/imports/Scene.js +79 -0
- package/imports/Shaders.js +165 -0
- package/imports/Shapes.js +129 -0
- package/imports/Storage.js +63 -0
- package/imports/Texture.js +67 -0
- package/imports/Time.js +28 -0
- package/imports/Transform.js +59 -0
- package/imports/components/BoxCollider.js +67 -0
- package/imports/components/BoxColliderDebug.js +38 -0
- package/imports/components/CircleCollider.js +67 -0
- package/imports/components/CircleColliderDebug.js +36 -0
- package/imports/components/Collider.js +51 -0
- package/imports/components/GameObject.js +160 -0
- package/imports/components/RigidBody.js +169 -0
- package/imports/lights/DirectionalLight.js +68 -0
- package/imports/lights/PointLight.js +17 -0
- package/imports/managers/AudioManager.js +146 -0
- package/imports/managers/CameraManager.js +60 -0
- package/imports/managers/EventManager.js +479 -0
- package/imports/managers/GLManager.js +65 -0
- package/imports/managers/IDManager.js +32 -0
- package/imports/managers/SceneManager.js +27 -0
- package/imports/managers/ShaderManager.js +133 -0
- package/imports/particlesystem/Particle.js +75 -0
- package/imports/particlesystem/ParticleSettings.js +49 -0
- package/imports/particlesystem/Particles.js +226 -0
- package/index.js +67 -0
- package/package.json +38 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import RigidBody from "./components/RigidBody.js";
|
|
2
|
+
import IDManager from "./managers/IDManager.js";
|
|
3
|
+
import { Vector2, Vector3 } from "./Physics.js";
|
|
4
|
+
import Transform from "./Transform.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @class Instance
|
|
8
|
+
* @description Represents an instance
|
|
9
|
+
* @param {string} name - The name of the instance
|
|
10
|
+
* @param {Vector3} position - The position of the instance
|
|
11
|
+
* @param {Vector2} scale - The scale of the instance
|
|
12
|
+
* @param {number} rotation - The rotation of the instance
|
|
13
|
+
* @param {number} frame - The frame of the instance
|
|
14
|
+
*/
|
|
15
|
+
class Instance {
|
|
16
|
+
constructor(
|
|
17
|
+
name,
|
|
18
|
+
position = new Vector3(0, 0, 0),
|
|
19
|
+
scale = new Vector2(1, 1),
|
|
20
|
+
rotation = 0,
|
|
21
|
+
frame = 0
|
|
22
|
+
) {
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.transform = new Transform(position, rotation, scale);
|
|
25
|
+
this.id = IDManager.generateUniqueID();
|
|
26
|
+
this.parent = null;
|
|
27
|
+
this.frame = frame;
|
|
28
|
+
|
|
29
|
+
// Animation properties
|
|
30
|
+
this.isAnimating = false;
|
|
31
|
+
this.animationFrames = [];
|
|
32
|
+
this.currentAnimationIndex = 0;
|
|
33
|
+
this.animationSpeed = 1000;
|
|
34
|
+
this.lastFrameTime = 0;
|
|
35
|
+
this.playOnce = false;
|
|
36
|
+
this.originalFrame = frame;
|
|
37
|
+
|
|
38
|
+
// Components
|
|
39
|
+
this.components = [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @method setParent
|
|
44
|
+
* @description Sets the parent of the instance
|
|
45
|
+
* @param {Instance} parent - The parent of the instance
|
|
46
|
+
*/
|
|
47
|
+
setParent(parent) {
|
|
48
|
+
this.parent = parent;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @method playAnimation
|
|
53
|
+
* @description Plays an animation with an array of frames
|
|
54
|
+
* @param {Array} frames - The frames to play
|
|
55
|
+
* @param {number} speed - The speed of the animation
|
|
56
|
+
*/
|
|
57
|
+
playAnimation(frames, speed = 1000) {
|
|
58
|
+
if (frames.length === 0) {
|
|
59
|
+
console.error("Animation frames cannot be empty!");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.animationFrames = frames;
|
|
64
|
+
this.animationSpeed = speed;
|
|
65
|
+
this.currentAnimationIndex = 0;
|
|
66
|
+
this.isAnimating = true;
|
|
67
|
+
this.playOnce = false;
|
|
68
|
+
this.lastFrameTime = 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @method playAnimationOnce
|
|
73
|
+
* @description Plays an animation with an array of frames once then stops
|
|
74
|
+
* @param {Array} frames - The frames to play
|
|
75
|
+
* @param {number} speed - The speed of the animation
|
|
76
|
+
*/
|
|
77
|
+
playAnimationOnce(frames, speed = 1000) {
|
|
78
|
+
if (frames.length === 0) {
|
|
79
|
+
console.error("Animation frames cannot be empty!");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.animationFrames = frames;
|
|
84
|
+
this.animationSpeed = speed;
|
|
85
|
+
this.currentAnimationIndex = 0;
|
|
86
|
+
this.isAnimating = true;
|
|
87
|
+
this.playOnce = true;
|
|
88
|
+
this.lastFrameTime = 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @method stopAnimation
|
|
93
|
+
* @description Stops the animation and optionally reverts to the original frame
|
|
94
|
+
* @param {boolean} revertToOriginal - Whether to revert to the original frame
|
|
95
|
+
*/
|
|
96
|
+
stopAnimation(revertToOriginal = false) {
|
|
97
|
+
this.isAnimating = false;
|
|
98
|
+
this.animationFrames = [];
|
|
99
|
+
this.currentAnimationIndex = 0;
|
|
100
|
+
|
|
101
|
+
if (revertToOriginal) {
|
|
102
|
+
this.frame = this.originalFrame;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @method setFrame
|
|
108
|
+
* @description Sets a specific frame
|
|
109
|
+
* @param {number} frame - The frame to set
|
|
110
|
+
*/
|
|
111
|
+
setFrame(frame) {
|
|
112
|
+
this.frame = frame;
|
|
113
|
+
this.isAnimating = false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @method updateAnimation
|
|
118
|
+
* @description Updates the animation
|
|
119
|
+
* @param {number} currentTime - The current time
|
|
120
|
+
*/
|
|
121
|
+
updateAnimation(currentTime) {
|
|
122
|
+
if (!this.isAnimating || this.animationFrames.length === 0) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (currentTime - this.lastFrameTime >= this.animationSpeed) {
|
|
127
|
+
this.frame = this.animationFrames[this.currentAnimationIndex];
|
|
128
|
+
this.currentAnimationIndex++;
|
|
129
|
+
|
|
130
|
+
if (this.currentAnimationIndex >= this.animationFrames.length) {
|
|
131
|
+
if (this.playOnce) {
|
|
132
|
+
this.stopAnimation();
|
|
133
|
+
} else {
|
|
134
|
+
this.currentAnimationIndex = 0; // Loop animation
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this.lastFrameTime = currentTime;
|
|
139
|
+
return true; // Frame changed
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return false; // No frame change
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @method addComponent
|
|
147
|
+
* @description Adds a component to the instance
|
|
148
|
+
* @param {Component} componentInstance - The component to add
|
|
149
|
+
*/
|
|
150
|
+
addComponent(componentInstance) {
|
|
151
|
+
const componentType = componentInstance.constructor;
|
|
152
|
+
if (this.components.some((comp) => comp instanceof componentType)) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Component ${componentType.name} already exists in ${this.name}`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.components.push(componentInstance);
|
|
159
|
+
componentInstance.setParent(this);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @method removeComponent
|
|
164
|
+
* @description Removes a component from the instance
|
|
165
|
+
* @param {Component} component - The component to remove
|
|
166
|
+
*/
|
|
167
|
+
removeComponent(component) {
|
|
168
|
+
if (component instanceof RigidBody) {
|
|
169
|
+
component.destroy();
|
|
170
|
+
}
|
|
171
|
+
this.components = this.components.filter(
|
|
172
|
+
(comp) => comp.id !== component.id
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @method getComponent
|
|
178
|
+
* @description Gets a component from the instance
|
|
179
|
+
* @param {Component} componentType - The type of the component to get
|
|
180
|
+
* @returns {Component} - The component
|
|
181
|
+
*/
|
|
182
|
+
getComponent(componentType) {
|
|
183
|
+
return this.components.find((comp) => comp instanceof componentType);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default Instance;
|