@urso/core 0.4.40 → 0.4.43

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.40",
3
+ "version": "0.4.43",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -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
 
@@ -101,6 +101,27 @@ 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
+
108
+ //Pixi texts have _texture.orig.width. When we call baseObject.width, Pixi runs update text. Its too slow operation.
109
+ if (baseObject._texture && (!baseObject._texture.orig.width || !baseObject._texture.orig.height)) {
110
+ baseObject.updateText(true);
111
+ }
112
+
113
+ const baseObjectWidth = baseObject._texture ? Math.abs(baseObject.scale.x) * baseObject._texture.orig.width : baseObject.width;
114
+ const baseObjectHeight = baseObject._texture ? Math.abs(baseObject.scale.y) * baseObject._texture.orig.height : baseObject.height;
115
+
116
+ if (target.maxWidth && target.maxWidth < baseObjectWidth) //check maxWidth
117
+ calculationNeed = true;
118
+
119
+ if (target.maxHeight && target.maxHeight < baseObjectHeight) //check maxHeight
120
+ calculationNeed = true;
121
+
122
+ if (!calculationNeed)
123
+ return;
124
+
104
125
  let scaleNeed = 1;
105
126
 
106
127
  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