frigame3 3.0.0 → 3.0.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.
Files changed (180) hide show
  1. package/dist/Animation.d.ts +42 -0
  2. package/dist/Animation.js +189 -0
  3. package/dist/BaseSprite.d.ts +116 -0
  4. package/dist/BaseSprite.js +518 -0
  5. package/dist/Gradient.d.ts +31 -0
  6. package/dist/Gradient.js +89 -0
  7. package/dist/Playground.d.ts +48 -0
  8. package/dist/Playground.js +167 -0
  9. package/dist/Rect.d.ts +63 -0
  10. package/dist/Rect.js +155 -0
  11. package/dist/Rectangle.d.ts +31 -0
  12. package/dist/Rectangle.js +69 -0
  13. package/dist/Renderer.d.ts +23 -0
  14. package/dist/Renderer.js +1 -0
  15. package/dist/ResourceManager.d.ts +21 -0
  16. package/dist/ResourceManager.js +100 -0
  17. package/dist/Sprite.d.ts +56 -0
  18. package/dist/Sprite.js +437 -0
  19. package/dist/SpriteGroup.d.ts +39 -0
  20. package/dist/SpriteGroup.js +176 -0
  21. package/dist/canvasRenderer/renderGroup.d.ts +15 -0
  22. package/dist/canvasRenderer/renderGroup.js +134 -0
  23. package/dist/canvasRenderer/renderPlayground.d.ts +9 -0
  24. package/dist/canvasRenderer/renderPlayground.js +67 -0
  25. package/dist/canvasRenderer/renderRectangle.d.ts +15 -0
  26. package/dist/canvasRenderer/renderRectangle.js +287 -0
  27. package/dist/canvasRenderer/renderSprite.d.ts +4 -0
  28. package/dist/canvasRenderer/renderSprite.js +93 -0
  29. package/dist/canvasRenderer.d.ts +2 -0
  30. package/dist/canvasRenderer.js +19 -0
  31. package/dist/dummyRenderer.d.ts +2 -0
  32. package/dist/dummyRenderer.js +41 -0
  33. package/dist/plugins/GamepadTracker.d.ts +15 -0
  34. package/dist/plugins/GamepadTracker.js +74 -0
  35. package/dist/plugins/Tilemap.d.ts +26 -0
  36. package/dist/plugins/Tilemap.js +85 -0
  37. package/dist/plugins/Vec2.d.ts +69 -0
  38. package/dist/plugins/Vec2.js +296 -0
  39. package/dist/plugins/fx/Shaker.d.ts +46 -0
  40. package/dist/plugins/fx/Shaker.js +190 -0
  41. package/dist/plugins/fx/Tweener.d.ts +42 -0
  42. package/dist/plugins/fx/Tweener.js +166 -0
  43. package/dist/plugins/fx/easing.d.ts +32 -0
  44. package/dist/plugins/fx/easing.js +192 -0
  45. package/dist/plugins/isometric/ISOMixin.d.ts +138 -0
  46. package/dist/plugins/isometric/ISOMixin.js +322 -0
  47. package/dist/plugins/isometric/ISORectangle.d.ts +151 -0
  48. package/dist/plugins/isometric/ISORectangle.js +127 -0
  49. package/dist/plugins/isometric/ISOSprite.d.ts +157 -0
  50. package/dist/plugins/isometric/ISOSprite.js +176 -0
  51. package/dist/plugins/isometric/ISOSpriteGroup.d.ts +151 -0
  52. package/dist/plugins/isometric/ISOSpriteGroup.js +116 -0
  53. package/dist/plugins/isometric/ISOTilemap.d.ts +24 -0
  54. package/dist/plugins/isometric/ISOTilemap.js +85 -0
  55. package/dist/plugins/isometric/utils.d.ts +2 -0
  56. package/dist/plugins/isometric/utils.js +10 -0
  57. package/dist/plugins/keyTracker.d.ts +3 -0
  58. package/dist/plugins/keyTracker.js +23 -0
  59. package/dist/plugins/mixer.d.ts +72 -0
  60. package/dist/plugins/mixer.js +396 -0
  61. package/dist/plugins/sorted/SortedAnimation.d.ts +13 -0
  62. package/dist/plugins/sorted/SortedAnimation.js +27 -0
  63. package/dist/plugins/sorted/SortedGroup.d.ts +137 -0
  64. package/dist/plugins/sorted/SortedGroup.js +61 -0
  65. package/dist/plugins/sorted/SortedMixin.d.ts +122 -0
  66. package/dist/plugins/sorted/SortedMixin.js +153 -0
  67. package/dist/plugins/sorted/SortedRectangle.d.ts +127 -0
  68. package/dist/plugins/sorted/SortedRectangle.js +17 -0
  69. package/dist/plugins/sorted/SortedSprite.d.ts +130 -0
  70. package/dist/plugins/sorted/SortedSprite.js +35 -0
  71. package/dist/utils.d.ts +11 -0
  72. package/dist/utils.js +33 -0
  73. package/package.json +6 -2
  74. package/CHANGELOG.md +0 -13
  75. package/biome.json +0 -93
  76. package/demo/package-lock.json +0 -515
  77. package/demo/package.json +0 -19
  78. package/demo/snake/index.html +0 -16
  79. package/demo/snake/index.ts +0 -110
  80. package/demo/tetris/index.html +0 -16
  81. package/demo/tetris/index.ts +0 -536
  82. package/demo/tsconfig.json +0 -53
  83. package/src/Animation.ts +0 -266
  84. package/src/BaseSprite.ts +0 -682
  85. package/src/Gradient.ts +0 -120
  86. package/src/Playground.ts +0 -247
  87. package/src/Rect.ts +0 -237
  88. package/src/Rectangle.ts +0 -108
  89. package/src/Renderer.ts +0 -28
  90. package/src/ResourceManager.ts +0 -145
  91. package/src/Sprite.ts +0 -484
  92. package/src/SpriteGroup.ts +0 -258
  93. package/src/canvasRenderer/renderGroup.ts +0 -194
  94. package/src/canvasRenderer/renderPlayground.ts +0 -103
  95. package/src/canvasRenderer/renderRectangle.ts +0 -421
  96. package/src/canvasRenderer/renderSprite.ts +0 -148
  97. package/src/canvasRenderer.ts +0 -38
  98. package/src/dummyRenderer.ts +0 -62
  99. package/src/plugins/GamepadTracker.ts +0 -97
  100. package/src/plugins/Tilemap.ts +0 -123
  101. package/src/plugins/Vec2.ts +0 -420
  102. package/src/plugins/fx/Shaker.ts +0 -293
  103. package/src/plugins/fx/Tweener.ts +0 -252
  104. package/src/plugins/fx/easing.ts +0 -276
  105. package/src/plugins/isometric/ISOMixin.ts +0 -444
  106. package/src/plugins/isometric/ISORectangle.ts +0 -183
  107. package/src/plugins/isometric/ISOSprite.ts +0 -228
  108. package/src/plugins/isometric/ISOSpriteGroup.ts +0 -155
  109. package/src/plugins/isometric/ISOTilemap.ts +0 -122
  110. package/src/plugins/isometric/utils.ts +0 -19
  111. package/src/plugins/keyTracker.ts +0 -31
  112. package/src/plugins/mixer.ts +0 -523
  113. package/src/plugins/sorted/SortedAnimation.ts +0 -53
  114. package/src/plugins/sorted/SortedGroup.ts +0 -94
  115. package/src/plugins/sorted/SortedMixin.ts +0 -203
  116. package/src/plugins/sorted/SortedRectangle.ts +0 -35
  117. package/src/plugins/sorted/SortedSprite.ts +0 -56
  118. package/src/utils.ts +0 -53
  119. package/test/animation/index.html +0 -20
  120. package/test/animation/index.ts +0 -253
  121. package/test/animation/mh.png +0 -0
  122. package/test/animation/moh.png +0 -0
  123. package/test/animation/mov.png +0 -0
  124. package/test/animation/mv.png +0 -0
  125. package/test/animation/rebound.png +0 -0
  126. package/test/animation/reboundm.png +0 -0
  127. package/test/animation/sh.png +0 -0
  128. package/test/animation/soh.png +0 -0
  129. package/test/animation/sov.png +0 -0
  130. package/test/animation/sv.png +0 -0
  131. package/test/isometric1/beach.png +0 -0
  132. package/test/isometric1/foglie.png +0 -0
  133. package/test/isometric1/grass.png +0 -0
  134. package/test/isometric1/index.html +0 -17
  135. package/test/isometric1/index.ts +0 -68
  136. package/test/isometric1/tronco.png +0 -0
  137. package/test/isometric1/untitled.tmx +0 -25
  138. package/test/isometric1/water.png +0 -0
  139. package/test/isometric2/banner.png +0 -0
  140. package/test/isometric2/books.png +0 -0
  141. package/test/isometric2/candlestick.png +0 -0
  142. package/test/isometric2/ice.png +0 -0
  143. package/test/isometric2/index.html +0 -16
  144. package/test/isometric2/index.ts +0 -129
  145. package/test/isometric2/knight_se.png +0 -0
  146. package/test/isometric2/tile.png +0 -0
  147. package/test/isometric2/untitled.tmx +0 -36
  148. package/test/isometric2/wall.png +0 -0
  149. package/test/layers/boy.png +0 -0
  150. package/test/layers/catgirl.png +0 -0
  151. package/test/layers/fri1.svg +0 -8
  152. package/test/layers/grassblock.png +0 -0
  153. package/test/layers/horngirl.png +0 -0
  154. package/test/layers/index.html +0 -17
  155. package/test/layers/index.ts +0 -191
  156. package/test/layers/pinkgirl.png +0 -0
  157. package/test/layers/render_ruler.py +0 -57
  158. package/test/layers/ruler.png +0 -0
  159. package/test/layers/sh.png +0 -0
  160. package/test/mixer/dieci.opus +0 -0
  161. package/test/mixer/dieci.wav +0 -0
  162. package/test/mixer/index.html +0 -33
  163. package/test/mixer/index.ts +0 -206
  164. package/test/mixer/news_intro.mp3 +0 -0
  165. package/test/mixer/news_intro.ogg +0 -0
  166. package/test/mixer/prova.mp3 +0 -0
  167. package/test/mixer/prova.ogg +0 -0
  168. package/test/package-lock.json +0 -515
  169. package/test/package.json +0 -19
  170. package/test/sorted/Brown Block.png +0 -0
  171. package/test/sorted/index.html +0 -16
  172. package/test/sorted/index.ts +0 -38
  173. package/test/transformation1/index.html +0 -17
  174. package/test/transformation1/index.ts +0 -51
  175. package/test/transformation1/sh.png +0 -0
  176. package/test/transformation2/index.html +0 -20
  177. package/test/transformation2/index.ts +0 -71
  178. package/test/transformation2/sh.png +0 -0
  179. package/test/tsconfig.json +0 -53
  180. package/tsconfig.json +0 -51
