@urso/core 0.1.90 → 0.1.95

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.
@@ -27,135 +27,135 @@ object-assign
27
27
  */
28
28
 
29
29
  /*!
30
- * @pixi/accessibility - v5.3.10
31
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
30
+ * @pixi/accessibility - v5.3.11
31
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
32
32
  *
33
33
  * @pixi/accessibility is licensed under the MIT License.
34
34
  * http://www.opensource.org/licenses/mit-license
35
35
  */
36
36
 
37
37
  /*!
38
- * @pixi/constants - v5.3.10
39
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
38
+ * @pixi/constants - v5.3.11
39
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
40
40
  *
41
41
  * @pixi/constants is licensed under the MIT License.
42
42
  * http://www.opensource.org/licenses/mit-license
43
43
  */
44
44
 
45
45
  /*!
46
- * @pixi/core - v5.3.10
47
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
46
+ * @pixi/core - v5.3.11
47
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
48
48
  *
49
49
  * @pixi/core is licensed under the MIT License.
50
50
  * http://www.opensource.org/licenses/mit-license
51
51
  */
52
52
 
53
53
  /*!
54
- * @pixi/display - v5.3.10
55
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
54
+ * @pixi/display - v5.3.11
55
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
56
56
  *
57
57
  * @pixi/display is licensed under the MIT License.
58
58
  * http://www.opensource.org/licenses/mit-license
59
59
  */
60
60
 
61
61
  /*!
62
- * @pixi/extract - v5.3.10
63
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
62
+ * @pixi/extract - v5.3.11
63
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
64
64
  *
65
65
  * @pixi/extract is licensed under the MIT License.
66
66
  * http://www.opensource.org/licenses/mit-license
67
67
  */
68
68
 
69
69
  /*!
70
- * @pixi/filter-displacement - v5.3.10
71
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
70
+ * @pixi/filter-displacement - v5.3.11
71
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
72
72
  *
73
73
  * @pixi/filter-displacement is licensed under the MIT License.
74
74
  * http://www.opensource.org/licenses/mit-license
75
75
  */
76
76
 
77
77
  /*!
78
- * @pixi/loaders - v5.3.10
79
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
78
+ * @pixi/loaders - v5.3.11
79
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
80
80
  *
81
81
  * @pixi/loaders is licensed under the MIT License.
82
82
  * http://www.opensource.org/licenses/mit-license
83
83
  */
84
84
 
85
85
  /*!
86
- * @pixi/math - v5.3.10
87
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
86
+ * @pixi/math - v5.3.11
87
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
88
88
  *
89
89
  * @pixi/math is licensed under the MIT License.
90
90
  * http://www.opensource.org/licenses/mit-license
91
91
  */
92
92
 
93
93
  /*!
94
- * @pixi/mesh-extras - v5.3.10
95
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
94
+ * @pixi/mesh-extras - v5.3.11
95
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
96
96
  *
97
97
  * @pixi/mesh-extras is licensed under the MIT License.
98
98
  * http://www.opensource.org/licenses/mit-license
99
99
  */
100
100
 
101
101
  /*!
102
- * @pixi/mixin-get-child-by-name - v5.3.10
103
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
102
+ * @pixi/mixin-get-child-by-name - v5.3.11
103
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
104
104
  *
105
105
  * @pixi/mixin-get-child-by-name is licensed under the MIT License.
106
106
  * http://www.opensource.org/licenses/mit-license
107
107
  */
108
108
 
109
109
  /*!
110
- * @pixi/mixin-get-global-position - v5.3.10
111
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
110
+ * @pixi/mixin-get-global-position - v5.3.11
111
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
112
112
  *
113
113
  * @pixi/mixin-get-global-position is licensed under the MIT License.
114
114
  * http://www.opensource.org/licenses/mit-license
115
115
  */
116
116
 
117
117
  /*!
118
- * @pixi/polyfill - v5.3.10
119
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
118
+ * @pixi/polyfill - v5.3.11
119
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
120
120
  *
121
121
  * @pixi/polyfill is licensed under the MIT License.
122
122
  * http://www.opensource.org/licenses/mit-license
123
123
  */
124
124
 
125
125
  /*!
126
- * @pixi/prepare - v5.3.10
127
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
126
+ * @pixi/prepare - v5.3.11
127
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
128
128
  *
129
129
  * @pixi/prepare is licensed under the MIT License.
130
130
  * http://www.opensource.org/licenses/mit-license
131
131
  */
