@urso/core 0.3.8 → 0.3.12

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.3.8",
3
+ "version": "0.3.12",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -42,20 +42,20 @@ class ComponentsDeviceRotateController extends ComponentsBaseController {
42
42
  }
43
43
 
44
44
  get _showOnLandscape() {
45
- return !this._resolutionsConfig.find(resolution => resolution.orientation === 'landscape');
45
+ return !this._resolutionsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.LANDSCAPE);
46
46
  }
47
47
 
48
48
  get _showOnPortrait() {
49
- return !this._resolutionsConfig.find(resolution => resolution.orientation === 'portrait');
49
+ return !this._resolutionsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.PORTRAIT);
50
50
  }
51
51
 
52
52
  get _isPortrait() {
53
- return this._orientation === 'portrait';
53
+ return this._orientation === Urso.device.ScreenOrientation.PORTRAIT;
54
54
  }
55
55
 
56
56
  get _needShow() {
57
- return (this._orientation === 'portrait' && this._showOnPortrait) ||
58
- (this._orientation !== 'portrait' && this._showOnLandscape)
57
+ return (this._orientation === Urso.device.ScreenOrientation.PORTRAIT && this._showOnPortrait) ||
58
+ (this._orientation !== Urso.device.ScreenOrientation.PORTRAIT && this._showOnLandscape)
59
59
  }
60
60
 
