@melonjs/spine-plugin 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Changelog
2
2
 
3
- ## 1.4.0 - 2023-09-xx
3
+ ## 1.5.0 - 2023-09-23
4
+
5
+ - fix the `addAnimation()` method not returning the corresponding set TrackEntry
6
+ - fix the base renderable `flip[X/Y]` method when used/applied to the Spine renderable
7
+ - add a `isCurrentAnimation()` method that returns true if the given name is corresponding to the current track current animation
8
+ - expose the `currentTrack` property to access the corresponding current animation track entry
9
+ - clarify in the readme that the current plugin support both the 4.1 and 4.2-beta Spine runtime versions
10
+ - the spine-plugin now requires to be properly registered using `me.plugin.register(SpinePlugin);`
11
+ - the spine-plugin now requires melonJS v15.12.0 or higher
12
+ - add check for minimum melonJS version when the plugin is registered
13
+ - restructure code to adhere to the updated plugin API and get a proper reference to the melonjs renderer instance
14
+
15
+ ## 1.4.0 - 2023-09-05
4
16
 
5
17
  - add support for loading spine assets through the melonJS preloader (see README)
6
18
  - add inline documentation for the Spine class, properties and methods
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # melonJS Spine Plugin
2
2
 
3
- a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementation for [melonJS 2](http://www.melonjs.org)
3
+ a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.x plugin implementation for [melonJS 2](http://www.melonjs.org)
4
4
 
5
5
  ![melonjs-spine-gif](https://github.com/melonjs/spine-plugin/assets/4033090/dc259c8e-def6-419e-83a9-cda374715686)
6
6
 
@@ -11,10 +11,10 @@ a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementati
11
11
  [![jsDeliver](https://data.jsdelivr.com/v1/package/npm/@melonjs/spine-plugin/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@melonjs/spine-plugin)
12
12
 
13
13
 
14
- Installation
14
+ ## Installation
15
15
  -------------------------------------------------------------------------------
16
16
  this plugin is already bundled with the required Spine [4.x runtime](package.json#dependencies), so there is no need to install it separately.
17
- >Note: this plugin requires melonJS version 15.10 or higher.
17
+ >Note: this plugin requires melonJS version 15.12 or higher.
18
18
 
19
19
  To install the plugin using npm :
20
20
 
@@ -22,9 +22,12 @@ To install the plugin using npm :
22
22
 
23
23
  Then import and use the plugin in your project. For example:
24
24
  ```JavaScript
25
- import * as Spine from '@melonjs/spine-plugin';
25
+ import { SpinePlugin } from '@melonjs/spine-plugin';
26
26
  import * as me from 'melonjs';
27
27
 
28
+ // register the plugin
29
+ me.plugin.register(SpinePlugin);
30
+
28
31
  // prepare/declare assets for the preloader
29
32
  const DataManifest = [
30
33
  {
@@ -37,22 +40,41 @@ const DataManifest = [
37
40
  "type": "spine",
38
41
  "src": "data/spine/alien.atlas"
39
42
  },
40
- ]
43
+ ];
44
+
45
+ // import default Spine class
46
+ import Spine from '@melonjs/spine-plugin';
47
+
48
+ // preload assets
49
+ me.loader.preload(DataManifest, async function() {
41
50
 
42
- // create a new Spine Renderable
43
- let spineAlien = new Spine(100, 100, {atlasFile: "alien.atlas", jsonFile: "alien-ess.json"});
51
+ // create a new Spine Renderable
52
+ let spineAlien = new Spine(100, 100, {atlasFile: "alien.atlas", jsonFile: "alien-ess.json"});
44
53
 
45
- // set default animation
46
- spineAlien.setAnimation(0, "death", true);
54
+ // set default animation
55
+ spineAlien.setAnimation(0, "death", true);
47
56
 
48
- // add it to the game world
49
- me.game.world.addChild(spineAlien);
57
+ // add it to the game world
58
+ me.game.world.addChild(spineAlien);
59
+
60
+ }
50
61
  ```
51
62
  >Note: use "spine" as a value for the `type` property to indicate which assets and are actual Spine assets and to be loaded using the plugin (requires version 1.4.0 or higher of the Spine plugin)
52
63
 
53
64
  for more details, see a complete usage example in the [test](test) folder
54
65
 
55
- Questions, need help ?
66
+ ## Compatibility
67
+ -------------------------------------------------------------------------------
68
+
69
+ below is the compatibility version matrix :
70
+
71
+ | melonJS | @melonjs/spine-plugin | spine-runtime |
72
+ |---|---|---|
73
+ | v15.12.x (or higher) | v1.x | v4.1, v4.2-beta |
74
+
75
+ >Note: the current version of the spine-plugin is bundled with the 4.2.x beta version of the Spine runtime, which is for now backward compatible with the Spine 4.1 runtime (from a player/rendering point of view).
76
+
77
+ ## Questions, need help ?
56
78
  -------------------------------------------------------------------------------
57
79
  If you need technical support, you can contact us through the following channels :
58
80
  * Forums: with melonJS 2 we moved to a new discourse [forum](https://melonjs.discourse.group), but we can still also find the previous one [here](http://www.html5gamedevs.com/forum/32-melonjs/)
@@ -1,7 +1,15 @@
1
- export let assetManager: AssetManager;
2
1
  /**
3
2
  * @classdesc
4
- * An object to display a Spine animated skeleton on screen.
3
+ * a Spine 4.x plugin implementation for melonJS
4
+ * @augments plugin.BasePlugin
5
+ */
6
+ export class SpinePlugin extends plugin.BasePlugin {
7
+ constructor();
8
+ assetManager: AssetManager;
9
+ }
10
+ /**
11
+ * @classdesc
12
+ * An renderable object to render Spine animated skeleton.
5
13
  * @augments Renderable
6
14
  */
7
15
  declare class Spine extends Renderable {
@@ -240,7 +248,6 @@ declare class Spine extends Renderable {
240
248
  VertexAttachment: typeof VertexAttachment;
241
249
  VertexAttribute: typeof VertexAttribute;
242
250
  readonly VertexAttributeType: any;
243
- WebGLBlendModeConverter: typeof WebGLBlendModeConverter;
244
251
  WindowedMean: typeof WindowedMean;
245
252
  } | {
246
253
  __proto__: null;
@@ -400,12 +407,36 @@ declare class Spine extends Renderable {
400
407
  WindowedMean: typeof WindowedMean;
401
408
  };
402
409
  skeleton: any;
410
+ plugin: plugin.BasePlugin;
411
+ renderer: any;
403
412
  animationState: any;
404
413
  skeletonRenderer: SkeletonRenderer;
405
- assetManager: any;
406
414
  root: any;
407
415
  boneOffset: Vector2;
408
416
  boneSize: Vector2;
417
+ isSpineFlipped: {
418
+ x: boolean;
419
+ y: boolean;
420
+ };
421
+ /**
422
+ * Stores settings and other state for the playback of the current animation (if any).
423
+ * @type {TrackEntry}
424
+ * @see http://en.esotericsoftware.com/spine-api-reference#TrackEntry
425
+ * @see setAnimation
426
+ * @default undefined
427
+ * @example
428
+ * // set a default animation to "run"
429
+ * this.setAnimation(0, "run", true);
430
+ * ...
431
+ * ...
432
+ * // pause the animation
433
+ * this.currentTrack.timeScale = 0;
434
+ * ...
435
+ * ...
436
+ * // resume the animation
437
+ * this.currentTrack.timeScale = 1;
438
+ */
439
+ currentTrack: TrackEntry;
409
440
  mixTime: number;
410
441
  jsonFile: number | undefined;
411
442
  atlasFile: number | undefined;
@@ -435,7 +466,19 @@ declare class Spine extends Renderable {
435
466
  * me.game.world.addChild(spineAlien);
436
467
  */
437
468
  setSkeleton(atlasFile?: number | undefined, jsonFile?: number | undefined): void;
469
+ /**
470
+ * flip the Spine skeleton on the horizontal axis (around its center)
471
+ * @param {boolean} [flip=true] - `true` to flip this Spine object.
472
+ * @returns {Spine} Reference to this object for method chaining
473
+ */
474
+ flipX(flip?: boolean | undefined): Spine;
438
475
  isDirty: boolean | undefined;
476
+ /**
477
+ * flip the Spine skeleton on the vertical axis (around its center)
478
+ * @param {boolean} [flip=true] - `true` to flip this Spine object.
479
+ * @returns {Spine} Reference to this object for method chaining
480
+ */
481
+ flipY(flip?: boolean | undefined): Spine;
439
482
  /**
440
483
  * Rotate this Spine object by the specified angle (in radians).
441
484
  * @param {number} angle - The angle to rotate (in radians)
@@ -478,26 +521,37 @@ declare class Spine extends Renderable {
478
521
  * @param {number} [track_index] - If the formerly current track entry was never applied to a skeleton, it is replaced (not mixed from). In either case trackEnd determines when the track is cleared.
479
522
  * @param {number} [index] - the animation index
480
523
  * @param {boolean} [loop= false] - If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its duration.
481
- * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose event occurs.
524
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose event occurs.
482
525
  */
483
- setAnimationByIndex(track_index?: number | undefined, index?: number | undefined, loop?: boolean | undefined): void;
526
+ setAnimationByIndex(track_index?: number | undefined, index?: number | undefined, loop?: boolean | undefined): TrackEntry;
484
527
  /**
485
528
  * Sets the current animation for a track, discarding any queued animations.
486
529
  * @param {number} [track_index] - If the formerly current track entry was never applied to a skeleton, it is replaced (not mixed from). In either case trackEnd determines when the track is cleared.
487
530
  * @param {string} [name] - the animation name
488
531
  * @param {boolean} [loop= false] - If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its duration.
489
- * @returns A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose event occurs.
532
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose event occurs.
490
533
  * @example
491
534
  * // set the current animation
492
535
  * spineAlien.setAnimation(0, "death", true);
493
536
  */
494
- setAnimation(track_index?: number | undefined, name?: string | undefined, loop?: boolean | undefined): void;
537
+ setAnimation(track_index?: number | undefined, name?: string | undefined, loop?: boolean | undefined): TrackEntry;
538
+ /**
539
+ * return true if the given animation name is the current running animation for the current track.
540
+ * @name isCurrentAnimation
541
+ * @param {string} name - animation name
542
+ * @returns {boolean}
543
+ * @example
544
+ * if (!this.isCurrentAnimation("death")) {
545
+ * // do something funny...
546
+ * }
547
+ */
548
+ isCurrentAnimation(name: string): boolean;
495
549
  /**
496
550
  * Adds an animation to be played after the current or last queued animation for a track, and sets the track entry's mixDuration.
497
551
  * @param {number} [delay=0] - If > 0, sets delay. If <= 0, the delay set is the duration of the previous track entry minus any mix duration plus the specified `delay` (ie the mix ends at (`delay` = 0) or before (`delay` < 0) the previous track entry duration). If the previous entry is looping, its next loop completion is used instead of its duration.
498
- * @return A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose} event occurs.
552
+ * @return {TrackEntry} A track entry to allow further customization of animation playback. References to the track entry must not be kept after the dispose} event occurs.
499
553
  */
500
- addAnimationByIndex(track_index: any, index: any, loop?: boolean, delay?: number | undefined): void;
554
+ addAnimationByIndex(track_index: any, index: any, loop?: boolean, delay?: number | undefined): TrackEntry;
501
555
  addAnimationByName(track_index: any, animationName: any, loop?: boolean, delay?: number): void;
502
556
  getSpinePosition(): Vector2d;
503
557
  setSpineSize(width: any, height: any): void;
@@ -534,21 +588,79 @@ declare class Spine extends Renderable {
534
588
  */
535
589
  setSkinByName(skinName: string): void;
536
590
  /**
537
- * Sets this slot to the setup pose.
591
+ * Reset this slot to the setup pose.
538
592
  */
539
593
  setToSetupPose(): void;
540
594
  }
595
+ import { plugin } from 'melonjs';
541
596
  /**
542
597
  * @classdesc
543
598
  * An Asset Manager class to load spine assets
544
599
  */
545
600
  declare class AssetManager {
546
601
  /**
602
+ * @param {CanvasRenderer|WebGLRenderer} renderer - a melonJS renderer instance
547
603
  * @param {string} [pathPrefix=""] - a default path prefix for assets location
548
604
  */
549
- constructor(pathPrefix?: string | undefined);
550
- asset_manager: any;
551
- pathPrefix: any;
605
+ constructor(renderer: CanvasRenderer | WebGLRenderer, pathPrefix?: string | undefined);
606
+ asset_manager: {
607
+ pathPrefix: string;
608
+ assets: {};
609
+ errors: {};
610
+ toLoad: number;
611
+ loaded: number;
612
+ textureLoader: any;
613
+ downloader: Downloader;
614
+ start(path: any): string;
615
+ success(callback: any, path: any, asset: any): void;
616
+ error(callback: any, path: any, message: any): void;
617
+ loadAll(): Promise<any>;
618
+ setRawDataURI(path: any, data: any): void;
619
+ loadBinary(path: any, success?: () => void, error?: () => void): void;
620
+ loadText(path: any, success?: () => void, error?: () => void): void;
621
+ loadJson(path: any, success?: () => void, error?: () => void): void;
622
+ loadTexture(path: any, success?: () => void, error?: () => void): void;
623
+ loadTextureAtlas(path: any, success: (() => void) | undefined, error: (() => void) | undefined, fileAlias: any): void;
624
+ get(path: any): any;
625
+ require(path: any): any;
626
+ remove(path: any): any;
627
+ removeAll(): void;
628
+ isLoadingComplete(): boolean;
629
+ getToLoad(): number;
630
+ getLoaded(): number;
631
+ dispose(): void;
632
+ hasErrors(): boolean;
633
+ getErrors(): {};
634
+ } | {
635
+ pathPrefix: string;
636
+ assets: {};
637
+ errors: {};
638
+ toLoad: number;
639
+ loaded: number;
640
+ textureLoader: any;
641
+ downloader: Downloader;
642
+ start(path: any): string;
643
+ success(callback: any, path: any, asset: any): void;
644
+ error(callback: any, path: any, message: any): void;
645
+ loadAll(): Promise<any>;
646
+ setRawDataURI(path: any, data: any): void;
647
+ loadBinary(path: any, success?: () => void, error?: () => void): void;
648
+ loadText(path: any, success?: () => void, error?: () => void): void;
649
+ loadJson(path: any, success?: () => void, error?: () => void): void;
650
+ loadTexture(path: any, success?: () => void, error?: () => void): void;
651
+ loadTextureAtlas(path: any, success: (() => void) | undefined, error: (() => void) | undefined, fileAlias: any): void;
652
+ get(path: any): any;
653
+ require(path: any): any;
654
+ remove(path: any): any;
655
+ removeAll(): void;
656
+ isLoadingComplete(): boolean;
657
+ getToLoad(): number;
658
+ getLoaded(): number;
659
+ dispose(): void;
660
+ hasErrors(): boolean;
661
+ getErrors(): {};
662
+ };
663
+ pathPrefix: string;
552
664
  /**
553
665
  * set a default path prefix for assets location
554
666
  * @see loadAsset
@@ -562,17 +674,37 @@ declare class AssetManager {
562
674
  * @param {string} atlas
563
675
  * @param {string} skel
564
676
  * @example
565
- * // load spine assets
677
+ * // "manually" load spine assets
566
678
  * Spine.assetManager.setPrefix("data/spine/");
567
679
  * Spine.assetManager.loadAsset("alien.atlas", "alien-ess.json");
568
680
  * await Spine.assetManager.loadAll();
569
681
  */
570
682
  loadAsset(atlas: string, skel: string): void;
683
+ /**
684
+ * load the given texture atlas
685
+ * @param {string} atlas
686
+ */
687
+ loadTextureAtlas(atlas: string, onload: any, onerror: any): void;
688
+ /**
689
+ * load the given skeleton .skel file
690
+ * @param {string} skel
691
+ */
692
+ loadBinary(skel: string, onload: any, onerror: any): void;
693
+ /**
694
+ * load the given skeleton binary file
695
+ * @param {string} skel
696
+ */
697
+ loadText(skel: string, onload: any, onerror: any): void;
571
698
  /**
572
699
  * load all defined spine assets
573
700
  * @see loadAsset
574
701
  */
575
- loadAll(): any;
702
+ loadAll(): Promise<any>;
703
+ /**
704
+ * get the loaded skeleton data
705
+ * @param {string} path
706
+ */
707
+ require(path: string): any;
576
708
  }
577
709
  /******************************************************************************
578
710
  * Spine Runtimes License Agreement
@@ -2369,34 +2501,6 @@ declare class PointAttachment extends VertexAttachment {
2369
2501
  computeWorldRotation(bone: any): number;
2370
2502
  copy(): PointAttachment;
2371
2503
  }
2372
- /******************************************************************************
2373
- * Spine Runtimes License Agreement
2374
- * Last updated July 28, 2023. Replaces all prior versions.
2375
- *
2376
- * Copyright (c) 2013-2023, Esoteric Software LLC
2377
- *
2378
- * Integration of the Spine Runtimes into software or otherwise creating
2379
- * derivative works of the Spine Runtimes is permitted under the terms and
2380
- * conditions of Section 2 of the Spine Editor License Agreement:
2381
- * http://esotericsoftware.com/spine-editor-license
2382
- *
2383
- * Otherwise, it is permitted to integrate the Spine Runtimes into software or
2384
- * otherwise create derivative works of the Spine Runtimes (collectively,
2385
- * "Products"), provided that each user of the Products must obtain their own
2386
- * Spine Editor license and redistribution of the Products in any form must
2387
- * include this license and copyright notice.
2388
- *
2389
- * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
2390
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2391
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2392
- * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
2393
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2394
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
2395
- * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
2396
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2397
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
2398
- * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2399
- *****************************************************************************/
2400
2504
  declare class PolygonBatcher {
2401
2505
  static getAndResetGlobalDrawCalls(): number;
2402
2506
  constructor(context: any, twoColorTint?: boolean, maxVertices?: number);
@@ -2411,10 +2515,9 @@ declare class PolygonBatcher {
2411
2515
  mesh: Mesh;
2412
2516
  srcColorBlend: any;
2413
2517
  srcAlphaBlend: any;
2414
- dstColorBlend: any;
2415
- dstAlphaBlend: any;
2518
+ dstBlend: any;
2416
2519
  begin(shader: any): void;
2417
- setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstColorBlend: any, dstAlphaBlend: any): void;
2520
+ setBlendMode(blendMode: any, premultipliedAlpha: any): void;
2418
2521
  draw(texture: any, vertices: any, indices: any): void;
2419
2522
  flush(): void;
2420
2523
  end(): void;
@@ -2424,6 +2527,12 @@ declare class PolygonBatcher {
2424
2527
  declare namespace PolygonBatcher {
2425
2528
  let disableCulling: boolean;
2426
2529
  let globalDrawCalls: number;
2530
+ let blendModesGL: {
2531
+ srcRgb: number;
2532
+ srcRgbPma: number;
2533
+ dstRgb: number;
2534
+ srcAlpha: number;
2535
+ }[];
2427
2536
  }
2428
2537
  declare class Pool {
2429
2538
  constructor(instantiator: any);
@@ -2781,10 +2890,9 @@ declare class ShapeRenderer {
2781
2890
  mesh: Mesh;
2782
2891
  srcColorBlend: any;
2783
2892
  srcAlphaBlend: any;
2784
- dstColorBlend: any;
2785
- dstAlphaBlend: any;
2893
+ dstBlend: any;
2786
2894
  begin(shader: any): void;
2787
- setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstColorBlend: any, dstAlphaBlend: any): void;
2895
+ setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstBlend: any): void;
2788
2896
  setColor(color: any): void;
2789
2897
  setColorWith(r: any, g: any, b: any, a: any): void;
2790
2898
  point(x: any, y: any, color: any): void;
@@ -3562,8 +3670,10 @@ declare class SlotData {
3562
3670
  declare class SpineCanvas {
3563
3671
  /** Constructs a new spine canvas, rendering to the provided HTML canvas. */
3564
3672
  constructor(canvas: any, config: any);
3673
+ config: any;
3565
3674
  /** Tracks the current time, delta, and other time related statistics. */
3566
3675
  time: TimeKeeper;
3676
+ disposed: boolean;
3567
3677
  htmlCanvas: any;
3568
3678
  context: ManagedWebGLRenderingContext;
3569
3679
  renderer: SceneRenderer;
@@ -3600,6 +3710,8 @@ declare class SpineCanvas {
3600
3710
  input: Input;
3601
3711
  /** Clears the canvas with the given color. The color values are given in the range [0,1]. */
3602
3712
  clear(r: any, g: any, b: any, a: any): void;
3713
+ /** Disposes the app, so the update() and render() functions are no longer called. Calls the dispose() callback.*/
3714
+ dispose(): void;
3603
3715
  }
3604
3716
  declare class StringSet {
3605
3717
  entries: {};
@@ -4185,13 +4297,6 @@ declare class VertexAttribute {
4185
4297
  type: any;
4186
4298
  numElements: any;
4187
4299
  }
4188
- declare class WebGLBlendModeConverter {
4189
- static getDestGLBlendMode(blendMode: any): 1 | 771;
4190
- static getDestColorGLBlendMode(blendMode: any): 1 | 769 | 771;
4191
- static getDestAlphaGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 771;
4192
- static getSourceColorGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 770 | 774;
4193
- static getSourceAlphaGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 770;
4194
- }
4195
4300
  declare class WindowedMean {
4196
4301
  constructor(windowSize?: number);
4197
4302
  addedValues: number;