@esotericsoftware/spine-webgl 4.2.84 → 4.2.85
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/AssetManager.js +1 -1
- package/dist/WebGL.js +1 -1
- package/dist/esm/spine-webgl.min.mjs +3 -3
- package/dist/esm/spine-webgl.mjs +50 -26
- package/dist/esm/spine-webgl.mjs.map +2 -2
- package/dist/iife/spine-webgl.js +50 -26
- package/dist/iife/spine-webgl.js.map +2 -2
- package/dist/iife/spine-webgl.min.js +3 -3
- package/package.json +2 -2
package/dist/iife/spine-webgl.js
CHANGED
|
@@ -26,6 +26,7 @@ var spine = (() => {
|
|
|
26
26
|
AnimationState: () => AnimationState,
|
|
27
27
|
AnimationStateAdapter: () => AnimationStateAdapter,
|
|
28
28
|
AnimationStateData: () => AnimationStateData,
|
|
29
|
+
AssetCache: () => AssetCache,
|
|
29
30
|
AssetManager: () => AssetManager,
|
|
30
31
|
AssetManagerBase: () => AssetManagerBase,
|
|
31
32
|
AtlasAttachmentLoader: () => AtlasAttachmentLoader,
|
|
@@ -5708,16 +5709,15 @@ var spine = (() => {
|
|
|
5708
5709
|
pathPrefix = "";
|
|
5709
5710
|
textureLoader;
|
|
5710
5711
|
downloader;
|
|
5711
|
-
|
|
5712
|
-
assetsRefCount = {};
|
|
5713
|
-
assetsLoaded = {};
|
|
5712
|
+
cache;
|
|
5714
5713
|
errors = {};
|
|
5715
5714
|
toLoad = 0;
|
|
5716
5715
|
loaded = 0;
|
|
5717
|
-
constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
|
|
5716
|
+
constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) {
|
|
5718
5717
|
this.textureLoader = textureLoader;
|
|
5719
5718
|
this.pathPrefix = pathPrefix;
|
|
5720
5719
|
this.downloader = downloader;
|
|
5720
|
+
this.cache = cache;
|
|
5721
5721
|
}
|
|
5722
5722
|
start(path) {
|
|
5723
5723
|
this.toLoad++;
|
|
@@ -5726,8 +5726,8 @@ var spine = (() => {
|
|
|
5726
5726
|
success(callback, path, asset) {
|
|
5727
5727
|
this.toLoad--;
|
|
5728
5728
|
this.loaded++;
|
|
5729
|
-
this.assets[path] = asset;
|
|
5730
|
-
this.assetsRefCount[path] = (this.assetsRefCount[path] || 0) + 1;
|
|
5729
|
+
this.cache.assets[path] = asset;
|
|
5730
|
+
this.cache.assetsRefCount[path] = (this.cache.assetsRefCount[path] || 0) + 1;
|
|
5731
5731
|
if (callback) callback(path, asset);
|
|
5732
5732
|
}
|
|
5733
5733
|
error(callback, path, message) {
|
|
@@ -5758,7 +5758,7 @@ var spine = (() => {
|
|
|
5758
5758
|
}) {
|
|
5759
5759
|
path = this.start(path);
|
|
5760
5760
|
if (this.reuseAssets(path, success, error)) return;
|
|
5761
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5761
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5762
5762
|
this.downloader.downloadBinary(path, (data) => {
|
|
5763
5763
|
this.success(success, path, data);
|
|
5764
5764
|
resolve(data);
|
|
@@ -5784,7 +5784,7 @@ var spine = (() => {
|
|
|
5784
5784
|
}) {
|
|
5785
5785
|
path = this.start(path);
|
|
5786
5786
|
if (this.reuseAssets(path, success, error)) return;
|
|
5787
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5787
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5788
5788
|
this.downloader.downloadJson(path, (data) => {
|
|
5789
5789
|
this.success(success, path, data);
|
|
5790
5790
|
resolve(data);
|
|
@@ -5798,10 +5798,14 @@ var spine = (() => {
|
|
|
5798
5798
|
reuseAssets(path, success = () => {
|
|
5799
5799
|
}, error = () => {
|
|
5800
5800
|
}) {
|
|
5801
|
-
const loadedStatus = this.assetsLoaded[path];
|
|
5801
|
+
const loadedStatus = this.cache.assetsLoaded[path];
|
|
5802
5802
|
const alreadyExistsOrLoading = loadedStatus !== void 0;
|
|
5803
5803
|
if (alreadyExistsOrLoading) {
|
|
5804
|
-
|
|
5804
|
+
this.cache.assetsLoaded[path] = loadedStatus.then((data) => {
|
|
5805
|
+
data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data;
|
|
5806
|
+
this.success(success, path, data);
|
|
5807
|
+
return data;
|
|
5808
|
+
}).catch((errorMsg) => this.error(error, path, errorMsg));
|
|
5805
5809
|
}
|
|
5806
5810
|
return alreadyExistsOrLoading;
|
|
5807
5811
|
}
|
|
@@ -5810,7 +5814,7 @@ var spine = (() => {
|
|
|
5810
5814
|
}) {
|
|
5811
5815
|
path = this.start(path);
|
|
5812
5816
|
if (this.reuseAssets(path, success, error)) return;
|
|
5813
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5817
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5814
5818
|
let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
|
|
5815
5819
|
let isWebWorker = !isBrowser;
|
|
5816
5820
|
if (isWebWorker) {
|
|
@@ -5854,7 +5858,7 @@ var spine = (() => {
|
|
|
5854
5858
|
let parent = index >= 0 ? path.substring(0, index + 1) : "";
|
|
5855
5859
|
path = this.start(path);
|
|
5856
5860
|
if (this.reuseAssets(path, success, error)) return;
|
|
5857
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5861
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5858
5862
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5859
5863
|
try {
|
|
5860
5864
|
let atlas = new TextureAtlas(atlasText);
|
|
@@ -5873,7 +5877,7 @@ var spine = (() => {
|
|
|
5873
5877
|
},
|
|
5874
5878
|
(imagePath, message) => {
|
|
5875
5879
|
if (!abort) {
|
|
5876
|
-
const errorMsg = `Couldn't load texture
|
|
5880
|
+
const errorMsg = `Couldn't load texture ${path} page image: ${imagePath}`;
|
|
5877
5881
|
this.error(error, path, errorMsg);
|
|
5878
5882
|
reject(errorMsg);
|
|
5879
5883
|
}
|
|
@@ -5898,7 +5902,7 @@ var spine = (() => {
|
|
|
5898
5902
|
}, fileAlias) {
|
|
5899
5903
|
path = this.start(path);
|
|
5900
5904
|
if (this.reuseAssets(path, success, error)) return;
|
|
5901
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5905
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5902
5906
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5903
5907
|
try {
|
|
5904
5908
|
const atlas = new TextureAtlas(atlasText);
|
|
@@ -5962,33 +5966,36 @@ var spine = (() => {
|
|
|
5962
5966
|
);
|
|
5963
5967
|
});
|
|
5964
5968
|
}
|
|
5969
|
+
setCache(cache) {
|
|
5970
|
+
this.cache = cache;
|
|
5971
|
+
}
|
|
5965
5972
|
get(path) {
|
|
5966
|
-
return this.assets[this.pathPrefix + path];
|
|
5973
|
+
return this.cache.assets[this.pathPrefix + path];
|
|
5967
5974
|
}
|
|
5968
5975
|
require(path) {
|
|
5969
5976
|
path = this.pathPrefix + path;
|
|
5970
|
-
let asset = this.assets[path];
|
|
5977
|
+
let asset = this.cache.assets[path];
|
|
5971
5978
|
if (asset) return asset;
|
|
5972
5979
|
let error = this.errors[path];
|
|
5973
5980
|
throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
|
|
5974
5981
|
}
|
|
5975
5982
|
remove(path) {
|
|
5976
5983
|
path = this.pathPrefix + path;
|
|
5977
|
-
let asset = this.assets[path];
|
|
5984
|
+
let asset = this.cache.assets[path];
|
|
5978
5985
|
if (asset.dispose) asset.dispose();
|
|
5979
|
-
delete this.assets[path];
|
|
5980
|
-
delete this.assetsRefCount[path];
|
|
5981
|
-
delete this.assetsLoaded[path];
|
|
5986
|
+
delete this.cache.assets[path];
|
|
5987
|
+
delete this.cache.assetsRefCount[path];
|
|
5988
|
+
delete this.cache.assetsLoaded[path];
|
|
5982
5989
|
return asset;
|
|
5983
5990
|
}
|
|
5984
5991
|
removeAll() {
|
|
5985
|
-
for (let path in this.assets) {
|
|
5986
|
-
let asset = this.assets[path];
|
|
5992
|
+
for (let path in this.cache.assets) {
|
|
5993
|
+
let asset = this.cache.assets[path];
|
|
5987
5994
|
if (asset.dispose) asset.dispose();
|
|
5988
5995
|
}
|
|
5989
|
-
this.assets = {};
|
|
5990
|
-
this.assetsLoaded = {};
|
|
5991
|
-
this.assetsRefCount = {};
|
|
5996
|
+
this.cache.assets = {};
|
|
5997
|
+
this.cache.assetsLoaded = {};
|
|
5998
|
+
this.cache.assetsRefCount = {};
|
|
5992
5999
|
}
|
|
5993
6000
|
isLoadingComplete() {
|
|
5994
6001
|
return this.toLoad == 0;
|
|
@@ -6004,7 +6011,7 @@ var spine = (() => {
|
|
|
6004
6011
|
}
|
|
6005
6012
|
// dispose asset only if it's not used by others
|
|
6006
6013
|
disposeAsset(path) {
|
|
6007
|
-
if (--this.assetsRefCount[path] === 0) {
|
|
6014
|
+
if (--this.cache.assetsRefCount[path] === 0) {
|
|
6008
6015
|
this.remove(path);
|
|
6009
6016
|
}
|
|
6010
6017
|
}
|
|
@@ -6015,6 +6022,23 @@ var spine = (() => {
|
|
|
6015
6022
|
return this.errors;
|
|
6016
6023
|
}
|
|
6017
6024
|
};
|
|
6025
|
+
var AssetCache = class _AssetCache {
|
|
6026
|
+
assets = {};
|
|
6027
|
+
assetsRefCount = {};
|
|
6028
|
+
assetsLoaded = {};
|
|
6029
|
+
static AVAILABLE_CACHES = /* @__PURE__ */ new Map();
|
|
6030
|
+
static getCache(id) {
|
|
6031
|
+
const cache = _AssetCache.AVAILABLE_CACHES.get(id);
|
|
6032
|
+
if (cache) return cache;
|
|
6033
|
+
const newCache = new _AssetCache();
|
|
6034
|
+
_AssetCache.AVAILABLE_CACHES.set(id, newCache);
|
|
6035
|
+
return newCache;
|
|
6036
|
+
}
|
|
6037
|
+
async addAsset(path, asset) {
|
|
6038
|
+
this.assetsLoaded[path] = Promise.resolve(asset);
|
|
6039
|
+
this.assets[path] = await asset;
|
|
6040
|
+
}
|
|
6041
|
+
};
|
|
6018
6042
|
var Downloader = class {
|
|
6019
6043
|
callbacks = {};
|
|
6020
6044
|
rawDataUris = {};
|