@urso/core 0.7.33 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.7.33",
3
+ "version": "0.7.35",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -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.assetsList.file[key] = someData;
26
+ this._setDataToAssetsList('file', key, someData);
20
27
  };
21
28
 
22
29
  addAtlas(key, someData) {
23
- this.assetsList.atlas[key] = someData;
30
+ this._setDataToAssetsList('atlas', key, someData);
24
31
  };
25
32
 
26
33
  addBinary(key, someData) {
27
- this.assetsList.binary[key] = someData;
34
+ this._setDataToAssetsList('binary', key, someData);
28
35
  };
29
36
 
30
37
  addBitmapFont(key, someData) {
31
- this.assetsList.bitmapFont[key] = someData;
38
+ this._setDataToAssetsList('bitmapFont', key, someData);
32
39
  };
33
40
 
34
41
  addContainer(key, someData) {
35
- this.assetsList.container[key] = someData;
42
+ this._setDataToAssetsList('container', key, someData);
36
43
  };
37
44
 
38
45
  addImage(key, someData) {
39
- this.assetsList.image[key] = someData;
46
+ this._setDataToAssetsList('image', key, someData);
40
47
  };
41
48
 
42
49
  addJson(key, someData) {
43
- this.assetsList.json[key] = someData;
50
+ this._setDataToAssetsList('json', key, someData);
44
51
  };
45
52
 
46
53
  addSound(key, someData) {
47
- this.assetsList.sound[key] = someData;
54
+ this._setDataToAssetsList('sound', key, someData);
48
55
  };
49
56
 
50
57
  addTexture(key, someData) {
51
- this.assetsList.texture[key] = someData;
58
+ this._setDataToAssetsList('texture', key, someData);
52
59
  this.globalAtlas.addTexture(key, someData);
53
60
  };
54
61
 
55
62
  addSpine(key, someData) {
56
- this.assetsList.spine[key] = someData;
63
+ this._setDataToAssetsList('spine', key, someData);
57
64
  };
58
65
 
59
66
  getFile(key) {
@@ -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
- const loader = new PIXI.Loader();
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
- loader.defaultQueryString = `appVersion=${appVersion}`;
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
- loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
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
- loader.onProgress.add(this._onLoadUpdate);
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;
@@ -185,18 +185,17 @@ class ModulesAssetsService {
185
185
  let imageData = Urso.cache.getAtlas(assetKey);
186
186
  const folderPath = imageData.url.split('/').slice(0, -1).join('/');
187
187
 
188
- for (let i = 0; i < imageData.spritesheet._frames.length; i++) {
189
- let frame = imageData.spritesheet._frames[i];
190
- let texture = imageData.textures[i];
191
- let newFilename = frame.filename;
188
+ for (const name of Object.keys(imageData.spritesheet._frames)) {
189
+ let texture = imageData.textures[name];
190
+ let newFilename = name;
192
191
 
193
- if (!frame.filename.includes('/'))
194
- newFilename = folderPath + '/' + frame.filename;
192
+ if (!name.includes('/'))
193
+ newFilename = folderPath + '/' + name;
195
194
 
196
195
  Urso.cache.addFile(newFilename, texture);
197
196
 
198
- if(assetModel.cacheTextures) {
199
- const textureKey = newFilename.split('/').pop().split('.')[0];
197
+ if (assetModel.cacheTextures) {
198
+ const textureKey = newFilename.split('.')[0];
200
199
  Urso.cache.addTexture(textureKey, texture);
201
200
  }
202
201
  }