Skip to content

Commit 2ffe151

Browse files
committed
Rebuilt for latest Spine Runtimes
1 parent 1de2bb8 commit 2ffe151

11 files changed

Lines changed: 1814 additions & 1380 deletions

plugins/spine/dist/SpinePluginDebug.js

Lines changed: 1612 additions & 1280 deletions
Large diffs are not rendered by default.

plugins/spine/dist/SpinePluginDebug.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/spine/src/runtimes/spine-both.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ declare module spine {
636636
private queueAsset;
637637
loadText(clientId: string, path: string): void;
638638
loadJson(clientId: string, path: string): void;
639-
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string): void;
639+
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string): void;
640640
get(clientId: string, path: string): any;
641641
private updateClientAssets;
642642
isLoadingComplete(clientId: string): boolean;
@@ -881,9 +881,9 @@ declare module spine {
881881
}
882882
declare module spine {
883883
abstract class Texture {
884-
protected _image: HTMLImageElement;
885-
constructor(image: HTMLImageElement);
886-
getImage(): HTMLImageElement;
884+
protected _image: HTMLImageElement | ImageBitmap;
885+
constructor(image: HTMLImageElement | ImageBitmap);
886+
getImage(): HTMLImageElement | ImageBitmap;
887887
abstract setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
888888
abstract setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
889889
abstract dispose(): void;
@@ -1400,7 +1400,7 @@ declare module spine.webgl {
14001400
private boundUnit;
14011401
private useMipMaps;
14021402
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
1403-
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement, useMipMaps?: boolean);
1403+
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
14041404
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
14051405
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear;
14061406
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
@@ -1738,7 +1738,8 @@ declare module spine.webgl {
17381738
canvas: HTMLCanvasElement | OffscreenCanvas;
17391739
gl: WebGLRenderingContext;
17401740
private restorables;
1741-
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig?: any);
1741+
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext | EventTarget | WebGL2RenderingContext, contextConfig?: any);
1742+
private setupCanvas;
17421743
addRestorable(restorable: Restorable): void;
17431744
removeRestorable(restorable: Restorable): void;
17441745
}