132
132
 
133
133
  /*!
134
- * @pixi/runner - v5.3.10
135
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
134
+ * @pixi/runner - v5.3.11
135
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
136
136
  *
137
137
  * @pixi/runner is licensed under the MIT License.
138
138
  * http://www.opensource.org/licenses/mit-license
139
139
  */
140
140
 
141
141
  /*!
142
- * @pixi/ticker - v5.3.10
143
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
142
+ * @pixi/ticker - v5.3.11
143
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
144
144
  *
145
145
  * @pixi/ticker is licensed under the MIT License.
146
146
  * http://www.opensource.org/licenses/mit-license
147
147
  */
148
148
 
149
149
  /*!
150
- * @pixi/utils - v5.3.10
151
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
150
+ * @pixi/utils - v5.3.11
151
+ * Compiled Mon, 01 Nov 2021 16:10:12 UTC
152
152
  *
153
153
  * @pixi/utils is licensed under the MIT License.
154
154
  * http://www.opensource.org/licenses/mit-license
155
155
  */
156
156
 
157
157
  /*!
158
- * GSAP 3.7.1
158
+ * GSAP 3.8.0
159
159
  * https://greensock.com
160
160
  *
161
161
  * @license Copyright 2008-2021, GreenSock. All rights reserved.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.1.90",
3
+ "version": "0.1.95",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
package/src/js/app.js CHANGED
@@ -14,7 +14,7 @@ class App {
14
14
  //setup Instances
15
15
  let instances = new Urso.Core.Modules.Instances.Controller();
16
16
  Urso.getInstance = instances.getInstance;
17
- Urso.getPath = instances.getPath;
17
+ Urso.getByPath = instances.getByPath;
18
18
  Urso.getInstancesModes = instances.getModes;
19
19
  Urso.addInstancesMode = instances.addMode;
20
20
  Urso.removeInstancesMode = instances.removeMode;
@@ -34,7 +34,7 @@ class App {
34
34
 
35
35
  //libs
36
36
  Urso.cache = Urso.getInstance('Lib.Cache'); //all assets cache
37
- Urso.device = Urso.getPath('Lib.Device'); //all device info
37
+ Urso.device = Urso.getByPath('Lib.Device'); //all device info
38
38
  Urso.loader = Urso.getInstance('Lib.Loader'); //assets loader class
39
39
  Urso.localData = Urso.getInstance('Lib.LocalData'); //local data storage
40
40
  Urso.logger = Urso.getInstance('Lib.Logger'); //logger
@@ -59,6 +59,7 @@ class App {
59
59
 
60
60
  //App.run
61
61
  Urso.device.whenReady(() => {
62
+ Urso.assets.updateQuality();
62
63
  Urso.getInstance('App').run();
63
64
  });
64
65
  }
@@ -2,7 +2,8 @@ let ConfigMain = {
2
2
  title: 'Urso', //game title
3
3
  mode: "development", // development/production/testing
4
4
  extendingChain: ['Urso.Core'], //chain that will be set as Urso.Game
5
- defaultScene: 'play' //default scene to display
5
+ defaultScene: 'play', //default scene to display
6
+ useBinPath: false
6
7
  };
7
8
 
8
9
  module.exports = ConfigMain;
@@ -17,6 +17,26 @@ class LibLoader {
17
17
  this._assetsQuery.push(asset);
18
18
  }
19
19
 
20
+ /**
21
+ * gets part of loading path
22
+ */
23
+ _getLoadPath(asset){
24
+ const { path } = asset;
25
+
26
+ if(!Urso.config.useBinPath) {
27
+ return `assets/${path}`;
28
+ }
29
+
30
+ const quality = Urso.getInstance('Modules.Assets.Service').getQuality();
31
+ const splitted = path.split('/');
32
+
33
+ if (splitted[0] === 'images') {
34
+ splitted.splice(1, 0, quality);
35
+ }
36
+
37
+ return `bin/${splitted.join('/')}`;
38
+ };
39
+
20
40
  /**
21
41
  * store loaded asset in cache
22
42
  */
