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,32 @@
|
|
|
1
|
+
import Emerald from "./imports/Emerald";
|
|
2
|
+
import BitmapText from "./imports/BitmapText";
|
|
3
|
+
import Color from "./imports/Color";
|
|
4
|
+
import Drawable from "./imports/Drawable";
|
|
5
|
+
import FPSCounter from "./imports/FPSCounter";
|
|
6
|
+
import Instance from "./imports/Instance";
|
|
7
|
+
import InstancedTexture from "./imports/InstancedTexture";
|
|
8
|
+
import { Physics, Vector2, Vector3 } from "./imports/Physics";
|
|
9
|
+
import Scene from "./imports/Scene";
|
|
10
|
+
import { Square2D, Triangle2D, Circle2D } from "./imports/Shapes";
|
|
11
|
+
import Storage from "./imports/Storage";
|
|
12
|
+
import Texture from "./imports/Texture";
|
|
13
|
+
import Time from "./imports/Time";
|
|
14
|
+
import Transform from "./imports/Transform";
|
|
15
|
+
import Particle from "./imports/particlesystem/Particle";
|
|
16
|
+
import Particles from "./imports/particlesystem/Particles";
|
|
17
|
+
import ParticleSettings from "./imports/particlesystem/ParticleSettings";
|
|
18
|
+
import AudioManager from "./imports/managers/AudioManager";
|
|
19
|
+
import CameraManager from "./imports/managers/CameraManager";
|
|
20
|
+
import EventManager from "./imports/managers/EventManager";
|
|
21
|
+
import SceneManager from "./imports/managers/SceneManager";
|
|
22
|
+
import DirectionalLight from "./imports/lights/DirectionalLight";
|
|
23
|
+
import PointLight from "./imports/lights/PointLight";
|
|
24
|
+
import BoxCollider from "./imports/components/BoxCollider";
|
|
25
|
+
import BoxColliderDebug from "./imports/components/BoxColliderDebug";
|
|
26
|
+
import CircleCollider from "./imports/components/CircleCollider";
|
|
27
|
+
import CircleColliderDebug from "./imports/components/CircleColliderDebug";
|
|
28
|
+
import Collider from "./imports/components/Collider";
|
|
29
|
+
import GameObject from "./imports/components/GameObject";
|
|
30
|
+
import RigidBody from "./imports/components/RigidBody";
|
|
31
|
+
export { Emerald, BitmapText, Color, Drawable, FPSCounter, Instance, InstancedTexture, Physics, Vector2, Vector3, Scene, Square2D, Triangle2D, Circle2D, Storage, Texture, Time, Transform, Particle, Particles, ParticleSettings, AudioManager, CameraManager, EventManager, SceneManager, DirectionalLight, PointLight, BoxCollider, BoxColliderDebug, CircleCollider, CircleColliderDebug, Collider, GameObject, RigidBody, };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import GameObject from "./components/GameObject.js";
|
|
2
|
+
import Instance from "./Instance.js";
|
|
3
|
+
import InstancedTexture from "./InstancedTexture.js";
|
|
4
|
+
import { Vector2, Vector3 } from "./Physics.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* BitmapText class for rendering text using a bitmap font texture
|
|
8
|
+
* @param {string} text - The text to display
|
|
9
|
+
* @param {string} texturePath - Path to the bitmap font texture
|
|
10
|
+
* @param {string} letters - String containing all available characters in the font
|
|
11
|
+
* @param {number} letterSpacing - Spacing between letters
|
|
12
|
+
* @param {number} frameWidth - Width of each character frame
|
|
13
|
+
* @param {number} frameHeight - Height of each character frame
|
|
14
|
+
* @param {number} framesPerRow - Number of character frames per row in the texture
|
|
15
|
+
* @param {number} totalFrames - Total number of character frames
|
|
16
|
+
* @param {boolean} pixelArt - Whether to use pixel-perfect rendering
|
|
17
|
+
* @param {number} fontSize - Size of the rendered text
|
|
18
|
+
* @param {Color} color - Color tint for the text
|
|
19
|
+
* @param {Vector3} position - Position of the text
|
|
20
|
+
* @param {number} rotation - Rotation of the text
|
|
21
|
+
* @param {boolean} useLighting - Whether the text should react to lighting (default: false)
|
|
22
|
+
*/
|
|
23
|
+
class BitmapText {
|
|
24
|
+
constructor(
|
|
25
|
+
text,
|
|
26
|
+
texturePath,
|
|
27
|
+
letters,
|
|
28
|
+
letterSpacing,
|
|
29
|
+
frameWidth,
|
|
30
|
+
frameHeight,
|
|
31
|
+
framesPerRow,
|
|
32
|
+
totalFrames,
|
|
33
|
+
pixelArt,
|
|
34
|
+
fontSize,
|
|
35
|
+
color,
|
|
36
|
+
position,
|
|
37
|
+
rotation,
|
|
38
|
+
useLighting = false // Default to false for text as it's typically UI
|
|
39
|
+
) {
|
|
40
|
+
this.text = text;
|
|
41
|
+
this.texturePath = texturePath;
|
|
42
|
+
this.fontSize = fontSize;
|
|
43
|
+
this.color = color;
|
|
44
|
+
this.position = position;
|
|
45
|
+
this.rotation = rotation;
|
|
46
|
+
this.letters = letters;
|
|
47
|
+
this.letterSpacing = letterSpacing;
|
|
48
|
+
this.frameWidth = frameWidth;
|
|
49
|
+
this.frameHeight = frameHeight;
|
|
50
|
+
this.framesPerRow = framesPerRow;
|
|
51
|
+
this.totalFrames = totalFrames;
|
|
52
|
+
this.pixelArt = pixelArt;
|
|
53
|
+
this.useLighting = useLighting;
|
|
54
|
+
this.gameObject = new GameObject(
|
|
55
|
+
text,
|
|
56
|
+
position,
|
|
57
|
+
rotation,
|
|
58
|
+
new Vector2(fontSize * text.length, fontSize)
|
|
59
|
+
);
|
|
60
|
+
this.letterDictionary = {};
|
|
61
|
+
for (let i = 0; i < letters.length; i++) {
|
|
62
|
+
this.letterDictionary[letters[i]] = i;
|
|
63
|
+
}
|
|
64
|
+
// Initialize the bitmap font texture
|
|
65
|
+
this.texture = new InstancedTexture(
|
|
66
|
+
this.texturePath,
|
|
67
|
+
text.length,
|
|
68
|
+
this.frameWidth,
|
|
69
|
+
this.frameHeight,
|
|
70
|
+
this.framesPerRow,
|
|
71
|
+
this.totalFrames,
|
|
72
|
+
0,
|
|
73
|
+
false,
|
|
74
|
+
this.pixelArt,
|
|
75
|
+
this.useLighting
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Apply the color to the texture if provided
|
|
79
|
+
if (this.color) {
|
|
80
|
+
this.texture.setColor(this.color);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Apply the lighting setting to the texture
|
|
84
|
+
this.texture.setUseLighting(this.useLighting);
|
|
85
|
+
|
|
86
|
+
this.gameObject.addComponent(this.texture);
|
|
87
|
+
for (let i = 0; i < text.length; i++) {
|
|
88
|
+
const letter = text[i];
|
|
89
|
+
const frameIndex = this.letterDictionary[letter];
|
|
90
|
+
if (frameIndex !== undefined) {
|
|
91
|
+
const instance = new Instance(
|
|
92
|
+
letter,
|
|
93
|
+
new Vector3(
|
|
94
|
+
this.position.x + i * (this.frameWidth + this.letterSpacing),
|
|
95
|
+
this.position.y,
|
|
96
|
+
this.position.z
|
|
97
|
+
),
|
|
98
|
+
new Vector2(this.fontSize, this.fontSize),
|
|
99
|
+
0,
|
|
100
|
+
frameIndex
|
|
101
|
+
);
|
|
102
|
+
this.texture.addInstance(instance);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @method setColor
|
|
109
|
+
* @description Updates the color of the bitmap text
|
|
110
|
+
* @param {Color} color - The color to set
|
|
111
|
+
*/
|
|
112
|
+
setColor(color) {
|
|
113
|
+
this.color = color;
|
|
114
|
+
if (this.texture) {
|
|
115
|
+
this.texture.setColor(color);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @method setUseLighting
|
|
121
|
+
* @description Controls whether the text reacts to lighting
|
|
122
|
+
* @param {boolean} useLighting - Whether the text should react to lighting
|
|
123
|
+
*/
|
|
124
|
+
setUseLighting(useLighting) {
|
|
125
|
+
this.useLighting = useLighting;
|
|
126
|
+
if (this.texture) {
|
|
127
|
+
this.texture.setUseLighting(useLighting);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @method setText
|
|
133
|
+
* @description Updates the text of the bitmap text
|
|
134
|
+
* @param {string} text - The text to set
|
|
135
|
+
*/
|
|
136
|
+
setText(text) {
|
|
137
|
+
this.text = text;
|
|
138
|
+
this.texture.clearInstances();
|
|
139
|
+
this.texture.updateInstanceCount(this.text.length);
|
|
140
|
+
for (let i = 0; i < text.length; i++) {
|
|
141
|
+
const letter = text[i];
|
|
142
|
+
const frameIndex = this.letterDictionary[letter];
|
|
143
|
+
if (frameIndex !== undefined) {
|
|
144
|
+
const instance = new Instance(
|
|
145
|
+
letter,
|
|
146
|
+
new Vector3(
|
|
147
|
+
this.position.x + i * (this.frameWidth + this.letterSpacing),
|
|
148
|
+
this.position.y,
|
|
149
|
+
this.position.z
|
|
150
|
+
),
|
|
151
|
+
new Vector2(this.fontSize, this.fontSize),
|
|
152
|
+
0,
|
|
153
|
+
frameIndex
|
|
154
|
+
);
|
|
155
|
+
this.texture.addInstance(instance);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @method setPosition
|
|
162
|
+
* @description Updates the position of the bitmap text
|
|
163
|
+
* @param {Vector3} position - The position to set
|
|
164
|
+
*/
|
|
165
|
+
setPosition(position) {
|
|
166
|
+
// Vector3
|
|
167
|
+
this.position = position;
|
|
168
|
+
this.gameObject.transform.position = position;
|
|
169
|
+
|
|
170
|
+
let instanceIndex = 0;
|
|
171
|
+
for (let textIndex = 0; textIndex < this.text.length; textIndex++) {
|
|
172
|
+
const letter = this.text[textIndex];
|
|
173
|
+
const frameIndex = this.letterDictionary[letter];
|
|
174
|
+
|
|
175
|
+
if (
|
|
176
|
+
frameIndex !== undefined &&
|
|
177
|
+
instanceIndex < this.texture.instances.length
|
|
178
|
+
) {
|
|
179
|
+
const instance = this.texture.instances[instanceIndex];
|
|
180
|
+
instance.transform.position.x =
|
|
181
|
+
position.x + textIndex * (this.frameWidth + this.letterSpacing);
|
|
182
|
+
instance.transform.position.y = position.y;
|
|
183
|
+
instance.transform.position.z = position.z;
|
|
184
|
+
instanceIndex++;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @method setFontSize
|
|
191
|
+
* @description Updates the font size of the bitmap text
|
|
192
|
+
* @param {number} fontSize - The font size to set
|
|
193
|
+
*/
|
|
194
|
+
setFontSize(fontSize) {
|
|
195
|
+
this.fontSize = fontSize;
|
|
196
|
+
this.gameObject.transform.scale = new Vector2(
|
|
197
|
+
fontSize * this.text.length,
|
|
198
|
+
fontSize
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
let instanceIndex = 0;
|
|
202
|
+
for (let textIndex = 0; textIndex < this.text.length; textIndex++) {
|
|
203
|
+
const letter = this.text[textIndex];
|
|
204
|
+
const frameIndex = this.letterDictionary[letter];
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
frameIndex !== undefined &&
|
|
208
|
+
instanceIndex < this.texture.instances.length
|
|
209
|
+
) {
|
|
210
|
+
const instance = this.texture.instances[instanceIndex];
|
|
211
|
+
instance.transform.scale = new Vector2(fontSize, fontSize);
|
|
212
|
+
instanceIndex++;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @method setLetterSpacing
|
|
219
|
+
* @description Updates the letter spacing of the bitmap text
|
|
220
|
+
* @param {number} letterSpacing - The letter spacing to set
|
|
221
|
+
*/
|
|
222
|
+
setLetterSpacing(letterSpacing) {
|
|
223
|
+
this.letterSpacing = letterSpacing;
|
|
224
|
+
|
|
225
|
+
let instanceIndex = 0;
|
|
226
|
+
for (let textIndex = 0; textIndex < this.text.length; textIndex++) {
|
|
227
|
+
const letter = this.text[textIndex];
|
|
228
|
+
const frameIndex = this.letterDictionary[letter];
|
|
229
|
+
|
|
230
|
+
if (
|
|
231
|
+
frameIndex !== undefined &&
|
|
232
|
+
instanceIndex < this.texture.instances.length
|
|
233
|
+
) {
|
|
234
|
+
const instance = this.texture.instances[instanceIndex];
|
|
235
|
+
instance.transform.position.x =
|
|
236
|
+
this.position.x + textIndex * (this.frameWidth + letterSpacing);
|
|
237
|
+
instance.transform.position.y = this.position.y;
|
|
238
|
+
instance.transform.position.z = this.position.z;
|
|
239
|
+
instanceIndex++;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export default BitmapText;
|
package/imports/Color.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Color
|
|
3
|
+
* @description Represents a color
|
|
4
|
+
* @param {number} r - The red value
|
|
5
|
+
* @param {number} g - The green value
|
|
6
|
+
* @param {number} b - The blue value
|
|
7
|
+
* @param {number} a - The alpha value
|
|
8
|
+
*/
|
|
9
|
+
class Color {
|
|
10
|
+
constructor(r, g, b, a = 255) {
|
|
11
|
+
this.r = r;
|
|
12
|
+
this.g = g;
|
|
13
|
+
this.b = b;
|
|
14
|
+
this.a = a;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Color;
|