plugins/spine/src/runtimes/spine-both.js

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,15 +3572,35 @@ var spine;
35723572
path = this.pathPrefix + path;
35733573
if (!this.queueAsset(clientId, textureLoader, path))
35743574
return;
3575-
var img = new Image();
3576-
img.crossOrigin = "anonymous";
3577-
img.onload = function (ev) {
3578-
_this.rawAssets[path] = img;
3579-
};
3580-
img.onerror = function (ev) {
3581-
_this.errors[path] = "Couldn't load image " + path;
3582-
};
3583-
img.src = path;
3575+
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
3576+
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
3577+
if (isWebWorker) {
3578+
var options = { mode: "cors" };
3579+
fetch(path, options).then(function (response) {
3580+
if (!response.ok) {
3581+
_this.errors[path] = "Couldn't load image " + path;
3582+
}
3583+
return response.blob();
3584+
}).then(function (blob) {
3585+
return createImageBitmap(blob, {
3586+
premultiplyAlpha: 'none',
3587+
colorSpaceConversion: 'none'
3588+
});
3589+
}).then(function (bitmap) {
3590+
_this.rawAssets[path] = bitmap;
3591+
});
3592+
}
3593+
else {
3594+
var img_1 = new Image();
3595+
img_1.crossOrigin = "anonymous";
3596+
img_1.onload = function (ev) {
3597+
_this.rawAssets[path] = img_1;
3598+
};
3599+
img_1.onerror = function (ev) {
3600+
_this.errors[path] = "Couldn't load image " + path;
3601+
};
3602+
img_1.src = path;
3603+
}
35843604
};
35853605
SharedAssetManager.prototype.get = function (clientId, path) {
35863606
path = this.pathPrefix + path;
@@ -3590,18 +3610,30 @@ var spine;
35903610
return clientAssets.assets[path];
35913611
};
35923612
SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
3613+
var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
3614+
var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
35933615
for (var i = 0; i < clientAssets.toLoad.length; i++) {
35943616
var path = clientAssets.toLoad[i];
35953617
var asset = clientAssets.assets[path];
35963618
if (asset === null || asset === undefined) {
35973619
var rawAsset = this.rawAssets[path];
35983620
if (rawAsset === null || rawAsset === undefined)
35993621
continue;
3600-
if (rawAsset instanceof HTMLImageElement) {
3601-
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3622+
if (isWebWorker) {
3623+
if (rawAsset instanceof ImageBitmap) {
3624+
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3625+
}
3626+
else {
3627+
clientAssets.assets[path] = rawAsset;
3628+
}
36023629
}
36033630
else {
3604-
clientAssets.assets[path] = rawAsset;
3631+
if (rawAsset instanceof HTMLImageElement) {
3632+
clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3633+
}
3634+
else {
3635+
clientAssets.assets[path] = rawAsset;
3636+
}
36053637
}
36063638
}
36073639
}
@@ -7749,7 +7781,7 @@ var spine;
77497781
return _this;
77507782
}
77517783
BoundingBoxAttachment.prototype.copy = function () {
7752-
var copy = new BoundingBoxAttachment(name);
7784+
var copy = new BoundingBoxAttachment(this.name);
77537785
this.copyTo(copy);
77547786
copy.color.setFromColor(this.color);
77557787
return copy;
@@ -7768,7 +7800,7 @@ var spine;
77687800
return _this;
77697801
}
77707802
ClippingAttachment.prototype.copy = function () {
7771-
var copy = new ClippingAttachment(name);
7803+
var copy = new ClippingAttachment(this.name);
77727804
this.copyTo(copy);
77737805
copy.endSlot = this.endSlot;
77747806
copy.color.setFromColor(this.color);
@@ -7912,7 +7944,7 @@ var spine;
79127944
return _this;
79137945
}
79147946
PathAttachment.prototype.copy = function () {
7915-
var copy = new PathAttachment(name);
7947+
var copy = new PathAttachment(this.name);
79167948
this.copyTo(copy);
79177949
copy.lengths = new Array(this.lengths.length);
79187950
spine.Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
@@ -7946,7 +7978,7 @@ var spine;
79467978
return Math.atan2(y, x) * spine.MathUtils.radDeg;
79477979
};
79487980
PointAttachment.prototype.copy = function () {
7949-
var copy = new PointAttachment(name);
7981+
var copy = new PointAttachment(this.name);
79507982
copy.x = this.x;
79517983
copy.y = this.y;
79527984
copy.rotation = this.rotation;
@@ -10706,30 +10738,32 @@ var spine;
1070610738
(function (webgl) {
1070710739
var ManagedWebGLRenderingContext = (function () {
1070810740
function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
10709-
var _this = this;
1071010741
if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
1071110742
this.restorables = new Array();
10712-
if (canvasOrContext instanceof HTMLCanvasElement) {
10713-
var canvas_1 = canvasOrContext;
10714-
this.gl = (canvas_1.getContext("webgl2", contextConfig) || canvas_1.getContext("webgl", contextConfig));
10715-
this.canvas = canvas_1;
10716-
canvas_1.addEventListener("webglcontextlost", function (e) {
10717-
var event = e;
10718-
if (e) {
10719-
e.preventDefault();
10720-
}
10721-
});
10722-
canvas_1.addEventListener("webglcontextrestored", function (e) {
10723-
for (var i = 0, n = _this.restorables.length; i < n; i++) {
10724-
_this.restorables[i].restore();
10725-
}
10726-
});
10743+
if (canvasOrContext instanceof HTMLCanvasElement || canvasOrContext instanceof EventTarget) {
10744+
this.setupCanvas(canvasOrContext, contextConfig);
1072710745
}
1072810746
else {
1072910747
this.gl = canvasOrContext;
1073010748
this.canvas = this.gl.canvas;
1073110749
}
1073210750
}
10751+
ManagedWebGLRenderingContext.prototype.setupCanvas = function (canvas, contextConfig) {
10752+
var _this = this;
10753+
this.gl = (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
10754+
this.canvas = canvas;
10755+
canvas.addEventListener("webglcontextlost", function (e) {
10756+
var event = e;
10757+
if (e) {
10758+
e.preventDefault();
10759+
}
10760+
});
10761+
canvas.addEventListener("webglcontextrestored", function (e) {
10762+
for (var i = 0, n = _this.restorables.length; i < n; i++) {
10763+
_this.restorables[i].restore();
10764+
}
10765+
});
10766+
};
1073310767
ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
1073410768
this.restorables.push(restorable);
1073510769
};

plugins/spine/src/runtimes/spine-both.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/spine/src/runtimes/spine-canvas.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ declare module spine {
636636
private queueAsset;
637637
loadText(clientId: string, path: string): void;
638638
loadJson(clientId: string, path: string): void;
639-
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string): void;
639+
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string): void;
640640
get(clientId: string, path: string): any;
641641
private updateClientAssets;
642642
isLoadingComplete(clientId: string): boolean;
@@ -881,9 +881,9 @@ declare module spine {
881881
}
882882
declare module spine {
883883
abstract class Texture {
884-
protected _image: HTMLImageElement;
885-
constructor(image: HTMLImageElement);
886-
getImage(): HTMLImageElement;
884+
protected _image: HTMLImageElement | ImageBitmap;
885+
constructor(image: HTMLImageElement | ImageBitmap);
886+
getImage(): HTMLImageElement | ImageBitmap;
887887
abstract setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
888888
abstract setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
889889
abstract dispose(): void;

plugins/spine/src/runtimes/spine-canvas.js

Lines changed: 48 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/spine/src/runtimes/spine-canvas.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/spine/src/runtimes/spine-webgl.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ declare module spine {
636636
private queueAsset;
637637
loadText(clientId: string, path: string): void;
638638
loadJson(clientId: string, path: string): void;
639-
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement) => any, path: string): void;
639+
loadTexture(clientId: string, textureLoader: (image: HTMLImageElement | ImageBitmap) => any, path: string): void;
640640
get(clientId: string, path: string): any;
641641
private updateClientAssets;
642642
isLoadingComplete(clientId: string): boolean;
@@ -881,9 +881,9 @@ declare module spine {
881881
}
882882
declare module spine {
883883
abstract class Texture {
884-
protected _image: HTMLImageElement;
885-
constructor(image: HTMLImageElement);
886-
getImage(): HTMLImageElement;
884+
protected _image: HTMLImageElement | ImageBitmap;
885+
constructor(image: HTMLImageElement | ImageBitmap);
886+
getImage(): HTMLImageElement | ImageBitmap;
887887
abstract setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
888888
abstract setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
889889
abstract dispose(): void;
@@ -1369,7 +1369,7 @@ declare module spine.webgl {
13691369
private boundUnit;
13701370
private useMipMaps;
13711371
static DISABLE_UNPACK_PREMULTIPLIED_ALPHA_WEBGL: boolean;
1372-
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement, useMipMaps?: boolean);
1372+
constructor(context: ManagedWebGLRenderingContext | WebGLRenderingContext, image: HTMLImageElement | ImageBitmap, useMipMaps?: boolean);
13731373
setFilters(minFilter: TextureFilter, magFilter: TextureFilter): void;
13741374
static validateMagFilter(magFilter: TextureFilter): TextureFilter.Nearest | TextureFilter.Linear | TextureFilter.Linear;
13751375
setWraps(uWrap: TextureWrap, vWrap: TextureWrap): void;
@@ -1707,7 +1707,8 @@ declare module spine.webgl {
17071707
canvas: HTMLCanvasElement | OffscreenCanvas;
17081708
gl: WebGLRenderingContext;
17091709
private restorables;
1710-
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext, contextConfig?: any);
1710+
constructor(canvasOrContext: HTMLCanvasElement | WebGLRenderingContext | EventTarget | WebGL2RenderingContext, contextConfig?: any);
1711+
private setupCanvas;
17111712
addRestorable(restorable: Restorable): void;
17121713
removeRestorable(restorable: Restorable): void;
17131714
}

0 commit comments

Comments
 (0)