canvasengine 2.0.0-beta.32 → 2.0.0-beta.34

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { h as a } from "./index-19a35G23.js";
2
- import { A as r, B as n, w as o, C as c, m as l, l as p, D as S, v as m, a5 as u, a4 as g, a2 as b, n as d, G as C, c as j, M as T, N as E, O, P as f, a3 as v, R as w, o as h, p as D, S as P, q as k, r as x, T as y, b as A, V as H, t as M, a1 as V, a0 as B, _ as G, d as N, J as R, H as q, K as U, e as z, W as I, $ as J, f as K, g as L, x as Q, j as W, i as X, y as Y, k as Z, X as _, I as $, Q as F, L as aa, Z as sa, z as ea, s as ta, U as ia, Y as ra, a as na, u as oa } from "./index-19a35G23.js";
1
+ import { h as a } from "./index-BLbc2zG5.js";
2
+ import { A as r, B as n, w as o, C as c, m as l, l as p, D as S, v as m, a5 as u, a4 as g, a2 as b, n as d, G as C, c as j, M as T, N as E, O, P as f, a3 as v, R as w, o as h, p as D, S as P, q as k, r as x, T as y, b as A, V as H, t as M, a1 as V, a0 as B, _ as G, d as N, J as R, H as q, K as U, e as z, W as I, $ as J, f as K, g as L, x as Q, j as W, i as X, y as Y, k as Z, X as _, I as $, Q as F, L as aa, Z as sa, z as ea, s as ta, U as ia, Y as ra, a as na, u as oa } from "./index-BLbc2zG5.js";
3
3
  const e = a.Howler;
4
4
  export {
5
5
  r as ArraySubject,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvasengine",
3
- "version": "2.0.0-beta.32",
3
+ "version": "2.0.0-beta.34",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -182,6 +182,7 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
182
182
  const { props, propObservables } = params;
183
183
  const tick: Signal = props.context.tick;
184
184
  const sheet = props.sheet ?? {};
185
+ const definition = props.sheet?.definition ?? {};
185
186
  this.app = props.context.app();
186
187
  if (sheet?.onFinish) {
187
188
  this.onFinish = sheet.onFinish;
@@ -190,8 +191,8 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
190
191
  if (this.destroyed) return
191
192
  this.update(value);
192
193
  });
193
- if (props.sheet?.definition) {
194
- this.spritesheet = props.sheet.definition;
194
+ if (definition) {
195
+ this.spritesheet = definition.value ?? definition;
195
196
  await this.createAnimations();
196
197
  }
197
198
  if (sheet.params) {
@@ -267,7 +268,14 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
267
268
  return texture
268
269
  }
269
270
 
270
- const sheet = props.sheet;
271
+ const sheet = props.sheet
272
+ const definition = props.sheet?.definition ?? {};
273
+
274
+ if (definition?.type === 'reset') {
275
+ this.spritesheet = definition.value ?? definition;
276
+ await this.resetAnimations();
277
+ }
278
+
271
279
  if (sheet?.params) this.sheetParams = sheet?.params;
272
280
 
273
281
  if (sheet?.playing && this.isMounted) {
@@ -287,9 +295,7 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
287
295
  if (isElement(props.texture)) {
288
296
  const textureInstance = props.texture.componentInstance;
289
297
  textureInstance.subjectInit
290
- .subscribe((value) => {
291
- console.log('a', value?.width)
292
- })
298
+ .subscribe()
293
299
  this.texture = this.renderer?.generateTexture(props.texture.componentInstance);
294
300
  } else {
295
301
  this.texture = props.texture;
@@ -337,7 +343,6 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
337
343
 
338
344
  stop() {
339
345
  this.currentAnimation = null;
340
- this.destroy();
341
346
  }
342
347
 
343
348
  play(name: string, params: any[] = []) {
@@ -353,7 +358,7 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
353
358
  );
354
359
  }
355
360
 
356
- const cloneParams = (params);
361
+ const cloneParams = structuredClone(params);
357
362
 
358
363
  this.removeChildren();
359
364
  animation.sprites = [];
@@ -393,6 +398,44 @@ export class CanvasSprite extends DisplayObject(PixiSprite) {
393
398
  });
394
399
  }
395
400
 
401
+ /**
402
+ * Resets the sprite by destroying and recreating all animations
403
+ * This method clears the current animation state, destroys existing textures,
404
+ * and recreates all animations from the spritesheet
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * // Reset all animations to their initial state
409
+ * sprite.resetAnimations();
410
+ *
411
+ * // Reset and then play a specific animation
412
+ * await sprite.resetAnimations();
413
+ * sprite.play('walk');
414
+ * ```
415
+ */
416
+ async resetAnimations(): Promise<void> {
417
+ // Stop current animation
418
+ this.stop();
419
+
420
+ // Clear all animations and textures
421
+ this.animations.clear();
422
+
423
+ // Reset animation state
424
+ this.currentAnimation = null;
425
+ this.currentAnimationContainer = null;
426
+ this.time = 0;
427
+ this.frameIndex = 0;
428
+
429
+ // Clear children
430
+ this.removeChildren();
431
+
432
+ // Recreate animations from spritesheet
433
+ if (this.spritesheet) {
434
+ await this.createAnimations();
435
+ this.play(this.sheetCurrentAnimation, [this.sheetParams]);
436
+ }
437
+ }
438
+
396
439
  update({ deltaRatio }) {
397
440
  if (
398
441
  !this.isPlaying() ||