@urso/core 0.4.39 → 0.4.42

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.4.39",
3
+ "version": "0.4.42",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -23,6 +23,10 @@ class LibLoader {
23
23
  _getLoadPath(asset) {
24
24
  const { path } = asset;
25
25
 
26
+ if (path.indexOf('http') === 0) { //if absolute path - just return
27
+ return path;
28
+ }
29
+
26
30
  if (!Urso.config.useBinPath) {
27
31
  return `assets/${path}`;
28
32
  }
@@ -6,6 +6,8 @@ class ModulesI18nController {
6
6
  * get text by localeId
7
7
  * @param {String} localeId
8
8
  * @param {Object} [localeVariables] - variables for locale string
9
+ *
10
+ * @example get('Some333 ${bet} " `test ${multi} text localized', {bet:12,multi:13})
9
11
  */
10
12
  get(localeId, localeVariables = {}) {
11
13
  if (this.#vocabulary && this.#vocabulary[localeId]) {
@@ -66,12 +68,11 @@ class ModulesI18nController {
66
68
  }
67
69
 
68
70
  _interpolate(string, params) {
69
- const names = Object.keys(params);
70
- const vals = Object.values(params);
71
- const encodedString = encodeURIComponent(string);
72
- const resultEncodedString = new Function(...names, `return \`${encodedString}\`;`)(...vals);
71
+ for (const [key, value] of Object.entries(params)) {
72
+ string = Urso.helper.stringReplace('${' + key + '}', value, string);
73
+ }
73
74
 
74
- return decodeURIComponent(resultEncodedString);
75
+ return string
75
76
  }
76
77
  }
77
78
 
@@ -36,14 +36,24 @@ class ModulesInstancesController {
36
36
  return true;
37
37
  }
38
38
 
39
- removeMode(mode) {
39
+ /**
40
+ * remove mode from system
41
+ * @param {String} mode
42
+ * @param {Boolean} passiveMode - do not refresh styles
43
+ * @returns
44
+ */
45
+ removeMode(mode, passiveMode) {
40
46
  let index = this._modes.indexOf(mode);
41
47
 
42
48
  if (index === -1)
43
49
  return false;
44
50
 
45
51
  this._modes.splice(index, 1);
46
- Urso.observer.emit(Urso.events.MODULES_INSTANCES_MODES_CHANGED);
52
+
53
+ if (!passiveMode) {
54
+ Urso.observer.emit(Urso.events.MODULES_INSTANCES_MODES_CHANGED);
55
+ }
56
+
47
57
  return true;
48
58
  }
49
59
 
@@ -101,6 +101,22 @@ class ModulesObjectsProxy {
101
101
  if (!target.maxWidth && !target.maxHeight)
102
102
  return;
103
103
 
104
+ let calculationNeed = false;
105
+
106
+ const baseObject = target._baseObject;
107
+ //Pixi texts have _texture.orig.width. When we call baseObject.width, Pixi runs update text. Its too slow operation.
108
+ const baseObjectWidth = baseObject._texture ? Math.abs(baseObject.scale.x) * baseObject._texture.orig.width : baseObject.width;
109
+ const baseObjectHeight = baseObject._texture ? Math.abs(baseObject.scale.y) * baseObject._texture.orig.height : baseObject.height;
110
+
111
+ if (target.maxWidth && target.maxWidth < baseObjectWidth) //check maxWidth
112
+ calculationNeed = true;
113
+
114
+ if (target.maxHeight && target.maxHeight < baseObjectHeight) //check maxHeight
115
+ calculationNeed = true;
116
+
117
+ if (!calculationNeed)
118
+ return;
119
+
104
120
  let scaleNeed = 1;
105
121
 
106
122
  if (target.maxWidth) {
@@ -42,7 +42,6 @@ class ModulesObjectsStyles {
42
42
  delete this._cache[selector];
43
43
  }
44
44
  }
45
-
46
45
  }
47
46
 
48
47
  _apply(selector, style) {
@@ -68,7 +67,7 @@ class ModulesObjectsStyles {
68
67
  _globalResetStyles() {
69
68
  for (let [selector, selectorCache] of Object.entries(this._cache)) {
70
69
  for (let [uid, object] of Object.entries(selectorCache))
71
- this._removeSelectorStyles(object, selector);
70
+ this._removeSelectorStyles(object, selector, true);
72
71
 
73
72
  delete this._cache[selector];
74
73
  }
@@ -84,7 +83,7 @@ class ModulesObjectsStyles {
84
83
  }
85
84
  }
86
85
 
87
- _removeSelectorStyles(object, selector) {
86
+ _removeSelectorStyles(object, selector, globalResetFlag) {
88
87
  delete object._styles[selector];
89
88
  let template = Urso.template.get();
90
89
  let styles = template.styles[selector];
@@ -94,12 +93,12 @@ class ModulesObjectsStyles {
94
93
  }
95
94
 
96
95
  for (let [key, value] of Object.entries(styles)) {
97
- this._restoreValueByKey(key, object);
96
+ this._restoreValueByKey(key, object, globalResetFlag);
98
97
  }
99
98
 
100
99
  }
101
100
 
102
- _restoreValueByKey(key, object) {
101
+ _restoreValueByKey(key, object, globalResetFlag) {
103
102
  //check own
104
103
  if (object._originalModel[key])
105
104
  return;
@@ -110,9 +109,11 @@ class ModulesObjectsStyles {
110
109
  Urso.objects._safeSetValueToTarget(object, key, tempObject[key]);
111
110
 
112
111
  //check other styles
113
- for (let [selector, style] of Object.entries(object._styles))
114
- if (typeof style[key] !== 'undefined')
115
- Urso.objects._safeSetValueToTarget(object, key, style[key]);
112
+ if (!globalResetFlag) {
113
+ for (let [selector, style] of Object.entries(object._styles))
114
+ if (typeof style[key] !== 'undefined')
115
+ Urso.objects._safeSetValueToTarget(object, key, style[key]);
116
+ }
116
117
  }
117
118
  }
118
119
 
@@ -55,7 +55,7 @@ class ModulesScenesResolutions {
55
55
  this._currentOrientation = this._templateSize.orientation;
56
56
 
57
57
  //update InstancesModes
58
- Object.values(Urso.device.ScreenOrientation).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
58
+ Object.values(Urso.device.ScreenOrientation).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation', true));
59
59
  Urso.addInstancesMode(this._templateSize.orientation + 'Orientation');
60
60
 
61
61
  this.emit(Urso.events.MODULES_SCENES_ORIENTATION_CHANGE, this._templateSize.orientation);