@esotericsoftware/spine-canvas 4.2.83 → 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.
|
@@ -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,
|
|
@@ -4927,7 +4928,7 @@ var spine = (() => {
|
|
|
4927
4928
|
this.copyTo(copy);
|
|
4928
4929
|
copy.regionUVs = new Array(this.regionUVs.length);
|
|
4929
4930
|
Utils.arrayCopy(this.regionUVs, 0, copy.regionUVs, 0, this.regionUVs.length);
|
|
4930
|
-
copy.uvs = new Array(this.uvs.length);
|
|
4931
|
+
copy.uvs = this.uvs instanceof Float32Array ? Utils.newFloatArray(this.uvs.length) : new Array(this.uvs.length);
|
|
4931
4932
|
Utils.arrayCopy(this.uvs, 0, copy.uvs, 0, this.uvs.length);
|
|
4932
4933
|
copy.triangles = new Array(this.triangles.length);
|
|
4933
4934
|
Utils.arrayCopy(this.triangles, 0, copy.triangles, 0, this.triangles.length);
|
|
@@ -5668,16 +5669,15 @@ var spine = (() => {
|
|
|
5668
5669
|
pathPrefix = "";
|
|
5669
5670
|
textureLoader;
|
|
5670
5671
|
downloader;
|
|
5671
|
-
|
|
5672
|
-
assetsRefCount = {};
|
|
5673
|
-
assetsLoaded = {};
|
|
5672
|
+
cache;
|
|
5674
5673
|
errors = {};
|
|
5675
5674
|
toLoad = 0;
|
|
5676
5675
|
loaded = 0;
|
|
5677
|
-
constructor(textureLoader, pathPrefix = "", downloader = new Downloader()) {
|
|
5676
|
+
constructor(textureLoader, pathPrefix = "", downloader = new Downloader(), cache = new AssetCache()) {
|
|
5678
5677
|
this.textureLoader = textureLoader;
|
|
5679
5678
|
this.pathPrefix = pathPrefix;
|
|
5680
5679
|
this.downloader = downloader;
|
|
5680
|
+
this.cache = cache;
|
|
5681
5681
|
}
|
|
5682
5682
|
start(path) {
|
|
5683
5683
|
this.toLoad++;
|
|
@@ -5686,8 +5686,8 @@ var spine = (() => {
|
|
|
5686
5686
|
success(callback, path, asset) {
|
|
5687
5687
|
this.toLoad--;
|
|
5688
5688
|
this.loaded++;
|
|
5689
|
-
this.assets[path] = asset;
|
|
5690
|
-
this.assetsRefCount[path] = (this.assetsRefCount[path] || 0) + 1;
|
|
5689
|
+
this.cache.assets[path] = asset;
|
|
5690
|
+
this.cache.assetsRefCount[path] = (this.cache.assetsRefCount[path] || 0) + 1;
|
|
5691
5691
|
if (callback) callback(path, asset);
|
|
5692
5692
|
}
|
|
5693
5693
|
error(callback, path, message) {
|
|
@@ -5718,7 +5718,7 @@ var spine = (() => {
|
|
|
5718
5718
|
}) {
|
|
5719
5719
|
path = this.start(path);
|
|
5720
5720
|
if (this.reuseAssets(path, success, error)) return;
|
|
5721
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5721
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5722
5722
|
this.downloader.downloadBinary(path, (data) => {
|
|
5723
5723
|
this.success(success, path, data);
|
|
5724
5724
|
resolve(data);
|
|
@@ -5744,7 +5744,7 @@ var spine = (() => {
|
|
|
5744
5744
|
}) {
|
|
5745
5745
|
path = this.start(path);
|
|
5746
5746
|
if (this.reuseAssets(path, success, error)) return;
|
|
5747
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5747
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5748
5748
|
this.downloader.downloadJson(path, (data) => {
|
|
5749
5749
|
this.success(success, path, data);
|
|
5750
5750
|
resolve(data);
|
|
@@ -5758,10 +5758,14 @@ var spine = (() => {
|
|
|
5758
5758
|
reuseAssets(path, success = () => {
|
|
5759
5759
|
}, error = () => {
|
|
5760
5760
|
}) {
|
|
5761
|
-
const loadedStatus = this.assetsLoaded[path];
|
|
5761
|
+
const loadedStatus = this.cache.assetsLoaded[path];
|
|
5762
5762
|
const alreadyExistsOrLoading = loadedStatus !== void 0;
|
|
5763
5763
|
if (alreadyExistsOrLoading) {
|
|
5764
|
-
|
|
5764
|
+
this.cache.assetsLoaded[path] = loadedStatus.then((data) => {
|
|
5765
|
+
data = data instanceof Image || data instanceof ImageBitmap ? this.textureLoader(data) : data;
|
|
5766
|
+
this.success(success, path, data);
|
|
5767
|
+
return data;
|
|
5768
|
+
}).catch((errorMsg) => this.error(error, path, errorMsg));
|
|
5765
5769
|
}
|
|
5766
5770
|
return alreadyExistsOrLoading;
|
|
5767
5771
|
}
|
|
@@ -5770,7 +5774,7 @@ var spine = (() => {
|
|
|
5770
5774
|
}) {
|
|
5771
5775
|
path = this.start(path);
|
|
5772
5776
|
if (this.reuseAssets(path, success, error)) return;
|
|
5773
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5777
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5774
5778
|
let isBrowser = !!(typeof window !== "undefined" && typeof navigator !== "undefined" && window.document);
|
|
5775
5779
|
let isWebWorker = !isBrowser;
|
|
5776
5780
|
if (isWebWorker) {
|
|
@@ -5814,7 +5818,7 @@ var spine = (() => {
|
|
|
5814
5818
|
let parent = index >= 0 ? path.substring(0, index + 1) : "";
|
|
5815
5819
|
path = this.start(path);
|
|
5816
5820
|
if (this.reuseAssets(path, success, error)) return;
|
|
5817
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5821
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5818
5822
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5819
5823
|
try {
|
|
5820
5824
|
let atlas = new TextureAtlas(atlasText);
|
|
@@ -5833,7 +5837,7 @@ var spine = (() => {
|
|
|
5833
5837
|
},
|
|
5834
5838
|
(imagePath, message) => {
|
|
5835
5839
|
if (!abort) {
|
|
5836
|
-
const errorMsg = `Couldn't load texture
|
|
5840
|
+
const errorMsg = `Couldn't load texture ${path} page image: ${imagePath}`;
|
|
5837
5841
|
this.error(error, path, errorMsg);
|
|
5838
5842
|
reject(errorMsg);
|
|
5839
5843
|
}
|
|
@@ -5858,7 +5862,7 @@ var spine = (() => {
|
|
|
5858
5862
|
}, fileAlias) {
|
|
5859
5863
|
path = this.start(path);
|
|
5860
5864
|
if (this.reuseAssets(path, success, error)) return;
|
|
5861
|
-
this.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5865
|
+
this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
|
|
5862
5866
|
this.downloader.downloadText(path, (atlasText) => {
|
|
5863
5867
|
try {
|
|
5864
5868
|
const atlas = new TextureAtlas(atlasText);
|
|
@@ -5922,33 +5926,36 @@ var spine = (() => {
|
|
|
5922
5926
|
);
|
|
5923
5927
|
});
|
|
5924
5928
|
}
|
|
5929
|
+
setCache(cache) {
|
|
5930
|
+
this.cache = cache;
|
|
5931
|
+
}
|
|
5925
5932
|
get(path) {
|
|
5926
|
-
return this.assets[this.pathPrefix + path];
|
|
5933
|
+
return this.cache.assets[this.pathPrefix + path];
|
|
5927
5934
|
}
|
|
5928
5935
|
require(path) {
|
|
5929
5936
|
path = this.pathPrefix + path;
|
|
5930
|
-
let asset = this.assets[path];
|
|
5937
|
+
let asset = this.cache.assets[path];
|
|
5931
5938
|
if (asset) return asset;
|
|
5932
5939
|
let error = this.errors[path];
|
|
5933
5940
|
throw Error("Asset not found: " + path + (error ? "\n" + error : ""));
|
|
5934
5941
|
}
|
|
5935
5942
|
remove(path) {
|
|
5936
5943
|
path = this.pathPrefix + path;
|
|
5937
|
-
let asset = this.assets[path];
|
|
5944
|
+
let asset = this.cache.assets[path];
|
|
5938
5945
|
if (asset.dispose) asset.dispose();
|
|
5939
|
-
delete this.assets[path];
|
|
5940
|
-
delete this.assetsRefCount[path];
|
|
5941
|
-
delete this.assetsLoaded[path];
|
|
5946
|
+
delete this.cache.assets[path];
|
|
5947
|
+
delete this.cache.assetsRefCount[path];
|
|
5948
|
+
delete this.cache.assetsLoaded[path];
|
|
5942
5949
|
return asset;
|
|
5943
5950
|
}
|
|
5944
5951
|
removeAll() {
|
|
5945
|
-
for (let path in this.assets) {
|
|
5946
|
-
let asset = this.assets[path];
|
|
5952
|
+
for (let path in this.cache.assets) {
|
|
5953
|
+
let asset = this.cache.assets[path];
|
|
5947
5954
|
if (asset.dispose) asset.dispose();
|
|
5948
5955
|
}
|
|
5949
|
-
this.assets = {};
|
|
5950
|
-
this.assetsLoaded = {};
|
|
5951
|
-
this.assetsRefCount = {};
|
|
5956
|
+
this.cache.assets = {};
|
|
5957
|
+
this.cache.assetsLoaded = {};
|
|
5958
|
+
this.cache.assetsRefCount = {};
|
|
5952
5959
|
}
|
|
5953
5960
|
isLoadingComplete() {
|
|
5954
5961
|
return this.toLoad == 0;
|
|
@@ -5964,7 +5971,7 @@ var spine = (() => {
|
|
|
5964
5971
|
}
|
|
5965
5972
|
// dispose asset only if it's not used by others
|
|
5966
5973
|
disposeAsset(path) {
|
|
5967
|
-
if (--this.assetsRefCount[path] === 0) {
|
|
5974
|
+
if (--this.cache.assetsRefCount[path] === 0) {
|
|
5968
5975
|
this.remove(path);
|
|
5969
5976
|
}
|
|
5970
5977
|
}
|
|
@@ -5975,6 +5982,23 @@ var spine = (() => {
|
|
|
5975
5982
|
return this.errors;
|
|
5976
5983
|
}
|
|
5977
5984
|
};
|
|
5985
|
+
var AssetCache = class _AssetCache {
|
|
5986
|
+
assets = {};
|
|
5987
|
+
assetsRefCount = {};
|
|
5988
|
+
assetsLoaded = {};
|
|
5989
|
+
static AVAILABLE_CACHES = /* @__PURE__ */ new Map();
|
|
5990
|
+
static getCache(id) {
|
|
5991
|
+
const cache = _AssetCache.AVAILABLE_CACHES.get(id);
|
|
5992
|
+
if (cache) return cache;
|
|
5993
|
+
const newCache = new _AssetCache();
|
|
5994
|
+
_AssetCache.AVAILABLE_CACHES.set(id, newCache);
|
|
5995
|
+
return newCache;
|
|
5996
|
+
}
|
|
5997
|
+
async addAsset(path, asset) {
|
|
5998
|
+
this.assetsLoaded[path] = Promise.resolve(asset);
|
|
5999
|
+
this.assets[path] = await asset;
|
|
6000
|
+
}
|
|
6001
|
+
};
|
|
5978
6002
|
var Downloader = class {
|
|
5979
6003
|
callbacks = {};
|
|
5980
6004
|
rawDataUris = {};
|