@melonjs/spine-plugin 1.3.0 → 1.4.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,12 @@
1
1
  # Changelog
2
2
 
3
- ## 1.3.0 - 2023-08-28å
3
+ ## 1.4.0 - 2023-09-xx
4
+
5
+ - add support for loading spine assets through the melonJS preloader (see README)
6
+ - add inline documentation for the Spine class, properties and methods
7
+ - console now display both the plugin and spine runtime versions
8
+
9
+ ## 1.3.0 - 2023-08-28
4
10
 
5
11
  - add support for Mesh Attachement
6
12
  - added more examples under the test folder and separated them into individual files
package/README.md CHANGED
@@ -13,8 +13,8 @@ a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementati
13
13
 
14
14
  Installation
15
15
  -------------------------------------------------------------------------------
16
- this plugin is already bundled with the required Spine runtime, so there is no need to install it separately.
17
- >Note: this plugin requires melonJS version 15.9.2 or higher.
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.
18
18
 
19
19
  To install the plugin using npm :
20
20
 
@@ -23,19 +23,32 @@ To install the plugin using npm :
23
23
  Then import and use the plugin in your project. For example:
24
24
  ```JavaScript
25
25
  import * as Spine from '@melonjs/spine-plugin';
26
-
27
- // load assets
28
- Spine.assetManager.setPrefix("data/spine/")
29
- Spine.assetManager.loadAsset("alien.atlas", "alien-ess.json");
30
-
31
- // create new Spine Renderable
32
- export default class AlienSpine extends Spine {
33
- constructor(x, y, settings ){
34
- super(x, y, settings);
35
- ...
36
- }
37
- }
26
+ import * as me from 'melonjs';
27
+
28
+ // prepare/declare assets for the preloader
29
+ const DataManifest = [
30
+ {
31
+ "name": "alien-ess.json",
32
+ "type": "spine",
33
+ "src": "data/spine/alien-ess.json"
34
+ },
35
+ {
36
+ "name": "alien.atlas",
37
+ "type": "spine",
38
+ "src": "data/spine/alien.atlas"
39
+ },
40
+ ]
41
+
42
+ // create a new Spine Renderable
43
+ let spineAlien = new Spine(100, 100, {atlasFile: "alien.atlas", jsonFile: "alien-ess.json"});
44
+
45
+ // set default animation
46
+ spineAlien.setAnimation(0, "death", true);
47
+
48
+ // add it to the game world
49
+ me.game.world.addChild(spineAlien);
38
50
  ```
51
+ >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)
39
52
 
40
53
  for more details, see a complete usage example in the [test](test) folder
41
54
 
@@ -1,6 +1,49 @@
1
1
  export let assetManager: AssetManager;
