@urso/core 0.4.20 → 0.4.23

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.20",
3
+ "version": "0.4.23",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -37,6 +37,8 @@ class ModulesObjectsBaseModel {
37
37
  this.alignY = Urso.helper.recursiveGet('alignY', params, 'top'); //or bottom or center
38
38
  this.width = Urso.helper.recursiveGet('width', params, false); //or 40% or 1456 // highest priority then scale
39
39
  this.height = Urso.helper.recursiveGet('height', params, false); //or 40% or 568 // highest priority then scale
40
+ this.maxWidth = Urso.helper.recursiveGet('maxWidth', params, false); //maximum width value. If objects width will be higher, it will be downscale. Do not use with scale.
41
+ this.maxHeight = Urso.helper.recursiveGet('maxHeight', params, false); //maximum height value. If objects height will be higher, it will be downscale. Do not use with scale.
40
42
  this.stretchingType = Urso.helper.recursiveGet('stretchingType', params, false); //or inscribed or circumscribed //works only if width=height=100%
41
43
  this.angle = Urso.helper.recursiveGet('angle', params, 0);
42
44
  this.visible = Urso.helper.recursiveGet('visible', params, true);
@@ -30,15 +30,13 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
30
30
  this.dropShadowDistance = Urso.helper.recursiveGet('dropShadowBlur', params, 0); // 6
31
31
  this.wordWrap = Urso.helper.recursiveGet('wordWrap', params, false);
32
32
  this.wordWrapWidth = Urso.helper.recursiveGet('wordWrapWidth', params, 100)
33
-
34
- this.maxWidth = Urso.helper.recursiveGet('maxWidth', params, false); //todo
35
33
  }
36
34
 
37
35
  _addBaseObject() {
38
36
  if (this.localeId)
39
37
  this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
40
38
 
41
- this._baseObject = new PIXI.Text(this.text);
39
+ this._baseObject = new PIXI.Text(this.text, { fontFamily: this.fontFamily });
42
40
 
43
41
  if (this.fillCustomColors) {
44
42
  this._baseObject.fillCustomColors = this.fillCustomColors;
@@ -85,6 +85,8 @@ class ModulesObjectsProxy {
85
85
 
86
86
  this._setProperty(target, propertyName, value);
87
87
 
88
+ this._checkMaxSize(target);
89
+
88
90
  //setup dirty to recalc params
89
91
  if (typeof target._baseObject.dirty !== 'undefined')
90
92
  target._baseObject.dirty = true;
@@ -92,6 +94,30 @@ class ModulesObjectsProxy {
92
94
  return true;
93
95
  };
94
96
 
97
+ _checkMaxSize(target) {
98
+ if (!target.maxWidth && !target.maxHeight)
99
+ return;
100
+
101
+ let scaleNeed = 1;
102
+
103
+ if (target.maxWidth) {
104
+ scaleNeed = Math.abs((target._baseObject.scale.x * target.maxWidth) / target._baseObject.width);
105
+ }
106
+
107
+ if (target.maxHeight) {
108
+ const scaleYNeed = Math.abs((target._baseObject.scale.y * target.maxHeight) / target._baseObject.height);
109
+
110
+ if (scaleNeed > scaleYNeed)
111
+ scaleNeed = scaleYNeed;
112
+ }
113
+
114
+ if (scaleNeed > 1)
115
+ scaleNeed = 1;
116
+
117
+ target._baseObject.scale.x = scaleNeed * Math.sign(target._baseObject.scale.x);
118
+ target._baseObject.scale.y = scaleNeed * Math.sign(target._baseObject.scale.y);
119
+ }
120
+
95
121
  _runCustomFunction(property, target) {
96
122
  const funcName = property.replace('function.', '');
97
123
  if (target[funcName])
@@ -4,6 +4,7 @@ class ModulesObjectsStyles {
4
4
 
5
5
  this._cache = {};
6
6
  this._tempObject = this.getInstance('BaseModel', {})
7
+ this._tempTextObject = this.getInstance('Models.Text', {})
7
8
  }
8
9
 
9
10
  refresh(parent) {
@@ -103,8 +104,10 @@ class ModulesObjectsStyles {
103
104
  if (object._originalModel[key])
104
105
  return;
105
106
 
107
+ const tempObject = (object.type === Urso.types.objects.TEXT) ? this._tempTextObject : this._tempObject;
108
+
106
109
  //restore defaults
107
- Urso.objects._safeSetValueToTarget(object, key, this._tempObject[key]);
110
+ Urso.objects._safeSetValueToTarget(object, key, tempObject[key]);
108
111
 
109
112
  //check other styles
110
113
  for (let [selector, style] of Object.entries(object._styles))