@urso/core 0.4.9 → 0.4.13

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.9",
3
+ "version": "0.4.13",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -7,8 +7,10 @@ class ComponentsFullscreenController extends ComponentsBaseController {
7
7
 
8
8
  this._fullscreenActivator = null;
9
9
  this._resolutionsConfig = null;
10
+ this.lastResizeFullscreenResult;
10
11
 
11
12
  this.createActivator();
13
+ this._resizeHandler();
12
14
  }
13
15
 
14
16
  createActivator() {
@@ -53,7 +55,14 @@ class ComponentsFullscreenController extends ComponentsBaseController {
53
55
  }
54
56
 
55
57
  _resizeHandler() {
56
- Urso.localData.set('fullscreen.isFullscreen', this.isFullscreen);
58
+ const isFullscreen = this.isFullscreen;
59
+
60
+ if (this.lastResizeFullscreenResult === isFullscreen)
61
+ return;
62
+
63
+ this.lastResizeFullscreenResult = isFullscreen;
64
+ Urso.localData.set('fullscreen.isFullscreen', isFullscreen);
65
+ this.emit(Urso.events.COMPONENTS_FULLSCREEN_CHANGE, isFullscreen);
57
66
  }
58
67
 
59
68
  _subscribeOnce() {
@@ -40,6 +40,10 @@ class ComponentsFullscreenIos {
40
40
  });
41
41
  }
42
42
 
