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
package/src/BaseSprite.ts DELETED
@@ -1,682 +0,0 @@
1
- import type { Playground } from "./Playground.js";
2
- import type {
3
- RectOptions,
4
- RectPos,
5
- RectSize,
6
- RectSizeX,
7
- RectSizeY,
8
- } from "./Rect.js";
9
- import { Rect } from "./Rect.js";
10
- import type { SpriteGroup } from "./SpriteGroup.js";
11
- import { clamp, lerp, pick } from "./utils.js";
12
-
13
- // source-over, lighter, multiply, screen
14
- export type BlendMode = "normal" | "add" | "multiply" | "screen";
15
-
16
- export interface TransformOptions {
17
- transformOrigin: number;
18
- transformOriginx: keyof RectSizeX | number;
19
- transformOriginy: keyof RectSizeY | number;
20
-
21
- angle: number;
22
-
23
- scale: number;
24
- scalex: number;
25
- scaley: number;
26
-
27
- flip: boolean;
28
- fliph: boolean;
29
- flipv: boolean;
30
-
31
- opacity: number;
32
- hidden: boolean;
33
-
34
- blendMode: BlendMode;
35
- }
36
-
37
- export interface BaseSpriteOptions extends RectOptions, TransformOptions {}
38
-
39
- export class BaseSprite extends Rect implements BaseSpriteOptions {
40
- _playground?: WeakRef<Playground>;
41
- _parent?: WeakRef<SpriteGroup>;
42
-
43
- _transformOriginx: keyof RectSizeX | number = "halfWidth";
44
- _transformOriginy: keyof RectSizeY | number = "halfHeight";
45
-
46
- _angle = 0;
47
-
48
- _scalex = 1;
49
- _scaley = 1;
50
- _fliph = 1;
51
- _flipv = 1;
52
-
53
- _opacity = 1;
54
- _hidden = false;
55
-
56
- _scaleh = 1;
57
- _scalev = 1;
58
-
59
- _blendMode: BlendMode = "normal";
60
-
61
- // Implementation details
62
-
63
- _needsUpdate = false;
64
- _prevLeft = 0;
65
- _prevTop = 0;
66
- _frameCounterLastMove = 0;
67
- _drawLeft = 0;
68
- _drawTop = 0;
69
- _drawWidth = 0;
70
- _drawHeight = 0;
71
-
72
- get playground(): Playground | undefined {
73
- return this._playground?.deref();
74
- }
75
-
76
- get parent(): SpriteGroup | undefined {
77
- return this._parent?.deref();
78
- }
79
-
80
- get transformOrigin(): number {
81
- const origin = this._transformOriginx;
82
-
83
- if (typeof origin === "string") {
84
- return this[origin];
85
- } else {
86
- return origin;
87
- }
88
- }
89
-
90
- set transformOrigin(value: number) {
91
- this._transformOriginx = value;
92
- this._transformOriginy = value;
93
- }
94
-
95
- get transformOriginx(): keyof RectSizeX | number {
96
- return this._transformOriginx;
97
- }
98
-
99
- set transformOriginx(value: keyof RectSizeX | number) {
100
- this._transformOriginx = value;
101
- }
102
-
103
- get transformOriginy(): keyof RectSizeY | number {
104
- return this._transformOriginy;
105
- }
106
-
107
- set transformOriginy(value: keyof RectSizeY | number) {
108
- this._transformOriginy = value;
109
- }
110
-
111
- get angle(): number {
112
- return this._angle;
113
- }
114
-
115
- set angle(value: number) {
116
- this._angle = value;
117
- }
118
-
119
- get scalex(): number {
120
- return this._scalex;
121
- }
122
-
123
- set scalex(value: number) {
124
- this._scalex = value;
125
- this._scaleh = value * this._fliph;
126
- }
127
-
128
- get scaley(): number {
129
- return this._scaley;
130
- }
131
-
132
- set scaley(value: number) {
133
- this._scaley = value;
134
- this._scalev = value * this._flipv;
135
- }
136
-
137
- get scale(): number {
138
- return this._scalex;
139
- }
140
-
141
- set scale(value: number) {
142
- this._scalex = value;
143
- this._scaley = value;
144
-
145
- this._scaleh = value * this._fliph;
146
- this._scalev = value * this._flipv;
147
- }
148
-
149
- get fliph(): boolean {
150
- return this._fliph < 0;
151
- }
152
-
153
- set fliph(value: boolean) {
154
- if (value) {
155
- this._fliph = -1;
156
- this._scaleh = -this._scalex;
157
- } else {
158
- this._fliph = 1;
159
- this._scaleh = this._scalex;
160
- }
161
- }
162
-
163
- get flipv(): boolean {
164
- return this._flipv < 0;
165
- }
166
-
167
- set flipv(value: boolean) {
168
- if (value) {
169
- this._flipv = -1;
170
- this._scalev = -this._scaley;
171
- } else {
172
- this._flipv = 1;
173
- this._scalev = this._scaley;
174
- }
175
- }
176
-
177
- get flip(): boolean {
178
- return this._fliph < 0;
179
- }
180
-
181
- set flip(value: boolean) {
182
- if (value) {
183
- this._fliph = -1;
184
- this._flipv = -1;
185
-
186
- this._scaleh = -this._scalex;
187
- this._scalev = -this._scaley;
188
- } else {
189
- this._fliph = 1;
190
- this._flipv = 1;
191
-
192
- this._scaleh = this._scalex;
193
- this._scalev = this._scaley;
194
- }
195
- }
196
-
197
- get opacity(): number {
198
- return this._opacity;
199
- }
200
-
201
- set opacity(value: number) {
202
- this._opacity = clamp(value, 0, 1) || 0;
203
- }
204
-
205
- get hidden(): boolean {
206
- return this._hidden;
207
- }
208
-
209
- set hidden(value: boolean) {
210
- this._hidden = value;
211
- }
212
-
213
- get blendMode(): BlendMode {
214
- return this._blendMode;
215
- }
216
-
217
- set blendMode(value: BlendMode) {
218
- this._blendMode = value;
219
- }
220
-
221
- override get left(): number {
222
- return super.left;
223
- }
224
-
225
- override set left(value: number) {
226
- this._move("left", value);
227
- }
228
-
229
- override get right(): number {
230
- return super.right;
231
- }
232
-
233
- override set right(value: number) {
234
- this._move("right", value);
235
- }
236
-
237
- override get centerx(): number {
238
- return super.centerx;
239
- }
240
-
241
- override set centerx(value: number) {
242
- this._move("centerx", value);
243
- }
244
-
245
- override get top(): number {
246
- return super.top;
247
- }
248
-
249
- override set top(value: number) {
250
- this._move("top", value);
251
- }
252
-
253
- override get bottom(): number {
254
- return super.bottom;
255
- }
256
-
257
- override set bottom(value: number) {
258
- this._move("bottom", value);
259
- }
260
-
261
- override get centery(): number {
262
- return super.centery;
263
- }
264
-
265
- override set centery(value: number) {
266
- this._move("centery", value);
267
- }
268
-
269
- override get width(): number {
270
- return super.width;
271
- }
272
-
273
- override set width(value: number) {
274
- this._resize("width", value);
275
- }
276
-
277
- override get halfWidth(): number {
278
- return super.halfWidth;
279
- }
280
-
281
- override set halfWidth(value: number) {
282
- this._resize("halfWidth", value);
283
- }
284
-
285
- override get height(): number {
286
- return super.height;
287
- }
288
-
289
- override set height(value: number) {
290
- this._resize("height", value);
291
- }
292
-
293
- override get halfHeight(): number {
294
- return super.halfHeight;
295
- }
296
-
297
- override set halfHeight(value: number) {
298
- this._resize("halfHeight", value);
299
- }
300
-
301
- override get radius(): number {
302
- return super.radius;
303
- }
304
-
305
- override set radius(value: number) {
306
- this._resize("radius", value);
307
- }
308
-
309
- constructor(options?: Partial<BaseSpriteOptions>) {
310
- super();
311
-
312
- if (options !== undefined) {
313
- Object.assign(
314
- this,
315
- pick(options, [
316
- "left",
317
- "right",
318
- "centerx",
319
- "top",
320
- "bottom",
321
- "centery",
322
- "width",
323
- "halfWidth",
324
- "height",
325
- "halfHeight",
326
- "radius",
327
- "transformOrigin",
328
- "transformOriginx",
329
- "transformOriginy",
330
- "angle",
331
- "scale",
332
- "scalex",
333
- "scaley",
334
- "flip",
335
- "fliph",
336
- "flipv",
337
- "opacity",
338
- "hidden",
339
- "blendMode",
340
- ]),
341
- );
342
- }
343
-
344
- this.teleport();
345
- }
346
-
347
- // Public functions
348
-
349
- drawFirst(): this {
350
- const parent = this.parent;
351
-
352
- if (parent !== undefined) {
353
- const parent_layers = parent._layers;
354
-
355
- const index = parent_layers.indexOf(this);
356
- if (index >= 0) {
357
- // Step 1: Remove myself from the parent layers
358
- parent_layers.splice(index, 1);
359
-
360
- // Step 2: Insert myself
361
- parent_layers.unshift(this);
362
- }
363
- }
364
-
365
- return this;
366
- }
367
-
368
- drawLast(): this {
369
- const parent = this.parent;
370
-
371
- if (parent !== undefined) {
372
- const parent_layers = parent._layers;
373
-
374
- const index = parent_layers.indexOf(this);
375
- if (index >= 0) {
376
- // Step 1: Remove myself from the parent layers
377
- parent_layers.splice(index, 1);
378
-
379
- // Step 2: Insert myself
380
- parent_layers.push(this);
381
- }
382
- }
383
-
384
- return this;
385
- }
386
-
387
- getDrawIndex(): number {
388
- const parent = this.parent;
389
-
390
- if (parent !== undefined) {
391
- return parent._layers.indexOf(this);
392
- }
393
-
394
- return -1;
395
- }
396
-
397
- drawTo(index: number): this {
398
- const parent = this.parent;
399
-
400
- if (parent !== undefined) {
401
- const parent_layers = parent._layers;
402
-
403
- const i = parent_layers.indexOf(this);
404
- if (i >= 0) {
405
- // Step 1: Remove myself from the parent layers
406
- parent_layers.splice(i, 1);
407
-
408
- // Step 2: Insert myself
409
- parent_layers.splice(
410
- clamp(Math.round(index) || 0, 0, parent_layers.length),
411
- 0,
412
- this,
413
- );
414
- }
415
- }
416
-
417
- return this;
418
- }
419
-
420
- drawBefore(sprite: BaseSprite): this {
421
- const parent = this.parent;
422
-
423
- if (parent !== undefined) {
424
- const parent_layers = parent._layers;
425
- const sprite_index = parent_layers.indexOf(sprite);
426
-
427
- if (sprite_index >= 0) {
428
- const index = parent_layers.indexOf(this);
429
- if (index >= 0) {
430
- // Step 1: Remove myself from the parent layers
431
- parent_layers.splice(index, 1);
432
-
433
- // Step 2: Insert myself
434
- parent_layers.splice(sprite_index, 0, this);
435
- }
436
- } else if (typeof console !== "undefined") {
437
- console.error("Sprite not found in the same sprite group");
438
- console.trace();
439
- }
440
- }
441
-
442
- return this;
443
- }
444
-
445
- drawAfter(sprite: BaseSprite): this {
446
- const parent = this.parent;
447
-
448
- if (parent !== undefined) {
449
- const parent_layers = parent._layers;
450
- const sprite_index = parent_layers.indexOf(sprite);
451
-
452
- if (sprite_index >= 0) {
453
- const index = parent_layers.indexOf(this);
454
- if (index >= 0) {
455
- // Step 1: Remove myself from the parent layers
456
- parent_layers.splice(index, 1);
457
-
458
- // Step 2: Insert myself
459
- parent_layers.splice(sprite_index + 1, 0, this);
460
- }
461
- } else if (typeof console !== "undefined") {
462
- console.error("Sprite not found in the same sprite group");
463
- console.trace();
464
- }
465
- }
466
-
467
- return this;
468
- }
469
-
470
- getAbsRect(absRect?: Rect): Rect {
471
- let left = this.left;
472
- let top = this.top;
473
- let parent = this.parent;
474
- while (parent !== undefined) {
475
- left += parent.left;
476
- top += parent.top;
477
- parent = parent.parent;
478
- }
479
-
480
- if (absRect !== undefined) {
481
- absRect.left = left;
482
- absRect.top = top;
483
- absRect.width = this.width;
484
- absRect.height = this.height;
485
-
486
- return absRect;
487
- } else {
488
- return new Rect({
489
- left: left,
490
- top: top,
491
- width: this.width,
492
- height: this.height,
493
- });
494
- }
495
- }
496
-
497
- teleport(): this {
498
- const playground = this.playground;
499
-
500
- this._prevLeft = this._left;
501
- this._prevTop = this._top;
502
-
503
- if (playground !== undefined) {
504
- this._frameCounterLastMove = playground.frameCounter;
505
- }
506
-
507
- return this;
508
- }
509
-
510
- wrapLeft(increment: number, modulo: number): this {
511
- this.left += increment;
512
-
513
- if (modulo > 0) {
514
- while (this._left > 0) {
515
- this._left -= modulo;
516
- this._prevLeft -= modulo;
517
- }
518
-
519
- while (this._left <= -modulo) {
520
- this._left += modulo;
521
- this._prevLeft += modulo;
522
- }
523
- } else if (modulo < 0) {
524
- while (this._left > 0) {
525
- this._left += modulo;
526
- this._prevLeft += modulo;
527
- }
528
-
529
- while (this._left <= modulo) {
530
- this._left -= modulo;
531
- this._prevLeft -= modulo;
532
- }
533
- } else {
534
- this._left = 0;
535
- this._prevLeft = 0;
536
- }
537
-
538
- return this;
539
- }
540
-
541
- wrapTop(increment: number, modulo: number): this {
542
- this.top += increment;
543
-
544
- if (modulo > 0) {
545
- while (this._top > 0) {
546
- this._top -= modulo;
547
- this._prevTop -= modulo;
548
- }
549
-
550
- while (this._top <= -modulo) {
551
- this._top += modulo;
552
- this._prevTop += modulo;
553
- }
554
- } else if (modulo < 0) {
555
- while (this._top > 0) {
556
- this._top += modulo;
557
- this._prevTop += modulo;
558
- }
559
-
560
- while (this._top <= modulo) {
561
- this._top -= modulo;
562
- this._prevTop -= modulo;
563
- }
564
- } else {
565
- this._top = 0;
566
- this._prevTop = 0;
567
- }
568
-
569
- return this;
570
- }
571
-
572
- // Implementation details
573
-
574
- _resize(prop: keyof RectSize, value: number): void {
575
- const left = this._left;
576
- const top = this._top;
577
- const prevLeft = this._prevLeft;
578
- const prevTop = this._prevTop;
579
- const frameCounterLastMove = this._frameCounterLastMove;
580
-
581
- super[prop] = value;
582
-
583
- // Resizing the sprite does not mean that it should change its position.
584
- // However, the new dimensions must be taken into consideration for the interpolation
585
- this._prevLeft = prevLeft + (this._left - left);
586
- this._prevTop = prevTop + (this._top - top);
587
- this._frameCounterLastMove = frameCounterLastMove;
588
- }
589
-
590
- _move(prop: keyof RectPos, value: number): void {
591
- const playground = this.playground;
592
-
593
- if (playground !== undefined) {
594
- const frameCounter = playground.frameCounter;
595
-
596
- if (frameCounter !== this._frameCounterLastMove) {
597
- this._prevLeft = this._left;
598
- this._prevTop = this._top;
599
- this._frameCounterLastMove = frameCounter;
600
- }
601
- }
602
-
603
- super[prop] = value;
604
- }
605
-
606
- _checkUpdate(): void {
607
- const oldNeedsUpdate = this._needsUpdate;
608
-
609
- this._needsUpdate = false;
610
-
611
- this._updateNeedsUpdate(oldNeedsUpdate);
612
- }
613
-
614
- _updateNeedsUpdate(oldNeedsUpdate: boolean): void {
615
- const parent = this.parent;
616
-
617
- if (parent !== undefined) {
618
- const parent_update_list = parent._updateList;
619
-
620
- if (this._needsUpdate && !oldNeedsUpdate) {
621
- const index = parent_update_list.indexOf(this);
622
- if (index < 0) {
623
- parent_update_list.push(this);
624
- }
625
- } else if (!this._needsUpdate && oldNeedsUpdate) {
626
- const index = parent_update_list.indexOf(this);
627
- if (index >= 0) {
628
- parent_update_list.splice(index, 1);
629
- }
630
- }
631
- }
632
- }
633
-
634
- _onReparent(): void {
635
- // no-op
636
- }
637
-
638
- _initRenderer(): void {
639
- // no-op
640
- }
641
-
642
- _update(): void {
643
- // no-op
644
- }
645
-
646
- _draw(interp: number): void {
647
- const playground = this.playground;
648
-
649
- if (playground !== undefined) {
650
- const trunc = Math.trunc;
651
- const myLeft = this._left;
652
- const myTop = this._top;
653
- const prevLeft = this._prevLeft;
654
- const prevTop = this._prevTop;
655
- const truncPrevLeft = trunc(prevLeft);
656
- const truncPrevTop = trunc(prevTop);
657
- let left = trunc(myLeft);
658
- let top = trunc(myTop);
659
-
660
- if (left !== truncPrevLeft || top !== truncPrevTop) {
661
- if (this._frameCounterLastMove === playground.frameCounter - 1) {
662
- const round = Math.round;
663
-
664
- left = round(lerp(truncPrevLeft, left, interp));
665
- top = round(lerp(truncPrevTop, top, interp));
666
- } else {
667
- this._prevLeft = myLeft;
668
- this._prevTop = myTop;
669
- }
670
- }
671
-
672
- this._drawLeft = left;
673
- this._drawTop = top;
674
- this._drawWidth = trunc(this._width);
675
- this._drawHeight = trunc(this._height);
676
- }
677
- }
678
-
679
- _remove(): void {
680
- // no-op
681
- }
682
- }