@@ -79,7 +99,8 @@ class LibLoader {
79
99
  // TODO: check to load
80
100
 
81
101
  const params = asset.params || false; // TODO: Set params field in base mode
82
- loader.add(asset.key, asset.path, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
102
+ const loadPath = this._getLoadPath(asset);
103
+ loader.add(asset.key, loadPath, params, (resource) => this._storeAsset(asset, resource)) //TODO set assets resolution instead _processLoadedImage baseTexture resolution
83
104
  });
84
105
 
85
106
  this._onLoadUpdate({progress: 0});
@@ -2,6 +2,16 @@ class ModulesAssetsConfig {
2
2
  constructor() {
3
3
  this.singleton = true;
4
4
 
5
+ /**
6
+ * quality settings for resource loading selection
7
+ */
8
+ this.qualityFactors = {
9
+ medium: 0.5,
10
+ hd: 0.75,
11
+ high: 1
12
+ };
13
+
14
+
5
15
  /**
6
16
  * initial is the default and will load on the preload
7
17
  * also you can call preload manualy by assets.loadGroup('groupName')
@@ -10,7 +20,7 @@ class ModulesAssetsConfig {
10
20
  initial: 0 //will load on the preload
11
21
  /*lazyPart1: 'lazyPart1',
12
22
  lazyPart2: 'lazyPart2'*/
13
- }
23
+ };
14
24
 
