@urso/core 0.7.34 → 0.7.35
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/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/lib/cache.js +17 -10
- package/src/js/lib/loader.js +24 -5
package/package.json
CHANGED
package/src/js/lib/cache.js
CHANGED
|
@@ -15,45 +15,52 @@ class LibCache {
|
|
|
15
15
|
this.globalAtlas = new PIXI.spine.TextureAtlas();
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
_setDataToAssetsList(assetType, key, data) {
|
|
19
|
+
if (this.assetsList[assetType][key])
|
|
20
|
+
console.warn(`LibCache ${assetType}: key alredy exists: `, key, data);
|
|
21
|
+
|
|
22
|
+
this.assetsList[assetType][key] = someData;
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
addFile(key, someData) {
|
|
19
|
-
this.
|
|
26
|
+
this._setDataToAssetsList('file', key, someData);
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
addAtlas(key, someData) {
|
|
23
|
-
this.
|
|
30
|
+
this._setDataToAssetsList('atlas', key, someData);
|
|
24
31
|
};
|
|
25
32
|
|
|
26
33
|
addBinary(key, someData) {
|
|
27
|
-
this.
|
|
34
|
+
this._setDataToAssetsList('binary', key, someData);
|
|
28
35
|
};
|
|
29
36
|
|
|
30
37
|
addBitmapFont(key, someData) {
|
|
31
|
-
this.
|
|
38
|
+
this._setDataToAssetsList('bitmapFont', key, someData);
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
addContainer(key, someData) {
|
|
35
|
-
this.
|
|
42
|
+
this._setDataToAssetsList('container', key, someData);
|
|
36
43
|
};
|
|
37
44
|
|
|
38
45
|
addImage(key, someData) {
|
|
39
|
-
this.
|
|
46
|
+
this._setDataToAssetsList('image', key, someData);
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
addJson(key, someData) {
|
|
43
|
-
this.
|
|
50
|
+
this._setDataToAssetsList('json', key, someData);
|
|
44
51
|
};
|
|
45
52
|
|
|
46
53
|
addSound(key, someData) {
|
|
47
|
-
this.
|
|
54
|
+
this._setDataToAssetsList('sound', key, someData);
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
addTexture(key, someData) {
|
|
51
|
-
this.
|
|
58
|
+
this._setDataToAssetsList('texture', key, someData);
|
|
52
59
|
this.globalAtlas.addTexture(key, someData);
|
|
53
60
|
};
|
|
54
61
|
|
|
55
62
|
addSpine(key, someData) {
|
|
56
|
-
this.
|
|
63
|
+
this._setDataToAssetsList('spine', key, someData);
|
|
57
64
|
};
|
|
58
65
|
|
|
59
66
|
getFile(key) {
|
package/src/js/lib/loader.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
class LibLoader {
|
|
2
2
|
constructor() {
|
|
3
3
|
this._isRunning = false;
|
|
4
|
+
this._iterationNumber = 0;
|
|
4
5
|
this._assetsQuery = [];
|
|
5
6
|
this._onLoadUpdate = () => { };
|
|
7
|
+
this._loader = null;
|
|
8
|
+
this._completeCallback = () => { };
|
|
9
|
+
|
|
10
|
+
this._onError = this._onError.bind(this);
|
|
6
11
|
};
|
|
7
12
|
|
|
8
13
|
isRunning() {
|
|
@@ -98,11 +103,14 @@ class LibLoader {
|
|
|
98
103
|
return false;
|
|
99
104
|
|
|
100
105
|
this._isRunning = true;
|
|
101
|
-
|
|
106
|
+
this._iterationNumber++;
|
|
107
|
+
const currentIteration = this._iterationNumber;
|
|
108
|
+
this._completeCallback = callback;
|
|
109
|
+
this._loader = new PIXI.Loader();
|
|
102
110
|
const appVersion = Urso.config.appVersion;
|
|
103
111
|
|
|
104
112
|
if (appVersion) {
|
|
105
|
-
|
|
113
|
+
this._loader.defaultQueryString = `appVersion=${appVersion}`;
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
this._assetsQuery.forEach(asset => {
|
|
@@ -118,13 +126,17 @@ class LibLoader {
|
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
const loadPath = this._getLoadPath(asset);
|
|
121
|
-
|
|
129
|
+
this._loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
|
|
122
130
|
});
|
|
123
131
|
|
|
124
132
|
this._onLoadUpdate({ progress: 0 });
|
|
125
|
-
|
|
133
|
+
this._loader.onProgress.add(this._onLoadUpdate);
|
|
134
|
+
this._loader.onError.add(this._onError);
|
|
135
|
+
|
|
136
|
+
this._loader.load(function (loader, resources) {
|
|
137
|
+
if (currentIteration !== this._iterationNumber)
|
|
138
|
+
return;
|
|
126
139
|
|
|
127
|
-
loader.load(function (loader, resources) {
|
|
128
140
|
this._onLoadUpdate({ progress: 100 });
|
|
129
141
|
this._assetsQuery = [];
|
|
130
142
|
this._isRunning = false;
|
|
@@ -132,6 +144,13 @@ class LibLoader {
|
|
|
132
144
|
}.bind(this));
|
|
133
145
|
};
|
|
134
146
|
|
|
147
|
+
|
|
148
|
+
_onError(error) {
|
|
149
|
+
this._loader.reset();
|
|
150
|
+
this._isRunning = false;
|
|
151
|
+
this.start(this._completeCallback);
|
|
152
|
+
}
|
|
153
|
+
|
|
135
154
|
};
|
|
136
155
|
|
|
137
156
|
module.exports = LibLoader;
|