@melonjs/spine-plugin 1.4.0 → 2.0.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.
@@ -0,0 +1,320 @@
1
+ /**
2
+ * @classdesc
3
+ * A renderable object to render Spine animated skeleton.
4
+ * @augments Renderable
5
+ */
6
+ export default class Spine extends Renderable {
7
+ /**
8
+ * @param {number} x - the x coordinates of the Spine object
9
+ * @param {number} y - the y coordinates of the Spine object
10
+ * @param {object} settings - Configuration parameters for the Spine object
11
+ * @param {string} [settings.atlasFile] - the name of the atlasFile to be used to create this spine animation
12
+ * @param {string} [settings.jsonFile] - the name of the jsonFile to be used to create this spine animation
13
+ * @param {number} [settings.mixTime = 0.2] - the default mix duration to use when no mix duration has been defined between two animations.
14
+ * @example
15
+ * import Spine, { SpinePlugin } from '@melonjs/spine-plugin';
16
+ * import * as me from 'melonjs';
17
+ *
18
+ * // register the plugin
19
+ * me.plugin.register(SpinePlugin);
20
+ *
21
+ * // prepare/declare assets for the preloader
22
+ * const DataManifest = [
23
+ * {
24
+ * "name": "alien-ess.json",
25
+ * "type": "spine",
26
+ * "src": "data/spine/alien-ess.json"
27
+ * },
28
+ * {
29
+ * "name": "alien.atlas",
30
+ * "type": "spine",
31
+ * "src": "data/spine/alien.atlas"
32
+ * },
33
+ * ]
34
+ *
35
+ * // create a new Spine Renderable
36
+ * let spineAlien = new Spine(100, 100, {atlasFile: "alien.atlas", jsonFile: "alien-ess.json"});
37
+ *
38
+ * // set default animation
39
+ * spineAlien.setAnimation(0, "death", true);
40
+ *
41
+ * // add it to the game world
42
+ * me.game.world.addChild(spineAlien);
43
+ */
44
+ constructor(x: number, y: number, settings: {
45
+ atlasFile?: string | undefined;
46
+ jsonFile?: string | undefined;
47
+ mixTime?: number | undefined;
48
+ });
49
+ runtime: typeof spineWebGL | typeof spineCanvas;
50
+ skeleton: any;
51
+ plugin: plugin.BasePlugin;
52
+ renderer: import("melonjs").Renderer;
53
+ animationState: any;
54
+ skeletonRenderer: SkeletonRenderer | spineWebGL.SkeletonRenderer;
55
+ root: any;
56
+ boneOffset: spineCanvas.Vector2;
57
+ boneSize: spineCanvas.Vector2;
58
+ isSpineFlipped: {
59
+ x: boolean;
60
+ y: boolean;
61
+ };
62
+ /**
63
+ * Stores settings and other state for the playback of the current animation (if any).
64
+ * @type {TrackEntry}
65
+ * @see http://en.esotericsoftware.com/spine-api-reference#TrackEntry
66
+ * @see setAnimation
67
+ * @default undefined
68
+ * @example
69
+ * // set a default animation to "run"
70
+ * this.setAnimation(0, "run", true);
71
+ * ...
72
+ * ...
73
+ * // pause the animation
74
+ * this.currentTrack.timeScale = 0;
75
+ * ...
76
+ * ...
77
+ * // resume the animation
78
+ * this.currentTrack.timeScale = 1;
79
+ */
80
+ currentTrack: TrackEntry;
81
+ gl: any;
82
+ canvas: any;
83
+ context: import("melonjs").Renderer | undefined;
84
+ twoColorTint: boolean | undefined;
85
+ spineBatcher: any;
86
+ shapesShader: spineWebGL.Shader | undefined;
87
+ shapes: spineWebGL.ShapeRenderer | undefined;
88
+ skeletonDebugRenderer: spineWebGL.SkeletonDebugRenderer | undefined;
89
+ mixTime: number;
90
+ jsonFile: string | undefined;
91
+ atlasFile: string | undefined;
92
+ set debugRendering(value: boolean);
93
+ /**
94
+ * Whether to enable the debug mode when rendering the spine object
95
+ * @default false
96
+ * @type {boolean}
97
+ */
98
+ get debugRendering(): boolean;
99
+ /**
100
+ * Set and load the given skeleton atlas and json definition files.
101
+ * (use this if you did not specify any json or atlas through the constructor)
102
+ * @param {string} atlasFile - the name of the atlasFile to be used to create this spine animation
103
+ * @param {string} jsonFile - the name of the jsonFile to be used to create this spine animation
104
+ * @example
105
+ * // create a new Spine Renderable
106
+ * let spineAlien = new Spine(100, 100);
107
+ *
108
+ * // set the skeleton
109
+ * spineAlien.setSkeleton("alien.atlas", "alien-ess.json");
110
+ *
111
+ * // set default animation
112
+ * spineAlien.setAnimation(0, "death", true);
113
+ *
114
+ * // add it to the game world
115
+ * me.game.world.addChild(spineAlien);
116
+ */
117
+ setSkeleton(atlasFile: string, jsonFile: string): void;
118
+ /**
119
+ * Flip the Spine skeleton on the horizontal axis (around its center).
120
+ * @param {boolean} [flip=true] - `true` to flip this Spine object.
121
+ * @returns {Spine} Reference to this object for method chaining
122
+ */
123
+ flipX(flip?: boolean): Spine;
124
+ /**
125
+ * Flip the Spine skeleton on the vertical axis (around its center).
126
+ * @param {boolean} [flip=true] - `true` to flip this Spine object.
127
+ * @returns {Spine} Reference to this object for method chaining
128
+ */
129
+ flipY(flip?: boolean): Spine;
130
+ /**
131
+ * Rotate this Spine object by the specified angle (in radians).
132
+ * @param {number} angle - The angle to rotate (in radians)
133
+ * @param {Vector2d|ObservableVector2d} [v] - an optional point to rotate around
134
+ * @returns {Spine} Reference to this object for method chaining
135
+ */
136
+ rotate(angle: number, v?: Vector2d | ObservableVector2d): Spine;
137
+ /**
138
+ * Scale the Spine object around its anchor point.
139
+ * @param {number} x - a number representing the abscissa of the scaling vector.
140
+ * @param {number} [y=x] - a number representing the ordinate of the scaling vector.
141
+ * @returns {Spine} Reference to this object for method chaining
142
+ */
143
+ scale(x: number, y?: number): Spine;
144
+ /**
145
+ * Update the bounding box for this spine object.
146
+ * (this will automatically update the bounds of the entire skeleton animation)
147
+ * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
148
+ * @returns {Bounds} this shape bounding box Rectangle object
149
+ */
150
+ updateBounds(absolute?: boolean): Bounds;
151
+ /**
152
+ * Draw this Spine object using the appropriate renderer.
153
+ * If WebGL, it uses the melonJS SpineBatcher for two-color tinted rendering.
154
+ * Otherwise, it falls back to the canvas skeleton renderer.
155
+ *
156
+ * @param {CanvasRenderer|WebGLRenderer} renderer - A renderer instance.
157
+ */
158
+ draw(renderer: CanvasRenderer | WebGLRenderer): void;
159
+ /**
160
+ * Disposes of all rendering-related resources to free GPU memory.
161
+ * Called automatically when the renderable is removed from the world.
162
+ */
163
+ dispose(): void;
164
+ /**
165
+ * Sets the current animation for a track by animation index, discarding any queued animations.
166
+ * @param {number} trackIndex - the track index
167
+ * @param {number} index - the animation index
168
+ * @param {boolean} [loop=false] - If true, the animation will repeat.
169
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback.
170
+ */
171
+ setAnimationByIndex(trackIndex: number, index: number, loop?: boolean): TrackEntry;
172
+ /**
173
+ * Sets the current animation for a track, discarding any queued animations.
174
+ * @param {number} trackIndex - the track index
175
+ * @param {string} name - the animation name
176
+ * @param {boolean} [loop=false] - If true, the animation will repeat.
177
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback.
178
+ * @example
179
+ * // set the current animation
180
+ * spineAlien.setAnimation(0, "death", true);
181
+ */
182
+ setAnimation(trackIndex: number, name: string, loop?: boolean): TrackEntry;
183
+ /**
184
+ * Return true if the given animation name is the current running animation for the current track.
185
+ * @param {string} name - animation name
186
+ * @returns {boolean}
187
+ * @example
188
+ * if (!this.isCurrentAnimation("death")) {
189
+ * // do something funny...
190
+ * }
191
+ */
192
+ isCurrentAnimation(name: string): boolean;
193
+ /**
194
+ * Adds an animation to be played after the current or last queued animation for a track, by index.
195
+ * @param {number} trackIndex - the track index
196
+ * @param {number} index - the animation index
197
+ * @param {boolean} [loop=false] - If true, the animation will repeat.
198
+ * @param {number} [delay=0] - delay in seconds before playing the animation
199
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback.
200
+ */
201
+ addAnimationByIndex(trackIndex: number, index: number, loop?: boolean, delay?: number): TrackEntry;
202
+ /**
203
+ * Adds an animation to be played after the current or last queued animation for a track, by name.
204
+ * @param {number} trackIndex - the track index
205
+ * @param {string} name - the animation name
206
+ * @param {boolean} [loop=false] - If true, the animation will repeat.
207
+ * @param {number} [delay=0] - delay in seconds before playing the animation
208
+ * @returns {TrackEntry} A track entry to allow further customization of animation playback.
209
+ */
210
+ addAnimation(trackIndex: number, name: string, loop?: boolean, delay?: number): TrackEntry;
211
+ /**
212
+ * Set the default mix duration to use when no mix duration has been defined between two animations.
213
+ * @param {number} mixTime
214
+ */
215
+ setDefaultMixTime(mixTime: number): void;
216
+ /**
217
+ * Sets a mix duration between two animations by name.
218
+ * @param {string} firstAnimation - the name of the first animation
219
+ * @param {string} secondAnimation - the name of the second animation
220
+ * @param {number} mixTime - the mix duration in seconds
221
+ */
222
+ setTransitionMixTime(firstAnimation: string, secondAnimation: string, mixTime: number): void;
223
+ /**
224
+ * Sets a skin by name.
225
+ * @param {string} skinName
226
+ * @example
227
+ * // create a new Spine Renderable
228
+ * let spineChar = new Spine(100, 100, {atlasFile: "mix-and-match-pma.atlas", jsonFile: "mix-and-match-pro.json"});
229
+ *
230
+ * // set default animation
231
+ * spineChar.setAnimation(0, "dance", true);
232
+ *
233
+ * // set skin
234
+ * spineChar.setSkinByName("full-skins/girl");
235
+ *
236
+ * // add it to the game world
237
+ * me.game.world.addChild(spineChar);
238
+ */
239
+ setSkinByName(skinName: string): void;
240
+ /**
241
+ * Create a combined skin from multiple skin names (mix-and-match).
242
+ * @param {string} combinedName - name for the new combined skin
243
+ * @param {...string} skinNames - names of skins to combine
244
+ * @example
245
+ * // combine multiple skins for mix-and-match
246
+ * spineChar.setCombinedSkin("custom", "skin-base", "nose/short", "eyelids/girly");
247
+ */
248
+ setCombinedSkin(combinedName: string, ...skinNames: string[]): void;
249
+ /**
250
+ * Sets an empty animation for a track, allowing the track entry to be mixed from.
251
+ * @param {number} trackIndex - the track index
252
+ * @param {number} [mixDuration=0] - mix duration in seconds
253
+ * @returns {TrackEntry} A track entry to allow further customization.
254
+ */
255
+ setEmptyAnimation(trackIndex: number, mixDuration?: number): TrackEntry;
256
+ /**
257
+ * Find a bone by name.
258
+ * @param {string} boneName - the bone name
259
+ * @returns {Bone|null} the bone, or null if not found
260
+ */
261
+ findBone(boneName: string): Bone | null;
262
+ /**
263
+ * Find a slot by name.
264
+ * @param {string} slotName - the slot name
265
+ * @returns {Slot|null} the slot, or null if not found
266
+ */
267
+ findSlot(slotName: string): Slot | null;
268
+ /**
269
+ * Register a listener for animation state events.
270
+ * @param {object} listener - an object with event handler methods
271
+ * @param {Function} [listener.start] - called when an animation starts
272
+ * @param {Function} [listener.interrupt] - called when an animation is interrupted
273
+ * @param {Function} [listener.end] - called when an animation ends
274
+ * @param {Function} [listener.dispose] - called when a track entry is disposed
275
+ * @param {Function} [listener.complete] - called when an animation completes a loop
276
+ * @param {Function} [listener.event] - called when a user-defined event fires
277
+ * @example
278
+ * spineObj.addAnimationListener({
279
+ * complete: (entry) => {
280
+ * console.log("Animation complete:", entry.animation.name);
281
+ * },
282
+ * event: (entry, event) => {
283
+ * console.log("Event:", event.data.name);
284
+ * }
285
+ * });
286
+ */
287
+ addAnimationListener(listener: {
288
+ start?: Function | undefined;
289
+ interrupt?: Function | undefined;
290
+ end?: Function | undefined;
291
+ dispose?: Function | undefined;
292
+ complete?: Function | undefined;
293
+ event?: Function | undefined;
294
+ }): void;
295
+ /**
296
+ * Remove a previously registered animation state listener.
297
+ * @param {object} listener - the listener to remove
298
+ */
299
+ removeAnimationListener(listener: object): void;
300
+ /**
301
+ * Get the list of animation names available in this skeleton.
302
+ * @returns {string[]} array of animation names
303
+ */
304
+ getAnimationNames(): string[];
305
+ /**
306
+ * Get the list of skin names available in this skeleton.
307
+ * @returns {string[]} array of skin names
308
+ */
309
+ getSkinNames(): string[];
310
+ /**
311
+ * Reset this skeleton to the setup pose.
312
+ */
313
+ setToSetupPose(): void;
314
+ }
315
+ import { Renderable } from "melonjs";
316
+ import * as spineWebGL from "@esotericsoftware/spine-webgl";
317
+ import * as spineCanvas from "@esotericsoftware/spine-canvas";
318
+ import { plugin } from "melonjs";
319
+ import SkeletonRenderer from "./SkeletonRenderer.js";
320
+ //# sourceMappingURL=Spine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Spine.d.ts","sourceRoot":"","sources":["../src/Spine.js"],"names":[],"mappings":"AAWA;;;;GAIG;AACH;IAmCC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA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B;IAED;;;;;;;OAOG;IACH,yBANW,MAAM,QACN,MAAM,SACN,OAAO,UACP,MAAM,GACJ,UAAU,CAItB;IAED;;;OAGG;IACH,2BAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,qCAJW,MAAM,mBACN,MAAM,WACN,MAAM,QAIhB;IAED;;;;;;;;;;;;;;;OAeG;IACH,wBAdW,MAAM,QAgBhB;IAED;;;;;;;OAOG;IACH,8BANW,MAAM,gBACH,MAAM,EAAA,QAkBnB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,gBACN,MAAM,GACJ,UAAU,CAItB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAIrB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAIrB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,+BAhBG;QAA4B,KAAK;QACL,SAAS;QACT,GAAG;QACH,OAAO;QACP,QAAQ;QACR,KAAK;KACjC,QAYF;IAED;;;OAGG;IACH,kCAFW,MAAM,QAIhB;IAED;;;OAGG;IACH,qBAFa,MAAM,EAAE,CAMpB;IAED;;;OAGG;IACH,gBAFa,MAAM,EAAE,CAMpB;IAED;;OAEG;IACH,uBAYC;CACD;2BAnqBwC,SAAS;4BADtB,+BAA+B;6BAF9B,gCAAgC;uBAGpB,SAAS;6BACrB,uBAAuB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A custom melonJS Batcher for rendering Spine skeletons with two-color tinting.
3
+ * Uses Spine's official two-color shader and the base Batcher's indexed drawing support.
4
+ * @category Rendering
5
+ */
6
+ export default class SpineBatcher extends Batcher {
7
+ /**
8
+ * @param {WebGLRenderer} renderer - the current WebGL renderer session
9
+ * @param {WebGLRenderingContext|WebGL2RenderingContext} canvas - the GL context for Spine shader creation
10
+ */
11
+ constructor(renderer: WebGLRenderer, canvas: WebGLRenderingContext | WebGL2RenderingContext);
12
+ /**
13
+ * the current texture bound to the batcher
14
+ * @type {object|null}
15
+ * @ignore
16
+ */
17
+ lastTexture: object | null;
18
+ /**
19
+ * Set the blend mode for subsequent draw calls.
20
+ * Maps Spine BlendMode enum to melonJS blend mode strings.
21
+ * @param {number} blendMode - Spine BlendMode enum value (0=Normal, 1=Additive, 2=Multiply, 3=Screen)
22
+ * @param {boolean} premultipliedAlpha - whether textures use premultiplied alpha
23
+ */
24
+ setBlendMode(blendMode: number, premultipliedAlpha: boolean): void;
25
+ /**
26
+ * Draw Spine vertices with the given texture and triangle indices.
27
+ * This matches the Spine PolygonBatcher.draw() API.
28
+ * @param {object} texture - a Spine GLTexture object
29
+ * @param {ArrayLike<number>} vertices - interleaved vertex data
30
+ * @param {number[]} indices - triangle index array
31
+ */
32
+ draw(texture: object, vertices: ArrayLike<number>, indices: number[]): void;
33
+ }
34
+ import { Batcher } from "melonjs";
35
+ //# sourceMappingURL=SpineBatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpineBatcher.d.ts","sourceRoot":"","sources":["../src/SpineBatcher.js"],"names":[],"mappings":"AAcA;;;;GAIG;AACH;IACC;;;OAGG;IACH,sBAHW,aAAa,UACb,qBAAqB,GAAC,sBAAsB,EAuDtD;IANA;;;;OAIG;IACH,aAHU,MAAM,GAAC,IAAI,CAGE;IAGxB;;;;;OAKG;IACH,wBAHW,MAAM,sBACN,OAAO,QAOjB;IAED;;;;;;OAMG;IACH,cAJW,MAAM,YACN,SAAS,CAAC,MAAM,CAAC,WACjB,MAAM,EAAE,QAwBlB;CAaD;wBArIuB,SAAS"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @classdesc
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
+ import { plugin } from "melonjs";
11
+ import AssetManager from "./AssetManager";
12
+ //# sourceMappingURL=SpinePlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpinePlugin.d.ts","sourceRoot":"","sources":["../src/SpinePlugin.js"],"names":[],"mappings":"AAUA;;;;GAIG;AACH;IACC,cAcC;IADA,2BAAuD;CAExD;uBA/BsB,SAAS;yBAQP,gBAAgB"}
@@ -0,0 +1,3 @@
1
+ export { SpinePlugin } from "./SpinePlugin.js";
2
+ export { default, default as Spine } from "./Spine.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}