15
25
  /**
16
26
  * you can make lazy load groups priority here
@@ -3,6 +3,22 @@ class ModulesAssetsController {
3
3
  this.singleton = true;
4
4
  };
5
5
 
6
+ /**
7
+ * Update quality
8
+ */
9
+ updateQuality(){
10
+ if(Urso.config.useBinPath){
11
+ this.getInstance('Service').updateQuality();
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Current quality getter
17
+ */
18
+ getQuality(){
19
+ this.getInstance('Service').getQuality();
20
+ }
21
+
6
22
  /**
7
23
  * instantly load initial assets and start lazy loading process, if needed
8
24
  * @param {Mixed} assets - asset or array of assets
@@ -1,12 +1,22 @@
1
1
  class ModulesAssetsService {
2
2
  constructor() {
3
3
  this.singleton = true;
4
-
4
+
5
5
  this.assets = {};
6
6
 
7
+ this._currentQuality = 'auto';
7
8
  this._addedAssetsCache = [];
8
9
  };
9
10
 
11
+ getQuality(){
12
+ return this._currentQuality;
13
+ }
14
+
15
+ updateQuality(){
16
+ this._currentQuality = this._detectQuality();
17
+ Urso.addInstancesMode(this._currentQuality);
18
+ }
19
+
10
20
  sortAssets(assets) {
11
21
  this.assets[this.getInstance('Config').loadingGroups.initial] = [];
12
22
 
@@ -125,13 +135,9 @@ class ModulesAssetsService {
125
135
  }
126
136
 
127
137
  _processLoadedImage(assetModel) {
128
- const { params, current } = this._getQualityParams();
129
- let imageQualityKey = assetModel.useBinPath;
138
+ const { qualityFactors } = this.getInstance('Config');
130
139
 
131
- if (imageQualityKey === true)
132
- imageQualityKey = current;
133
-
134
- let qualityTextureResolution = params[imageQualityKey] || 1;
140
+ const resolution = qualityFactors[this._currentQuality] || 1;
135
141
 
136
142
  const assetKey = assetModel.key;
137
143
  //textures cache
@@ -140,14 +146,14 @@ class ModulesAssetsService {
140
146
  if (!imageData) {
141
147
  //from atlas ?!
142
148
  let texture = Urso.cache.getFile(assetModel.path);
143
-
149
+
144
150
  if (!texture)
145
151
  return Urso.logger.error('ModulesAssetsService process Loaded Image error: no image ', assetModel);
146
152
 
147
153
  Urso.cache.addTexture(assetKey, texture); //TODO change resolution of base texture
148
154
  } else {
149
155
  //regular image
150
- const baseTexture = new PIXI.BaseTexture(imageData.data, { resolution: qualityTextureResolution });
156
+ const baseTexture = new PIXI.BaseTexture(imageData.data, { resolution });
151
157
  const texture = new PIXI.Texture(baseTexture);
152
158
  Urso.cache.addTexture(assetKey, texture);
153
159
  }
@@ -215,9 +221,6 @@ class ModulesAssetsService {
215
221
  //set loadingGroup
216
222
  model.loadingGroup = loadingGroup || model.loadingGroup || this.getInstance('Config').loadingGroups.initial;
217
223
 
218
- //setup path if its need
219
- this._setQualityPath(model); //TODO adapt for dragonbones
220
-
221
224
  //check if container or dragonbones
222
225
  if (model.contents) {
223
226
  for (let content of model.contents) {
@@ -253,41 +256,65 @@ class ModulesAssetsService {
253
256
  this.loadGroup(groupName, () => { this._continueLazyLoad(step + 1); })
254
257
  }
255
258
 
256
- // TODO: MOVE TO CFG OR HELPER?
257
- _getQualityParams() {
258
- const params = {
259
- high: 1,
260
- hd: 0.75,
261
- medium: 0.5,
262
- low: 0.25
263
- }
264
- const current = 'hd';
265
- return { params, current };
259
+ _qualityReducer(qualityFactors, widthFactor){
260
+ return [(acc, val) => {
261
+ if (acc === null) {
262
+ return val;
263
+ }
264
+
265
+ const currentQuality = qualityFactors[acc];
266
+ const qualityFactor = qualityFactors[val];
267
+
268
+ const nextQuality = (currentQuality > qualityFactor && qualityFactor >= widthFactor)
269
+ || (qualityFactor >= widthFactor && widthFactor > currentQuality)
270
+ || (widthFactor >= qualityFactor && qualityFactor > currentQuality);
271
+
272
+ return nextQuality ? val : acc;
273
+
274
+ }, null]
266
275
  }
267
276
 
268
- _setQualityPath(asset) {
269
- if (!asset.useBinPath)
270
- return;
277
+ _detectQuality(){
278
+ const { qualityFactors } = this.getInstance('Config');
279
+ const userQuality = Urso.helper.parseGetParams()['quality'];
280
+
281
+ if(userQuality && qualityFactors[userQuality]){
282
+ return userQuality;
283
+ }
284
+
285
+ return this._calculateQuality(qualityFactors);
286
+ }
271
287
 
272
- const { params, current } = this._getQualityParams();
288
+ _calculateQuality(qualityFactors){
289
+ const { android, iOS, iPad, macOS } = Urso.device;
290
+ const isMobile = android || iOS || iPad;
273
291
 
274
- const setQuality = asset => {
275
- const qualityPath = (typeof asset.useBinPath === 'string' && params[asset.useBinPath]) ? asset.useBinPath : current;
276
- asset.path = asset.path.replace('assets', `bin/${qualityPath}`);
292
+ if (macOS && !isMobile) {
293
+ return 'high';
277
294
  }
278
295
 
279
- if (!asset.contents) {
280
- setQuality(asset);
281
- return;
296
+ if(macOS && iPad) {
297
+ return 'medium';
282
298
  }
283
299
 
284
- for (const childAsset of asset.contents) {
285
- const binPath = (childAsset.useBinPath && childAsset.useBinPath !== asset.useBinPath)
286
- ? childAsset.useBinPath : asset.useBinPath;
300
+ const resCfg = Urso.getInstance('Modules.Scenes.ResolutionsConfig').contents[0];
301
+
302
+ const { devicePixelRatio } = window;
303
+ let { width, height } = screen;
287
304
 
288
- childAsset.useBinPath = binPath;
289
- setQuality(childAsset);
305
+ if (isMobile) {
306
+ width = (width > height) ? width : height;
290
307
  }
308
+
309
+ if (iOS) {
310
+ width *= devicePixelRatio;
311
+ }
312
+
313
+ const widthFactor = width / resCfg.width;
314
+
315
+ return Object
316
+ .keys(qualityFactors)
317
+ .reduce(...this._qualityReducer(qualityFactors, widthFactor));
291
318
  }
292
319
 
293
320
  _addAssetToLoader(assetModel, loader) {
@@ -4,7 +4,7 @@ class ModulesInstancesController {
4
4
  this._cache = {};
5
5
 
6
6
  this.getInstance = this.getInstance.bind(this);
7
- this.getPath = this.getPath.bind(this);
7
+ this.getByPath = this.getByPath.bind(this);
8
8
  this._setComonFunctions = this._setComonFunctions.bind(this);
9
9
 
10
10
  this.getModes = this.getModes.bind(this);
@@ -12,12 +12,12 @@ class ModulesInstancesController {
12
12
  this.removeMode = this.removeMode.bind(this);
13
13
  }
14
14
 
15
- getPath(path, noModes, modeName) {
15
+ getByPath(path, noModes, modeName) {
16
16
  let callback = (a) => {
17
17
  return a;
18
18
  };
19
19
 
20
- return this._findClass({ path: path, callback: callback, noModes: noModes, modeName: modeName });
20
+ return this._findClass({ path, callback, noModes, modeName });
21
21
  }
22
22
 
23
23
  getModes() {
@@ -64,7 +64,7 @@ class ModulesInstancesController {
64
64
  return instance;
65
65
  };
66
66
 
67
- return this._findClass({ path: path, callback: callback, noModes: noModes, modeName: modeName });
67
+ return this._findClass({ path, callback, noModes, modeName });
68
68
  }
69
69
 
70
70
  _setComonFunctions(classObject, path) {
@@ -147,7 +147,7 @@ class ModulesInstancesController {
147
147
  return this._cache[cacheKey] ? params.callback(this._cache[cacheKey]) : false;
148
148
 
149
149
  //no class in cache - we will find class by path
150
- let classObject = this._getClassByPath(params.path);
150
+ let classObject = this._getClassByPath(params.path, params.noModes);
151
151
 
152
152
  if (!classObject)
153
153
  return false;
@@ -166,10 +166,10 @@ class ModulesInstancesController {
166
166
  return params.callback(this._cache[cacheKey]);
167
167
  }
168
168
 
169
- _getClassByPath(path) {
169
+ _getClassByPath(path, noModes) {
170
170
  let pathArr = path.split('.');
171
171
  let entitiesArray = Urso.helper.mergeArrays(['Urso', 'Game'], pathArr);
172
- return this._checkPathExist(entitiesArray);
172
+ return this._checkPathExist(entitiesArray, noModes);
173
173
  }
174
174
 
175
175
  /**
@@ -177,12 +177,12 @@ class ModulesInstancesController {
177
177
  * @param {Object} entitiesArray like ['Urso', 'Game', 'Lib', 'Helper']
178
178
  * @returns {mixed}
179
179
  */
180
- _checkPathExist(entitiesArray) {
180
+ _checkPathExist(entitiesArray, noModes) {
181
181
  let currentTestObject = window;
182
182
  let testMode;
183
183
 
184
184
  for (let entitiesIndex = 0; entitiesIndex < entitiesArray.length; entitiesIndex++) {
185
- if (this._modes && entitiesIndex === entitiesArray.length - 1)
185
+ if (!noModes && this._modes && entitiesIndex === entitiesArray.length - 1)
186
186
  testMode = this._checkPathWithModes(currentTestObject, entitiesArray, entitiesIndex);
187
187
 
188
188
  if (testMode)
@@ -40,9 +40,6 @@ class ModulesStatesManagerRace extends Action {
40
40
  action.run(this._actionSuccessHandler);
41
41
  else
42
42
  action.finished = true;
43
-
44
- if (!this.finished) //action can be finished instantly after run
45
- this._checkFinish();
46
43
  }
47
44
 
48
45
  _actionSuccessHandler() {
@@ -1,4 +1,4 @@
1
- class ModulesTemplateController {
1
+ class ModulesTemplateService {
2
2
  constructor() {
3
3
  this.singleton = true;
4
4
 
@@ -58,8 +58,11 @@ class ModulesTemplateController {
58
58
  if (!groupTemplate)
59
59
  Urso.logger.error('ModulesTemplateController group Template error ' + obj.groupName);
60
60
 
61
- this._parseAssets(groupTemplate.assets, groupTemplate._templatePath);
62
- this._parseObjects(groupTemplate.objects, groupTemplate._templatePath);
61
+ if (groupTemplate.assets)
62
+ this._parseAssets(groupTemplate.assets, groupTemplate._templatePath);
63
+
64
+ if (groupTemplate.objects)
65
+ this._parseObjects(groupTemplate.objects, groupTemplate._templatePath);
63
66
 
64
67
  this._mergeStylesAndAssets({ styles: groupTemplate.styles, assets: groupTemplate.assets })
65
68
 
@@ -119,4 +122,4 @@ class ModulesTemplateController {
119
122
 
120
123
  }
121
124
 
122
- module.exports = ModulesTemplateController;
125
+ module.exports = ModulesTemplateService;