@@ -1,293 +0,0 @@
1
- import type { Playground } from "../../Playground.js";
2
- import { lerp } from "../../utils.js";
3
- import { linear } from "./easing.js";
4
-
5
- // Inspired by https://jonny.morrill.me/en/blog/gamedev-how-to-implement-a-camera-shake-effect/
6
-
7
- export interface ShakeOptions {
8
- duration: number;
9
- frequency: number;
10
- decay: (t: number) => number;
11
- callback: () => void;
12
- suppressWarning: boolean;
13
- }
14
-
15
- interface ShakeProp {
16
- amplitude: number;
17
- start_value: number;
18
- current_value: number;
19
- sample_value: number;
20
- }
21
-
22
- interface ShakeObj<T extends object> {
23
- target_obj: T;
24
- current_sample: number;
25
- num_sample: number;
26
- current_step: number;
27
- steps_per_sample: number;
28
- decay: (t: number) => number;
29
- callback?: () => void;
30
- property_list: Map<keyof T, ShakeProp>;
31
- }
32
-
33
- export class Shaker extends EventTarget {
34
- _nextId = 1; // Start from 1 to guarantee that shakeId is always truthy
35
- _shake_queue: Map<number, ShakeObj<Record<string, number>>> = new Map<
36
- number,
37
- ShakeObj<Record<string, number>>
38
- >();
39
- _shaking = false;
40
- _playground: WeakRef<Playground>;
41
- _callbackId: number | null = null;
42
-
43
- constructor(playground: Playground) {
44
- super();
45
-
46
- this._playground = new WeakRef(playground);
47
-
48
- this.registerCallback();
49
-
50
- playground.addEventListener("clearCallbacks", this._onClearCallbacks);
51
- }
52
-
53
- _shakeStep = (): void => {
54
- if (this._shaking) {
55
- // Process all the shakes in the queue
56
- for (const [shakeId, shake_obj] of this._shake_queue) {
57
- const target_obj = shake_obj.target_obj;
58
-
59
- shake_obj.current_step += 1;
60
-
61
- if (shake_obj.current_step >= shake_obj.steps_per_sample) {
62
- shake_obj.current_step = 0;
63
- shake_obj.current_sample += 1;
64
-
65
- if (shake_obj.current_sample >= shake_obj.num_sample) {
66
- // This object has finished its shaking
67
-
68
- // Restore every property to its initial value
69
- for (const [property, shake_prop] of shake_obj.property_list) {
70
- target_obj[property] = shake_prop.start_value;
71
- }
72
-
73
- // Call the complete callback
74
- const callback = shake_obj.callback;
75
- callback?.();
76
-
77
- // Remove this shake
78
- this._shake_queue.delete(shakeId);
79
- } else {
80
- for (const [property, shake_prop] of shake_obj.property_list) {
81
- // Set the properties to the current value
82
- target_obj[property] = shake_prop.sample_value;
83
-
84
- // Update the property list with a new sample
85
- shake_prop.current_value = shake_prop.sample_value;
86
- shake_prop.sample_value =
87
- shake_prop.start_value +
88
- lerp(
89
- (Math.random() * 2 - 1) * shake_prop.amplitude,
90
- 0,
91
- shake_obj.decay(
92
- shake_obj.current_sample / shake_obj.num_sample,
93
- ),
94
- );
95
- }
96
- }
97
- } else {
98
- // Set the properties to the current value
99
- for (const [property, shake_prop] of shake_obj.property_list) {
100
- target_obj[property] = lerp(
101
- shake_prop.current_value,
102
- shake_prop.sample_value,
103
- shake_obj.current_step / shake_obj.steps_per_sample,
104
- );
105
- }
106
- }
107
- }
108
-
109
- // If there are no more shakes in the queue, this callback can be stopped
110
- if (this._shake_queue.size === 0) {
111
- this._shaking = false;
112
- }
113
- }
114
- };
115
-
116
- registerCallback(options?: { suppressWarning?: boolean }): this {
117
- if (this._callbackId === null) {
118
- const playground = this._playground.deref();
119
-
120
- if (playground !== undefined) {
121
- this._callbackId = playground.registerCallback(this._shakeStep);
122
- } else {
123
- if (
124
- typeof console !== "undefined" &&
125
- options?.suppressWarning === false
126
- ) {
127
- console.warn("playground has been garbage collected");
128
- console.trace();
129
- }
130
- }
131
- } else {
132
- if (
133
- typeof console !== "undefined" &&
134
- options?.suppressWarning === false
135
- ) {
136
- console.warn("Callback already registered");
137
- console.trace();
138
- }
139
- }
140
-
141
- return this;
142
- }
143
-
144
- removeCallback(options?: { suppressWarning?: boolean }): this {
145
- const playground = this._playground.deref();
146
-
147
- if (playground !== undefined) {
148
- playground.removeCallback(this._callbackId, options);
149
- } else {
150
- if (
151
- typeof console !== "undefined" &&
152
- options?.suppressWarning === false
153
- ) {
154
- console.warn("playground has been garbage collected");
155
- console.trace();
156
- }
157
- }
158
-
159
- this._callbackId = null;
160
-
161
- return this;
162
- }
163
-
164
- _onClearCallbacks = (): void => {
165
- if (this._callbackId !== null) {
166
- this._callbackId = null;
167
- this.registerCallback();
168
- }
169
- };
170
-
171
- shake<T extends object>(
172
- target_obj: T,
173
- properties: Partial<Record<keyof T, number>>,
174
- options?: Partial<ShakeOptions>,
175
- ): number {
176
- const playground = this._playground.deref();
177
-
178
- if (playground !== undefined) {
179
- const duration = options?.duration || 1;
180
- const frequency = options?.frequency || 60;
181
- const decay = options?.decay ?? linear;
182
-
183
- const steps_per_sample = playground.framesFromMs(1000 / frequency);
184
- const num_sample = Math.ceil(
185
- playground.framesFromMs(duration) / steps_per_sample,
186
- );
187
-
188
- const shake_obj: ShakeObj<T> = {
189
- target_obj: target_obj,
190
- current_sample: 0,
191
- num_sample: num_sample,
192
- current_step: 0,
193
- steps_per_sample: steps_per_sample,
194
- decay: decay,
195
- property_list: new Map<keyof T, ShakeProp>(),
196
- };
197
-
198
- if (options?.callback !== undefined) {
199
- shake_obj.callback = options.callback;
200
- }
201
-
202
- const property_list = shake_obj.property_list;
203
-
204
- for (const [property, value] of Object.entries(properties)) {
205
- const start_value = target_obj[property as keyof T] as number;
206
- const amplitude = value as number;
207
-
208
- property_list.set(property as keyof T, {
209
- amplitude: amplitude,
210
- start_value: start_value,
211
- current_value: start_value,
212
- sample_value: start_value + (Math.random() * 2 - 1) * amplitude,
213
- });
214
- }
215
-
216
- const shakeId = this._nextId;
217
- this._nextId += 1;
218
-
219
- this._shake_queue.set(
220
- shakeId,
221
- shake_obj as unknown as ShakeObj<Record<string, number>>,
222
- );
223
- this._shaking = true;
224
-
225
- return shakeId;
226
- } else {
227
- if (
228
- typeof console !== "undefined" &&
229
- options?.suppressWarning === false
230
- ) {
231
- console.warn("playground has been garbage collected");
232
- console.trace();
233
- }
234
-
235
- return -1;
236
- }
237
- }
238
-
239
- removeShake(
240
- shakeId: number | null,
241
- options?: { suppressWarning?: boolean },
242
- ): this {
243
- if (shakeId === null) {
244
- if (
245
- typeof console !== "undefined" &&
246
- options?.suppressWarning === false
247
- ) {
248
- console.warn("shakeId is null");
249
- console.trace();
250
- }
251
- return this;
252
- }
253
-
254
- const shake_obj = this._shake_queue.get(shakeId);
255
- if (shake_obj !== undefined) {
256
- const target_obj = shake_obj.target_obj;
257
-
258
- // Restore every property to its initial value
259
- for (const [property, shake_prop] of shake_obj.property_list) {
260
- target_obj[property] = shake_prop.start_value;
261
- }
262
-
263
- this._shake_queue.delete(shakeId);
264
- } else {
265
- if (
266
- typeof console !== "undefined" &&
267
- options?.suppressWarning === false
268
- ) {
269
- console.warn("No shakes removed");
270
- console.trace();
271
- }
272
- }
273
-
274
- return this;
275
- }
276
-
277
- clearShakes(): this {
278
- for (const shake_obj of this._shake_queue.values()) {
279
- const target_obj = shake_obj.target_obj;
280
-
281
- // Restore every property to its initial value
282
- for (const [property, shake_prop] of shake_obj.property_list) {
283
- target_obj[property] = shake_prop.start_value;
284
- }
285
- }
286
-
287
- this._shake_queue.clear();
288
-
289
- this.dispatchEvent(new Event("clearShakes"));
290
-
291
- return this;
292
- }
293
- }
@@ -1,252 +0,0 @@
1
- import type { Playground } from "../../Playground.js";
2
- import { lerp } from "../../utils.js";
3
- import { swing } from "./easing.js";
4
-
5
- export type Speed = "slow" | "fast";
6
-
7
- export interface TweenOptions {
8
- duration: Speed | number;
9
- easing: (t: number) => number;
10
- callback: () => void;
11
- suppressWarning: boolean;
12
- }
13
-
14
- interface TweenProp {
15
- start_value: number;
16
- target_value: number;
17
- }
18
-
19
- interface TweenObj<T extends object> {
20
- target_obj: T;
21
- current_step: number;
22
- num_step: number;
23
- easing: (t: number) => number;
24
- callback?: () => void;
25
- property_list: Map<keyof T, TweenProp>;
26
- }
27
-
28
- const speeds = {
29
- slow: 600,
30
- fast: 200,
31
- _default: 400,
32
- };
33
-
34
- export class Tweener extends EventTarget {
35
- _nextId = 1; // Start from 1 to guarantee that tweenId is always truthy
36
- _tween_queue: Map<number, TweenObj<Record<string, number>>> = new Map<
37
- number,
38
- TweenObj<Record<string, number>>
39
- >();
40
- _tweening = false;
41
- _playground: WeakRef<Playground>;
42
- _callbackId: number | null = null;
43
-
44
- constructor(playground: Playground) {
45
- super();
46
-
47
- this._playground = new WeakRef(playground);
48
-
49
- this.registerCallback();
50
-
51
- playground.addEventListener("clearCallbacks", this._onClearCallbacks);
52
- }
53
-
54
- _tweenStep = (): void => {
55
- if (this._tweening) {
56
- // Process all the tweens in the queue
57
- for (const [tweenId, tween_obj] of this._tween_queue) {
58
- const target_obj = tween_obj.target_obj;
59
-
60
- tween_obj.current_step += 1;
61
-
62
- if (tween_obj.current_step >= tween_obj.num_step) {
63
- // This object has finished its tweening
64
-
65
- // Set every property to its target value
66
- for (const [property, tween_prop] of tween_obj.property_list) {
67
- target_obj[property] = tween_prop.target_value;
68
- }
69
-
70
- // Call the complete callback
71
- const callback = tween_obj.callback;
72
- callback?.();
73
-
74
- // Remove this tween
75
- this._tween_queue.delete(tweenId);
76
- } else {
77
- // Set the properties to the current value
78
- for (const [property, tween_prop] of tween_obj.property_list) {
79
- target_obj[property] = lerp(
80
- tween_prop.start_value,
81
- tween_prop.target_value,
82
- tween_obj.easing(tween_obj.current_step / tween_obj.num_step),
83
- );
84
- }
85
- }
86
- }
87
-
88
- // If there are no more tweens in the queue, this callback can be stopped
89
- if (this._tween_queue.size === 0) {
90
- this._tweening = false;
91
- }
92
- }
93
- };
94
-
95
- registerCallback(options?: { suppressWarning?: boolean }): this {
96
- if (this._callbackId === null) {
97
- const playground = this._playground.deref();
98
-
99
- if (playground !== undefined) {
100
- this._callbackId = playground.registerCallback(this._tweenStep);
101
- } else {
102
- if (
103
- typeof console !== "undefined" &&
104
- options?.suppressWarning === false
105
- ) {
106
- console.warn("playground has been garbage collected");
107
- console.trace();
108
- }
109
- }
110
- } else {
111
- if (
112
- typeof console !== "undefined" &&
113
- options?.suppressWarning === false
114
- ) {
115
- console.warn("Callback already registered");
116
- console.trace();
117
- }
118
- }
119
-
120
- return this;
121
- }
122
-
123
- removeCallback(options?: { suppressWarning?: boolean }): this {
124
- const playground = this._playground.deref();
125
-
126
- if (playground !== undefined) {
127
- playground.removeCallback(this._callbackId, options);
128
- } else {
129
- if (
130
- typeof console !== "undefined" &&
131
- options?.suppressWarning === false
132
- ) {
133
- console.warn("playground has been garbage collected");
134
- console.trace();
135
- }
136
- }
137
-
138
- this._callbackId = null;
139
-
140
- return this;
141
- }
142
-
143
- _onClearCallbacks = (): void => {
144
- if (this._callbackId !== null) {
145
- this._callbackId = null;
146
- this.registerCallback();
147
- }
148
- };
149
-
150
- tween<T extends object>(
151
- target_obj: T,
152
- properties: Partial<Record<keyof T, number>>,
153
- options?: Partial<TweenOptions>,
154
- ): number {
155
- const playground = this._playground.deref();
156
-
157
- if (playground !== undefined) {
158
- const duration = ((): number => {
159
- const duration = options?.duration;
160
-
161
- if (typeof duration === "string") {
162
- return speeds[duration];
163
- } else if (duration === 0) {
164
- return 0;
165
- } else {
166
- return duration || speeds._default;
167
- }
168
- })();
169
-
170
- const easing = options?.easing ?? swing;
171
-
172
- const tween_obj: TweenObj<T> = {
173
- target_obj: target_obj,
174
- current_step: 0,
175
- num_step: playground.framesFromMs(duration),
176
- easing: easing,
177
- property_list: new Map<keyof T, TweenProp>(),
178
- };
179
-
180
- if (options?.callback !== undefined) {
181
- tween_obj.callback = options.callback;
182
- }
183
-
184
- const property_list = tween_obj.property_list;
185
-
186
- for (const [property, value] of Object.entries(properties)) {
187
- property_list.set(property as keyof T, {
188
- start_value: target_obj[property as keyof T] as number,
189
- target_value: value as number,
190
- });
191
- }
192
-
193
- const tweenId = this._nextId;
194
- this._nextId += 1;
195
-
196
- this._tween_queue.set(
197
- tweenId,
198
- tween_obj as unknown as TweenObj<Record<string, number>>,
199
- );
200
- this._tweening = true;
201
-
202
- return tweenId;
203
- } else {
204
- if (
205
- typeof console !== "undefined" &&
206
- options?.suppressWarning === false
207
- ) {
208
- console.warn("playground has been garbage collected");
209
- console.trace();
210
- }
211
-
212
- return -1;
213
- }
214
- }
215
-
216
- removeTween(
217
- tweenId: number | null,
218
- options?: { suppressWarning?: boolean },
219
- ): this {
220
- if (tweenId === null) {
221
- if (
222
- typeof console !== "undefined" &&
223
- options?.suppressWarning === false
224
- ) {
225
- console.warn("tweenId is null");
226
- console.trace();
227
- }
228
- return this;
229
- }
230
-
231
- const deleted = this._tween_queue.delete(tweenId);
232
-
233
- if (
234
- !deleted &&
235
- typeof console !== "undefined" &&
236
- options?.suppressWarning === false
237
- ) {
238
- console.warn("No tweens removed");
239
- console.trace();
240
- }
241
-
242
- return this;
243
- }
244
-
245
- clearTweens(): this {
246
- this._tween_queue.clear();
247
-
248
- this.dispatchEvent(new Event("clearTweens"));
249
-
250
- return this;
251
- }
252
- }