61
61
  set _isVisible(needShowDiv) {
@@ -63,7 +63,7 @@ class ComponentsDeviceRotateController extends ComponentsBaseController {
63
63
  }
64
64
 
65
65
  _updateOrientation() {
66
- this._orientation = innerWidth > innerHeight ? 'landscape' : 'portrait';
66
+ this._orientation = innerWidth > innerHeight ? Urso.device.ScreenOrientation.LANDSCAPE : Urso.device.ScreenOrientation.PORTRAIT;
67
67
  }
68
68
 
69
69
  _updateVisibility() {
@@ -33,7 +33,7 @@ class ComponentsFullscreenAndroid {
33
33
  }
34
34
 
35
35
  _updateOrientation() {
36
- this._orientation = innerWidth > innerHeight ? 'landscape' : 'portrait';
36
+ this._orientation = innerWidth > innerHeight ? Urso.device.ScreenOrientation.LANDSCAPE : Urso.device.ScreenOrientation.PORTRAIT;
37
37
  }
38
38
 
39
39
  get isFullscreen() {
@@ -49,7 +49,7 @@ class ComponentsFullscreenAndroid {
49
49
  }
50
50
 
51
51
  get _isPortrait() {
52
- return this._orientation === 'portrait';
52
+ return this._orientation === Urso.device.ScreenOrientation.PORTRAIT;
53
53
  }
54
54
 
55
55
  get _needShowOnCurrentOrientation() {
@@ -58,11 +58,11 @@ class ComponentsFullscreenAndroid {
58
58
  }
59
59
 
60
60
  get _showOnLandscape() {
61
- return this._orientationsConfig.find(resolution => resolution.orientation === 'landscape');
61
+ return this._orientationsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.LANDSCAPE);
62
62
  }
63
63
 
64
64
  get _showOnPortrait() {
65
- return this._orientationsConfig.find(resolution => resolution.orientation === 'portrait');
65
+ return this._orientationsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.PORTRAIT);
66
66
  }
67
67
 
68
68
  set isVisible(needShowDiv) {
@@ -37,15 +37,15 @@ class ComponentsFullscreenController extends ComponentsBaseController {
37
37
  }
38
38
 
39
39
  get _showOnLandscape() {
40
- return this._resolutionsConfig.find(resolution => resolution.orientation === 'landscape');
40
+ return this._resolutionsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.LANDSCAPE);
41
41
  }
42
42
 
43
43
  get _showOnPortrait() {
44
- return this._resolutionsConfig.find(resolution => resolution.orientation === 'portrait');
44
+ return this._resolutionsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.PORTRAIT);
45
45
  }
46
46
 
47
47
  get _isPortrait() {
48
- return innerWidth > innerHeight ? 'portrait' : 'landscape';
48
+ return innerWidth > innerHeight ? Urso.device.ScreenOrientation.PORTRAIT : Urso.device.ScreenOrientation.LANDSCAPE;
49
49
  }
50
50
 
51
51
  get isFullscreen() {
@@ -55,7 +55,7 @@ class ComponentsFullscreenIos {
55
55
  }
56
56
 
57
57
  _updateOrientation() {
58
- this._orientation = innerWidth > innerHeight ? 'landscape' : 'portrait';
58
+ this._orientation = innerWidth > innerHeight ? Urso.device.ScreenOrientation.LANDSCAPE : Urso.device.ScreenOrientation.PORTRAIT;
59
59
  }
60
60
 
61
61
  _updateResize() {
@@ -68,7 +68,7 @@ class ComponentsFullscreenIos {
68
68
  }
69
69
 
70
70
  get _isPortrait() {
71
- return this._orientation === 'portrait';
71
+ return this._orientation === Urso.device.ScreenOrientation.PORTRAIT;
72
72
  }
73
73
 
74
74
  get _needShowOnCurrentOrientation() {
@@ -76,11 +76,11 @@ class ComponentsFullscreenIos {
76
76
  }
77
77
 
78
78
  get _showOnLandscape() {
79
- return this._orientationsConfig.find(resolution => resolution.orientation === 'landscape');
79
+ return this._orientationsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.LANDSCAPE);
80
80
  }
81
81
 
82
82
  get _showOnPortrait() {
83
- return this._orientationsConfig.find(resolution => resolution.orientation === 'portrait');
83
+ return this._orientationsConfig.find(resolution => resolution.orientation === Urso.device.ScreenOrientation.PORTRAIT);
84
84
  }
85
85
 
86
86
  set isVisible(needShowDiv) {
@@ -476,6 +476,16 @@ LibDevice = function () {
476
476
  */
477
477
  this.fullscreenKeyboard = false;
478
478
 
479
+ /**
480
+ * Enum for possible screen orientations.
481
+ * @readonly
482
+ * @enum {string}
483
+ */
484
+ this.ScreenOrientation = {
485
+ LANDSCAPE: 'landscape',
486
+ PORTRAIT: 'portrait'
487
+ };
488
+
479
489
  };
480
490
 
481
491
  // Device is really a singleton/static entity; instantiate it
@@ -2,6 +2,8 @@ class ModulesAssetsConfig {
2
2
  constructor() {
3
3
  this.singleton = true;
4
4
 
5
+ this.defaultQualityFactor = 1;
6
+
5
7
  /**
6
8
  * quality settings for resource loading selection
7
9
  */
@@ -18,7 +18,14 @@ class ModulesAssetsController {
18
18
  * Current quality getter
19
19
  */
20
20
  getQuality() {
21
- this.getInstance('Service').getQuality();
21
+ return this.getInstance('Service').getQuality();
22
+ }
23
+
24
+ /**
25
+ * Current asset resolution
26
+ */
27
+ getCurrentResolution() {
28
+ return this.getInstance('Service').getCurrentResolution();
22
29
  }
23
30
 
24
31
  /**
@@ -160,10 +160,13 @@ class ModulesAssetsService {
160
160
  }
161
161
  }
162
162
 
163
- _processLoadedImage(assetModel) {
164
- const { qualityFactors } = this.getInstance('Config');
163
+ getCurrentResolution() {
164
+ const { qualityFactors, defaultQualityFactor } = this.getInstance('Config');
165
+ return qualityFactors[this._currentQuality] || defaultQualityFactor || 1;
166
+ }
165
167
 
166
- const resolution = qualityFactors[this._currentQuality] || 1;
168
+ _processLoadedImage(assetModel) {
169
+ const resolution = this.getCurrentResolution();
167
170
 
168
171
  const assetKey = assetModel.key;
169
172
  //textures cache
@@ -55,6 +55,15 @@ class ModulesObjectsBaseModel {
55
55
  Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
56
56
  }
57
57
 
58
+ get transform() {
59
+ return this._baseObject.transform;
60
+ }
61
+
62
+ addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
63
+ //TODO zIndex
64
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
65
+ }
66
+
58
67
  removeChild(childObject, doNotRefreshStylesFlag) {
59
68
  Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
60
69
  }
@@ -149,13 +149,17 @@ class ModulesObjectsCreate {
149
149
  this.removeChild(child.parent, child, true);
150
150
  }
151
151
 
152
- newParent.contents.push(child);
153
- let childBase = child._baseObject;
154
- newParent._baseObject.addChild(childBase);
155
- child.parent = newParent;
156
-
157
- if (!doNotRefreshStylesFlag)
158
- Urso.objects.refreshStyles(); //todo optimization
152
+ if (child._baseObject) { //regular our object
153
+ newParent.contents.push(child);
154
+ let childBase = child._baseObject;
155
+ newParent._baseObject.addChild(childBase);
156
+ child.parent = newParent;
157
+
158
+ if (!doNotRefreshStylesFlag)
159
+ Urso.objects.refreshStyles(); //todo optimization
160
+ } else { //pixi system object
161
+ newParent._baseObject.addChild(child);
162
+ }
159
163
  }
160
164
 
161
165
  removeChild(parent, child, doNotRefreshStylesFlag) {
@@ -116,7 +116,7 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
116
116
  }
117
117
 
118
118
  _onButtonUp() {
119
- if (this._isDisabled)
119
+ if (this._isDisabled || !this._isDown)
120
120
  return false;
121
121
 
122
122
  this._isDown = false;
@@ -8,6 +8,7 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
8
8
  this._baseObject = null;
9
9
  this._handleIsPulling = false;
10
10
 
11
+ this._setVariables();
11
12
  this._addBaseObject();
12
13
  this._createSliderTextures();
13
14
  this._createValueText();
@@ -25,6 +26,17 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
25
26
  this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
26
27
  this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
27
28
  this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
29
+ this.isVertical = Urso.helper.recursiveGet('isVertical', params, false);
30
+ }
31
+
32
+ _setVariables() {
33
+ if(this.isVertical) {
34
+ this.positionKey = 'y';
35
+ this.targetObjParam = 'height';
36
+ }else {
37
+ this.positionKey = 'x';
38
+ this.targetObjParam = 'width';
39
+ }
28
40
  }
29
41
 
30
42
  _createSliderTextures() {
@@ -113,82 +125,94 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
113
125
  this._handleIsDragging = true;
114
126
  }
115
127
 
116
- _onPointerMove({ x }) {
128
+ _onPointerMove({ x, y }) {
117
129
  if (!this._handleIsDragging)
118
130
  return
119
131
 
120
- if (x < this.x)
121
- this._sliderHandle.x = 0;
122
- else if (x > this.x + this._sliderBg._baseObject.width)
123
- this._sliderHandle.x = this._sliderBg._baseObject.width;
132
+ const value = this.isVertical ? y : x;
133
+
134
+ if (value < this[this.positionKey])
135
+ this._sliderHandle[this.positionKey] = 0;
136
+ else if (value >= this[this.positionKey] + this._sliderBg._baseObject[this.targetObjParam])
137
+ this._sliderHandle[this.positionKey] = this._sliderBg._baseObject[this.targetObjParam];
124
138
  else
125
- this._sliderHandle.x = x - this.x;
139
+ this._sliderHandle[this.positionKey] = value - this[this.positionKey];
126
140
 
127
141
  this._setFillMask();
142
+
143
+ const data = { class: this.class, name: this.name, position: this._sliderHandle[this.positionKey] };
144
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_MOVE, data)
128
145
  }
129
146
 
130
147
  _onPointerUp(obj) {
131
148
  this._handleIsDragging = false;
132
- let x;
149
+ let targetObj;
133
150
 
134
- if (obj.target === this._sliderBg._baseObject) {
135
- x = obj.data.getLocalPosition(obj.target).x;
136
- } else
137
- x = this._sliderHandle.x;
151
+ if (obj.target === this._sliderBg._baseObject)
152
+ targetObj = obj.data.getLocalPosition(obj.target)
153
+ else
154
+ targetObj = this._sliderHandle;
138
155
 
139
- this._dropHandle(x);
156
+ const {x, y} = targetObj;
157
+ const value = this.isVertical ? y : x;
158
+ this._dropHandle(value);
140
159
  }
141
160
 
142
161
  _setDefaultValue(){
143
162
  if(!this.points.includes(this.defaultValue))
144
163
  this.defaultValue = this.points[0];
145
164
 
146
- let x = this.points.indexOf(this.defaultValue) * this._sliderBg._baseObject.width / (this.points.length - 1);
165
+ let value = this.points.indexOf(this.defaultValue) *
166
+ this._sliderBg._baseObject[this.targetObjParam] / (this.points.length - 1);
147
167
 
148
- this._setNewValue(x, this.defaultValue);
168
+ this._setNewValue(value, this.defaultValue);
149
169
  }
150
170
 
151
- _dropHandle(x) {
171
+ _dropHandle(givenValue) {
152
172
  let value;
153
- let handleX;
173
+ let coord;
154
174
 
155
175
  if(this.points.length <= 2){
156
- handleX = x;
157
- value = ~~(100 / this._sliderBg._baseObject.width * x);
176
+ coord = givenValue;
177
+ value = ~~(100 / this._sliderBg._baseObject[this.targetObjParam] * givenValue);
158
178
  }
159
179
  // calculate closest point
160
180
  else{
161
181
  for (let i = 0; i < this.points.length; i++) {
162
- let pointX = i * this._sliderBg._baseObject.width / (this.points.length - 1);
182
+ let pointCoord = i * this._sliderBg._baseObject[this.targetObjParam] / (this.points.length - 1);
163
183
 
164
- if (typeof (handleX) === 'number' && x - pointX < handleX - x) {
165
- handleX = handleX;
184
+ if (typeof (coord) === 'number' && givenValue - pointCoord < coord - givenValue) {
185
+ coord = coord;
166
186
  } else {
167
- handleX = pointX;
187
+ coord = pointCoord;
168
188
  value = this.points[i];
169
189
  }
170
190
  }
171
191
  }
192
+ const data = { class: this.class, name: this.name, position: coord, value: value };
172
193
 
173
- this._setNewValue(handleX, value);
194
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_HANDLE_DROP, data);
195
+ this._setNewValue(coord, value);
174
196
  }
175
197
 
176
198
  _setFillMask(){
177
199
  if(!this._fillMask)
178
200
  return
179
201
 
180
- const progress = (this._sliderHandle.x - this._sliderBg.x) * 100 / this._fillTexture._baseObject.width * 0.01;
181
- this._fillMask.scaleX = progress;
202
+ const progress = (this._sliderHandle[this.positionKey] - this._sliderBg[this.positionKey]) *
203
+ 100 / this._fillTexture._baseObject[this.targetObjParam] * 0.01;
204
+
205
+ const scaleKey = this.isVertical ? 'scaleY' : 'scaleX';
206
+ this._fillMask[scaleKey] = progress;
182
207
  }
183
208
 
184
- _setNewValue(x, value){
185
- this._sliderHandle.x = x;
209
+ _setNewValue(coord, value){
210
+ this._sliderHandle[this.positionKey] = coord;
186
211
 
187
212
  if (this.currentValueText)
188
213
  this.currentValueText.text = value;
189
214
 
190
215
  this._setFillMask();
191
- this.emit(Urso.events.MODULES_OBJECTS_SLIDER_SET_NEW_VALUE, { name: this.name, value: value, class: this.class });
192
216
  }
193
217
 
194
218
  _subscribeOnce() {
@@ -9,7 +9,8 @@ class ModulesObserverConfig {
9
9
  MODULES_INSTANCES_MODES_CHANGED: 'modules.instances.modes.changed',
10
10
  MODULES_OBJECTS_BUTTON_PRESS: 'modules.objects.button.press',
11
11
  MODULES_OBJECTS_HIT_AREA_PRESS: 'modules.objects.hitArea.press',
12
- MODULES_OBJECTS_SLIDER_SET_NEW_VALUE: 'modules.objects.slider.setNewValue',
12
+ MODULES_OBJECTS_SLIDER_HANDLE_MOVE: 'modules.objects.slider.handleMove',
13
+ MODULES_OBJECTS_SLIDER_HANDLE_DROP: 'modules.objects.slider.handleDrop',
13
14
  MODULES_OBJECTS_TOGGLE_PRESS: 'modules.objects.toggle.press',
14
15
  MODULES_OBJECTS_TEXTINPUT_BLUR: 'modules.objects.textinput.blur',
15
16
  MODULES_OBJECTS_TEXTINPUT_INPUT: 'modules.objects.textinput.input',
@@ -4,7 +4,6 @@ class ModulesScenesResolutions {
4
4
  this.singleton = true;
5
5
  this._activeResolution = false; //object
6
6
  this._templateSize = { orientation: 0, width: 0, height: 0 };
7
- this._orientations = { landscape: 'landscape', portrait: 'portrait' }
8
7
  this._currentOrientation = null;
9
8
 
10
9
  this.refreshSceneSize = this.refreshSceneSize.bind(this);
@@ -53,7 +52,7 @@ class ModulesScenesResolutions {
53
52
  console.log('[SCENE] New Template Size', this._templateSize);
54
53
 
55
54
  //update InstancesModes
56
- Object.values(this._orientations).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
55
+ Object.values(Urso.device.ScreenOrientation).forEach((orientationValue) => Urso.removeInstancesMode(orientationValue + 'Orientation'));
57
56
  Urso.addInstancesMode(orientation + 'Orientation');
58
57
 
59
58
  //send new resolution event
@@ -68,12 +67,9 @@ class ModulesScenesResolutions {
68
67
  };
69
68
 
70
69
  _getWindowSize() {
71
- const iOS = Urso.device.iOS;
72
- const { width, height } = document.body.getBoundingClientRect();
73
-
74
70
  let windowSize = {
75
- width: iOS ? window.innerWidth : width,
76
- height: iOS ? window.innerHeight : height
71
+ width: window.innerWidth,
72
+ height: window.innerHeight
77
73
  };
78
74
 
79
75
  if (window.devicePixelRatio && window.devicePixelRatio !== 1) {
@@ -85,7 +81,7 @@ class ModulesScenesResolutions {
85
81
  }
86
82
 
87
83
  _getOrientation(windowSize) {
88
- return windowSize.width > windowSize.height ? this._orientations.landscape : this._orientations.portrait; //todo move to constants
84
+ return windowSize.width > windowSize.height ? Urso.device.ScreenOrientation.LANDSCAPE : Urso.device.ScreenOrientation.PORTRAIT;
89
85
  }
90
86
 
91
87
  _getResolutionConfig(windowSize) {
@@ -2,14 +2,14 @@ class ModulesScenesResolutionsConfig {
2
2
  constructor() {
3
3
  this.singleton = true;
4
4
 
5
- this._orientations = ['landscape', 'portrait'];
5
+ this._orientations = [Urso.device.ScreenOrientation.LANDSCAPE, Urso.device.ScreenOrientation.PORTRAIT]; //you can use only one orientation for config contents
6
6
 
7
7
  this.contents = [
8
8
  {
9
9
  "name": 'default',
10
10
  "width": 1920,
11
11
  "height": 1080,
12
- "orientation": 'landscape',
12
+ "orientation": Urso.device.ScreenOrientation.LANDSCAPE,
13
13
  "adaptive": true
14
14
  }
15
15
  ];