43
+ get isFullscreen() {
44
+ return this._isFullscreen;
45
+ }
46
+
43
47
  get _isFullscreen() {
44
48
  const minFactor = 0.51;
45
49
  const deviceFactor = screen.width / screen.height;
@@ -49,7 +53,7 @@ class ComponentsFullscreenIos {
49
53
 
50
54
  return !(
51
55
  this._isPortrait ?
52
- factor - deviceFactor < 0.1:
56
+ factor - deviceFactor < 0.1 :
53
57
  factor > minFactor
54
58
  );
55
59
  }
@@ -87,8 +91,8 @@ class ComponentsFullscreenIos {
87
91
  this._div.style.zIndex = needShowDiv ? 1 : -1;
88
92
  clearTimeout(this._scrollTimeout)
89
93
  this._scrollTimeout = setTimeout(() => {
90
- if(needShowDiv)
91
- window.scrollTo(0,0);
94
+ if (needShowDiv)
95
+ window.scrollTo(0, 0);
92
96
  }, 200);
93
97
  }
94
98
 
@@ -17,6 +17,8 @@ require('./setTimeout');
17
17
  import Howler from 'howler';
18
18
  window.Howler = Howler;
19
19
 
20
+ require("./pixiPatch.js");
21
+
20
22
  Urso.Core.Extra = {
21
23
  BrowserEvents: require('./browserEvents.js')
22
24
  };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * ModulesObjectsModelsText fillCustomColors patch
3
+ */
4
+
5
+
6
+ /**
7
+ * Render the text with letter-spacing.
8
+ *
9
+ * @param text - The text to draw
10
+ * @param x - Horizontal position to draw the text
11
+ * @param y - Vertical position to draw the text
12
+ * @param isStroke - Is this drawing for the outside stroke of the
13
+ * text? If not, it's for the inside fill
14
+ */
15
+ PIXI.Text.prototype.drawLetterSpacing = function (text, x, y, isStroke) {
16
+ if (isStroke === void 0) { isStroke = false; }
17
+ var style = this._style;
18
+ // letterSpacing of 0 means normal
19
+ var letterSpacing = style.letterSpacing;
20
+ // Checking that we can use moddern canvas2D api
21
+ // https://developer.chrome.com/origintrials/#/view_trial/3585991203293757441
22
+ // note: this is unstable API, Chrome less 94 use a `textLetterSpacing`, newest use a letterSpacing
23
+ // eslint-disable-next-line max-len
24
+ var supportLetterSpacing = 'letterSpacing' in CanvasRenderingContext2D.prototype
25
+ || 'textLetterSpacing' in CanvasRenderingContext2D.prototype;
26
+
27
+ if ((letterSpacing === 0 || supportLetterSpacing) && (!this.fillCustomColors || this.fillCustomColors.length === 0)) { //colors patch in if state
28
+ if (supportLetterSpacing) {
29
+ this.context.letterSpacing = letterSpacing;
30
+ this.context.textLetterSpacing = letterSpacing;
31
+ }
32
+ if (isStroke) {
33
+ this.context.strokeText(text, x, y);
34
+ }
35
+ else {
36
+ this.context.fillText(text, x, y);
37
+ }
38
+ return;
39
+ }
40
+ var currentPosition = x;
41
+
42
+ var customColors = [];//colors patch block
43
+ var textIndexOffset = this.text.indexOf(text);
44
+ if (this.fillCustomColors) {
45
+ for (var k in this.fillCustomColors){
46
+ var colorsParams = this.fillCustomColors[k];
47
+ customColors[colorsParams.position] = colorsParams.color;
48
+ }
49
+ }
50
+
51
+ // Using Array.from correctly splits characters whilst keeping emoji together.
52
+ // This is not supported on IE as it requires ES6, so regular text splitting occurs.
53
+ // This also doesn't account for emoji that are multiple emoji put together to make something else.
54
+ // Handling all of this would require a big library itself.
55
+ // https://medium.com/@giltayar/iterating-over-emoji-characters-the-es6-way-f06e4589516
56
+ // https://github.com/orling/grapheme-splitter
57
+ var stringArray = Array.from ? Array.from(text) : text.split('');
58
+ var previousWidth = this.context.measureText(text).width;
59
+ var currentWidth = 0;
60
+ for (var i = 0; i < stringArray.length; ++i) {
61
+ var currentChar = stringArray[i];
62
+
63
+ if (isStroke) {
64
+ this.context.strokeText(currentChar, currentPosition, y);
65
+ }
66
+ else {
67
+ if (customColors[textIndexOffset + i]) { //colors patch block
68
+ this.context.fillStyle = customColors[textIndexOffset + i];
69
+ }
70
+
71
+ this.context.fillText(currentChar, currentPosition, y);
72
+ }
73
+ currentWidth = this.context.measureText(text.substring(i + 1)).width;
74
+ currentPosition += previousWidth - currentWidth + letterSpacing;
75
+ previousWidth = currentWidth;
76
+ }
77
+ };
@@ -31,6 +31,7 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
31
31
  this.keyDownAction = Urso.helper.recursiveGet('keyDownAction', params, false);
32
32
  this.mouseOverAction = Urso.helper.recursiveGet('mouseOverAction', params, false);
33
33
  this.mouseOutAction = Urso.helper.recursiveGet('mouseOutAction', params, false);
34
+ this.noActionOnMouseOut = Urso.helper.recursiveGet('noActionOnMouseOut', params, Urso.device.desktop ? true : false);
34
35
 
35
36
  this.buttonFrames = {
36
37
  over: Urso.helper.recursiveGet('buttonFrames.over', params, false),
@@ -48,9 +49,9 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
48
49
 
49
50
  if (this._isOver)
50
51
  this._changeTexture('over');
51
- else if(this._isDown)
52
+ else if (this._isDown)
52
53
  this._changeTexture('pressed');
53
- else if(this._isDisabled)
54
+ else if (this._isDisabled)
54
55
  this._changeTexture('disabled');
55
56
  else
56
57
  this._changeTexture('out');
@@ -66,6 +67,7 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
66
67
  this._changeTexture('out');
67
68
 
68
69
  this._isDisabled = false;
70
+ this._baseObject.buttonMode = true;
69
71
  }
70
72
 
71
73
  disable() {
@@ -74,6 +76,7 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
74
76
 
75
77
  this._changeTexture('disabled');
76
78
  this._isDisabled = true;
79
+ this._baseObject.buttonMode = false;
77
80
  }
78
81
 
79
82
  _addBaseObject() {
@@ -121,8 +124,10 @@ class ModulesObjectsModelsButton extends Urso.Core.Modules.Objects.BaseModel {
121
124
 
122
125
  this._isDown = false;
123
126
 
124
- if (this.action)
125
- this.action();
127
+ if (this.action) {
128
+ if (!this.noActionOnMouseOut || this._isOver) //if noActionOnMouseOut && mouse is out of button -> do nothing
129
+ this.action();
130
+ }
126
131
 
127
132
  if (this._isDisabled) //can be disabled after action
128
133
  return false;
@@ -20,6 +20,7 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
20
20
  this.fontStyle = Urso.helper.recursiveGet('fontStyle', params, false); //'italic'
21
21
  this.fontWeight = Urso.helper.recursiveGet('fontWeight', params, false); // 'bold'
22
22
  this.fill = Urso.helper.recursiveGet('fill', params, '#000000'); // gradient ['#ffffff', '#00ff99']
23
+ this.fillCustomColors = Urso.helper.recursiveGet('fillCustomColors', params, false); //or array [{position:12,color:'#000000'},...]
23
24
  this.stroke = Urso.helper.recursiveGet('stroke', params, 'black');
24
25
  this.strokeThickness = Urso.helper.recursiveGet('strokeThickness', params, 0);
25
26
  this.dropShadow = Urso.helper.recursiveGet('dropShadow', params, false);
@@ -38,6 +39,10 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
38
39
  this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
39
40
 
40
41
  this._baseObject = new PIXI.Text(this.text);
42
+
43
+ if (this.fillCustomColors) {
44
+ this._baseObject.fillCustomColors = this.fillCustomColors;
45
+ }
41
46
  };
42
47
 
43
48
  _newLocaleHandler() {
@@ -161,6 +161,7 @@ class ModulesObjectsProxy {
161
161
  'fontStyle': 'style.fontStyle',
162
162
  'fontWeight': 'style.fontWeight',
163
163
  'fill': 'style.fill',
164
+ 'fillCustomColors': 'fillCustomColors',
164
165
  'stroke': 'style.stroke',
165
166
  'strokeThickness': 'style.strokeThickness',
166
167
  'dropShadow': 'style.dropShadow',
@@ -3,6 +3,7 @@ class ModulesObserverConfig {
3
3
  this.singleton = true;
4
4
 
5
5
  this.list = {
6
+ COMPONENTS_FULLSCREEN_CHANGE: 'components.fullscreen.change',
6
7
  MODULES_ASSETS_GROUP_LOADED: 'modules.assets.group.loaded',
7
8
  MODULES_ASSETS_LOAD_PROGRESS: 'modules.assets.load.progress',
8
9
  MODULES_ASSETS_LAZYLOAD_FINISHED: 'modules.assets.lazyLoad.finished',