@urso/core 0.3.11 → 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.11",
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
@@ -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
  ];