@urso/core 0.4.19 → 0.4.22

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.19",
3
+ "version": "0.4.22",
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])
@@ -51,18 +51,19 @@ class ModulesScenesResolutions {
51
51
  console.log('[SCENE] New Resolution', currentResolution, 'windowSize:', windowSize);
52
52
  console.log('[SCENE] New Template Size', this._templateSize);
53
53
 
54
- //update InstancesModes
55
- Object.values(Urso.device.ScreenOrientation).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
56
- Urso.addInstancesMode(orientation + 'Orientation');
57
-
58
- //send new resolution event
59
- this.emit(Urso.events.MODULES_SCENES_NEW_RESOLUTION, { resolution: currentResolution, template: this._templateSize });
60
-
61
54
  if (this._currentOrientation !== this._templateSize.orientation) {
62
55
  this._currentOrientation = this._templateSize.orientation;
56
+
57
+ //update InstancesModes
58
+ Object.values(Urso.device.ScreenOrientation).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
59
+ Urso.addInstancesMode(this._templateSize.orientation + 'Orientation');
60
+
63
61
  this.emit(Urso.events.MODULES_SCENES_ORIENTATION_CHANGE, this._templateSize.orientation);
64
62
  }
65
63
 
64
+ //send new resolution event
65
+ this.emit(Urso.events.MODULES_SCENES_NEW_RESOLUTION, { resolution: currentResolution, template: this._templateSize });
66
+
66
67
  return true;
67
68
  };
68
69