2
- declare class Spine extends Renderable$1 {
3
- constructor(x: any, y: any, settings: any);
2
+ /**
3
+ * @classdesc
4
+ * An object to display a Spine animated skeleton on screen.
5
+ * @augments Renderable
6
+ */
7
+ declare class Spine extends Renderable {
8
+ /**
9
+ * @param {number} x - the x coordinates of the Spine object
10
+ * @param {number} y - the y coordinates of the Spine object
11
+ * @param {object} settings - Configuration parameters for the Spine object
12
+ * @param {number} [settings.atlasFile] - the name of the atlasFile to be used to create this spine animation
13
+ * @param {number} [settings.jsonFile] - the name of the atlasFile to be used to create this spine animation
14
+ * @param {number} [settings.mixTime = 0.2] - the default mix duration to use when no mix duration has been defined between two animations.
15
+ * @example
16
+ * import * as Spine from '@melonjs/spine-plugin';
17
+ * import * as me from 'melonjs';
18
+ *
19
+ * // prepare/declare assets for the preloader
20
+ * const DataManifest = [
21
+ * {
22
+ * "name": "alien-ess.json",
23
+ * "type": "spine",
24
+ * "src": "data/spine/alien-ess.json"
25
+ * },
26
+ * {
27
+ * "name": "alien.atlas",
28
+ * "type": "spine",
29
+ * "src": "data/spine/alien.atlas"
30
+ * },
31
+ * ]
32
+ *
33
+ * // create a new Spine Renderable
34
+ * let spineAlien = new Spine(100, 100, {atlasFile: "alien.atlas", jsonFile: "alien-ess.json"});
35
+ *
36
+ * // set default animation
37
+ * spineAlien.setAnimation(0, "death", true);
38
+ *
39
+ * // add it to the game world
40
+ * me.game.world.addChild(spineAlien);
41
+ */
42
+ constructor(x: number, y: number, settings: {
43
+ atlasFile?: number | undefined;
44
+ jsonFile?: number | undefined;
45
+ mixTime?: number | undefined;
46
+ });
4
47
  runtime: {
5
48
  __proto__: null;
6
49
  AlphaTimeline: typeof AlphaTimeline;
@@ -363,53 +406,208 @@ declare class Spine extends Renderable$1 {
363
406
  root: any;
364
407
  boneOffset: Vector2;
365
408
  boneSize: Vector2;
366
- scaleValue: {
367
- x: number;
368
- y: number;
369
- };
370
- mixTime: any;
371
- jsonFile: any;
372
- atlasFile: any;
409
+ mixTime: number;
410
+ jsonFile: number | undefined;
411
+ atlasFile: number | undefined;
373
412
  set debugRendering(arg: boolean);
413
+ /**
414
+ * Whether to enabler the debug mode when rendering the spine object
415
+ * @default false
416
+ * @type {boolean}
417
+ */
374
418
  get debugRendering(): boolean;
375
- setSkeleton(atlasFile: any, jsonFile: any): void;
376
- loadSpineAssets(atlasFile: any, jsonFile: any): void;
377
- rotate(angle: any, v: any): void;
378
- scale(x: any, y?: any): void;
419
+ /**
420
+ * set and load the given skeleton atlas and json definition files
421
+ * (use this if you did not specify any json or atlas through the constructor)
422
+ * @param {number} [atlasFile] - the name of the atlasFile to be used to create this spine animation
423
+ * @param {number} [jsonFile] - the name of the atlasFile to be used to create this spine animation
424
+ * @example
425
+ * // create a new Spine Renderable
426
+ * let spineAlien = new Spine(100, 100);
427
+ *
428
+ * // set the skeleton
429
+ * spineAlien.setSkeleton("alien.atlas", "alien-ess.json");
430
+ *
431
+ * // set default animation
432
+ * spineAlien.setAnimation(0, "death", true);
433
+ *
434
+ * // add it to the game world
435
+ * me.game.world.addChild(spineAlien);
436
+ */
437
+ setSkeleton(atlasFile?: number | undefined, jsonFile?: number | undefined): void;
438
+ isDirty: boolean | undefined;
439
+ /**
440
+ * Rotate this Spine object by the specified angle (in radians).
441
+ * @param {number} angle - The angle to rotate (in radians)
442
+ * @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
443
+ * @returns {Spine} Reference to this object for method chaining
444
+ */
445
+ rotate(angle: number, v?: Vector2d | ObservableVector2d): Spine;
446
+ /**
447
+ * scale the Spine object around his anchor point. Scaling actually applies changes
448
+ * to the currentTransform member wich is used by the renderer to scale the object
449
+ * when rendering. It does not scale the object itself. For example if the renderable
450
+ * is an image, the image.width and image.height properties are unaltered but the currentTransform
451
+ * member will be changed.
452
+ * @param {number} x - a number representing the abscissa of the scaling vector.
453
+ * @param {number} [y=x] - a number representing the ordinate of the scaling vector.
454
+ * @returns {Spine} Reference to this object for method chaining
455
+ */
456
+ scale(x: number, y?: number | undefined): Spine;
457
+ /**
458
+ * update the bounding box for this spine object.
459
+ * (this will automatically update the bounds of the entire skeleton animation)
460
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
461
+ * @returns {Bounds} this shape bounding box Rectangle object
462
+ */
463
+ updateBounds(absolute?: boolean | undefined): Bounds;
464
+ /**
465
+ * update function (automatically called by melonJS).
466
+ * @param {number} dt - time since the last update in milliseconds.
467
+ * @returns {boolean} true if the renderable is dirty
468
+ */
469
+ update(dt: number): boolean;
379
470
  /**
380
471
  * draw this spine object
381
- * @name draw
382
- * @memberof Spine
383
- * @protected
384
472
  * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance
385
473
  * @param {Camera2d} [viewport] - the viewport to (re)draw
386
474
  */
387
- protected draw(renderer: CanvasRenderer | WebGLRenderer): void;
388
- setAnimationByIndex(track_index: any, index: any, loop?: boolean): void;
389
- setAnimation(track_index: any, name: any, loop?: boolean): void;
390
- addAnimationByIndex(track_index: any, index: any, loop?: boolean, delay?: number): void;
475
+ draw(renderer: CanvasRenderer | WebGLRenderer): void;
476
+ /**
477
+ * Sets the current animation for a track, discarding any queued animations.
478
+ * @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
+ * @param {number} [index] - the animation index
480
+ * @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.
482
+ */
483
+ setAnimationByIndex(track_index?: number | undefined, index?: number | undefined, loop?: boolean | undefined): void;
484
+ /**
485
+ * Sets the current animation for a track, discarding any queued animations.
486
+ * @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
+ * @param {string} [name] - the animation name
488
+ * @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.
490
+ * @example
491
+ * // set the current animation
492
+ * spineAlien.setAnimation(0, "death", true);
493
+ */
494
+ setAnimation(track_index?: number | undefined, name?: string | undefined, loop?: boolean | undefined): void;
495
+ /**
496
+ * Adds an animation to be played after the current or last queued animation for a track, and sets the track entry's mixDuration.
497
+ * @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.
499
+ */
500
+ addAnimationByIndex(track_index: any, index: any, loop?: boolean, delay?: number | undefined): void;
391
501
  addAnimationByName(track_index: any, animationName: any, loop?: boolean, delay?: number): void;
392
502
  getSpinePosition(): Vector2d;
393
503
  setSpineSize(width: any, height: any): void;
504
+ width: any;
505
+ height: any;
394
506
  getSpineSize(): {
395
- width: number;
396
- height: number;
507
+ width: any;
508
+ height: any;
397
509
  };
398
- setDefaultMixTime(mixTime: any): void;
510
+ /**
511
+ * Set the default mix duration to use when no mix duration has been defined between two animations.
512
+ * @param {number} mixTime
513
+ */
514
+ setDefaultMixTime(mixTime: number): void;
515
+ /**
516
+ * Sets a mix duration by animation name.
517
+ */
399
518
  setTransitionMixTime(firstAnimation: any, secondAnimation: any, mixTime: any): void;
400
- setSkinByName(skinName: any): void;
519
+ /**
520
+ * Sets a skin by name.
521
+ * @param {string} skinName
522
+ * @example
523
+ * // create a new Spine Renderable
524
+ * let spineAlien = new Spine(100, 100, {atlasFile: "mix-and-match-pma.atlas", jsonFile: "mix-and-match-pro.json"});
525
+ *
526
+ * // set default animation
527
+ * spineAlien.setAnimation(0, "dance", true);
528
+ *
529
+ * // set default skin
530
+ * spineAlien.setSkinByName("full-skins/girl");
531
+ *
532
+ * // add it to the game world
533
+ * me.game.world.addChild(spineAlien);
534
+ */
535
+ setSkinByName(skinName: string): void;
536
+ /**
537
+ * Sets this slot to the setup pose.
538
+ */
401
539
  setToSetupPose(): void;
402
540
  }
541
+ /**
542
+ * @classdesc
543
+ * An Asset Manager class to load spine assets
544
+ */
403
545
  declare class AssetManager {
404
- constructor(pathPrefix?: string);
546
+ /**
547
+ * @param {string} [pathPrefix=""] - a default path prefix for assets location
548
+ */
549
+ constructor(pathPrefix?: string | undefined);
405
550
  asset_manager: any;
406
- pathPrefix: string;
407
- initAssetManager(): void;
408
- setPrefix(pathPrefix: any): void;
409
- loadAsset(atlas: any, skel: any): void;
551
+ pathPrefix: any;
552
+ /**
553
+ * set a default path prefix for assets location
554
+ * @see loadAsset
555
+ * @param {string} pathPrefix
556
+ */
557
+ setPrefix(pathPrefix: string): void;
558
+ /**
559
+ * define all spine assets to be loaded
560
+ * @see setPrefix
561
+ * @see loadAll
562
+ * @param {string} atlas
563
+ * @param {string} skel
564
+ * @example
565
+ * // load spine assets
566
+ * Spine.assetManager.setPrefix("data/spine/");
567
+ * Spine.assetManager.loadAsset("alien.atlas", "alien-ess.json");
568
+ * await Spine.assetManager.loadAll();
569
+ */
570
+ loadAsset(atlas: string, skel: string): void;
571
+ /**
572
+ * load all defined spine assets
573
+ * @see loadAsset
574
+ */
410
575
  loadAll(): any;
411
576
  }
412
- import { Renderable as Renderable$1 } from 'melonjs';
577
+ /******************************************************************************
578
+ * Spine Runtimes License Agreement
579
+ * Last updated July 28, 2023. Replaces all prior versions.
580
+ *
581
+ * Copyright (c) 2013-2023, Esoteric Software LLC
582
+ *
583
+ * Integration of the Spine Runtimes into software or otherwise creating
584
+ * derivative works of the Spine Runtimes is permitted under the terms and
585
+ * conditions of Section 2 of the Spine Editor License Agreement:
586
+ * http://esotericsoftware.com/spine-editor-license
587
+ *
588
+ * Otherwise, it is permitted to integrate the Spine Runtimes into software or
589
+ * otherwise create derivative works of the Spine Runtimes (collectively,
590
+ * "Products"), provided that each user of the Products must obtain their own
591
+ * Spine Editor license and redistribution of the Products in any form must
592
+ * include this license and copyright notice.
593
+ *
594
+ * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
595
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
596
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
597
+ * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
598
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
599
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
600
+ * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
601
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
602
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
603
+ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
604
+ *****************************************************************************/
605
+ declare class Renderable {
606
+ constructor(vertices: any, numVertices: any, numFloats: any);
607
+ vertices: any;
608
+ numVertices: any;
609
+ numFloats: any;
610
+ }
413
611
  /** Changes a bone's local {@link Bone#shearX} and {@link Bone#shearY}. */
414
612
  declare class AlphaTimeline extends CurveTimeline1 {
415
613
  slotIndex: any;
@@ -2213,9 +2411,10 @@ declare class PolygonBatcher {
2213
2411
  mesh: Mesh;
2214
2412
  srcColorBlend: any;
2215
2413
  srcAlphaBlend: any;
2216
- dstBlend: any;
2414
+ dstColorBlend: any;
2415
+ dstAlphaBlend: any;
2217
2416
  begin(shader: any): void;
2218
- setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstBlend: any): void;
2417
+ setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstColorBlend: any, dstAlphaBlend: any): void;
2219
2418
  draw(texture: any, vertices: any, indices: any): void;
2220
2419
  flush(): void;
2221
2420
  end(): void;
@@ -2582,9 +2781,10 @@ declare class ShapeRenderer {
2582
2781
  mesh: Mesh;
2583
2782
  srcColorBlend: any;
2584
2783
  srcAlphaBlend: any;
2585
- dstBlend: any;
2784
+ dstColorBlend: any;
2785
+ dstAlphaBlend: any;
2586
2786
  begin(shader: any): void;
2587
- setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstBlend: any): void;
2787
+ setBlendMode(srcColorBlend: any, srcAlphaBlend: any, dstColorBlend: any, dstAlphaBlend: any): void;
2588
2788
  setColor(color: any): void;
2589
2789
  setColorWith(r: any, g: any, b: any, a: any): void;
2590
2790
  point(x: any, y: any, color: any): void;
@@ -3150,40 +3350,6 @@ declare class SkeletonJson {
3150
3350
  readVertices(map: any, attachment: any, verticesLength: any): void;
3151
3351
  readAnimation(map: any, name: any, skeletonData: any): void;
3152
3352
  }
3153
- /******************************************************************************
3154
- * Spine Runtimes License Agreement
3155
- * Last updated July 28, 2023. Replaces all prior versions.
3156
- *
3157
- * Copyright (c) 2013-2023, Esoteric Software LLC
3158
- *
3159
- * Integration of the Spine Runtimes into software or otherwise creating
3160
- * derivative works of the Spine Runtimes is permitted under the terms and
3161
- * conditions of Section 2 of the Spine Editor License Agreement:
3162
- * http://esotericsoftware.com/spine-editor-license
3163
- *
3164
- * Otherwise, it is permitted to integrate the Spine Runtimes into software or
3165
- * otherwise create derivative works of the Spine Runtimes (collectively,
3166
- * "Products"), provided that each user of the Products must obtain their own
3167
- * Spine Editor license and redistribution of the Products in any form must
3168
- * include this license and copyright notice.
3169
- *
3170
- * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
3171
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3172
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3173
- * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
3174
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3175
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
3176
- * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
3177
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3178
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
3179
- * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3180
- *****************************************************************************/
3181
- declare class Renderable {
3182
- constructor(vertices: any, numVertices: any, numFloats: any);
3183
- vertices: any;
3184
- numVertices: any;
3185
- numFloats: any;
3186
- }
3187
3353
  declare class Vector2 {
3188
3354
  constructor(x?: number, y?: number);
3189
3355
  x: number;
@@ -4021,8 +4187,10 @@ declare class VertexAttribute {
4021
4187
  }
4022
4188
  declare class WebGLBlendModeConverter {
4023
4189
  static getDestGLBlendMode(blendMode: any): 1 | 771;
4190
+ static getDestColorGLBlendMode(blendMode: any): 1 | 769 | 771;
4191
+ static getDestAlphaGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 771;
4024
4192
  static getSourceColorGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 770 | 774;
4025
- static getSourceAlphaGLBlendMode(blendMode: any): 1 | 769 | 771;
4193
+ static getSourceAlphaGLBlendMode(blendMode: any, premultipliedAlpha?: boolean): 1 | 770;
4026
4194
  }
4027
4195
  declare class WindowedMean {
4028
4196
  constructor(windowSize?: number);