@urso/core 0.7.55 → 0.7.57

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.7.55",
3
+ "version": "0.7.57",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -98,6 +98,7 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
98
98
  //do not forget use super._subscribeOnce() , if you will use _subscribeOnce in the component
99
99
  this._processStates();
100
100
  this._processActions();
101
+ this.addListener(Urso.events.MODULES_STATES_MANAGER_STOP, this._onStatesManagerStop.bind(this), true);
101
102
  }
102
103
 
103
104
  destroy() {
@@ -113,6 +114,10 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
113
114
  }
114
115
  }
115
116
 
117
+ _onStatesManagerStop() {
118
+ this._finishCallbacks = {};
119
+ }
120
+
116
121
  }
117
122
 
118
123
  module.exports = ComponentsStateDrivenController;
@@ -522,6 +522,7 @@ class LibHelper {
522
522
 
523
523
  if (a !== 0 && b !== 0) {
524
524
  const cornerRcos = (a * a + b * b - c * c) / (2 * a * b);
525
+ Urso.math.intMakeBetween(cornerRcos, -1, 1);
525
526
  angle = Math.acos(cornerRcos);
526
527
  }
527
528
 
@@ -606,7 +607,7 @@ class LibHelper {
606
607
  * @returns { Object }
607
608
  */
608
609
  getRGB(color) {
609
- return {
610
+ return {
610
611
  alpha: 16777215 < color ? color >>> 24 : 255,
611
612
  red: color >> 16 & 255,
612
613
  green: color >> 8 & 255,
@@ -634,7 +635,7 @@ class LibHelper {
634
635
  * @returns { Number }
635
636
  */
636
637
  interpolateColor32(startColor, targetColor, step) {
637
- if(startColor === targetColor)
638
+ if (startColor === targetColor)
638
639
  return startColor;
639
640
 
640
641
  const startColorRGB = this.getRGB(startColor);
@@ -38,6 +38,7 @@ class ModulesObserverConfig {
38
38
  MODULES_STATES_MANAGER_STATE_CHANGE: 'modules.statesManager.stateChange',
39
39
  MODULES_STATES_MANAGER_ACTION_START: 'modules.statesManager.actionStart',
40
40
  MODULES_STATES_MANAGER_ACTION_FINISH: 'modules.statesManager.actionFinish',
41
+ MODULES_STATES_MANAGER_STOP: 'modules.statesManager.stop',
41
42
  MODULES_SCENES_ORIENTATION_CHANGE: 'modules.scenes.orientation.change',
42
43
  MODULES_SCENES_NEW_RESOLUTION: 'modules.scenes.newResolution',
43
44
  MODULES_SCENES_NEW_SCENE_INIT: 'modules.scenes.newSceneInit',
@@ -46,6 +46,9 @@ class ModulesStatesManagerAction {
46
46
  }
47
47
 
48
48
  terminate() {
49
+ if(this._forceDestroying)
50
+ return;
51
+
49
52
  if (!this._running) {
50
53
  Urso.logger.warn('ModulesStatesManagerAction: action run from terminating', this.name);
51
54
  this.run(() => { });
@@ -62,6 +65,9 @@ class ModulesStatesManagerAction {
62
65
  }
63
66
 
64
67
  _onFinish() {
68
+ if(this._forceDestroying)
69
+ return;
70
+
65
71
  if (this.finished) {
66
72
  Urso.logger.error('ModulesStatesManagerAction: action alredy finished', this.name);
67
73
  return;
@@ -77,6 +83,15 @@ class ModulesStatesManagerAction {
77
83
  log(`%c action finish <--- ${this.name} (${elapsedTime}ms)`, 'color: blue');
78
84
  this._onFinishCallback();
79
85
  }
86
+
87
+ // Interrupts currently active actions on states manager stop
88
+ forceDestroy() {
89
+ if(this._forceDestroying || !this._running)
90
+ return;
91
+
92
+ this._forceDestroying = true;
93
+ log(`%c action forceDestroyed <--- ${this.name}`, 'color: #F39986');
94
+ }
80
95
  }
81
96
 
82
97
  module.exports = ModulesStatesManagerAction;
@@ -5,6 +5,7 @@ class ModulesStatesManagerController {
5
5
 
6
6
  this._configStates;
7
7
  this._currentState;
8
+ this._currentAction;
8
9
  this._forceNextStateKey = null;
9
10
  this._started = false;
10
11
  this._paused = false;
@@ -32,6 +33,21 @@ class ModulesStatesManagerController {
32
33
  this._nextState();
33
34
  }
34
35
 
36
+ restart() {
37
+ this.stop();
38
+
39
+ this._started = false;
40
+ this._paused = false;
41
+
42
+ this.start();
43
+ }
44
+
45
+ stop() {
46
+ this._currentAction && this._currentAction.forceDestroy();
47
+ this._currentAction = null;
48
+ this.emit(Urso.events.MODULES_STATES_MANAGER_STOP);
49
+ }
50
+
35
51
  pause() {
36
52
  this._paused = true;
37
53
  }
@@ -56,7 +72,6 @@ class ModulesStatesManagerController {
56
72
  _iteratorConstructor() {
57
73
  let nextIndex = 0;
58
74
 
59
-
60
75
  const getNextStateByOrder = () => {
61
76
  let statesArray = Object.keys(this._configStates);
62
77
 
@@ -132,7 +147,8 @@ class ModulesStatesManagerController {
132
147
  //actions instances guard
133
148
  if (!classInstance.guard())
134
149
  return this._nextState();
135
-
150
+
151
+ this._currentAction = classInstance;
136
152
  classInstance.run(this._nextState);
137
153
  }
138
154
 
@@ -54,7 +54,7 @@ class ModulesStatesManagerRace extends Action {
54
54
  }
55
55
 
56
56
  terminate() {
57
- if (this._terminating)
57
+ if (this._terminating || this._forceDestroying)
58
58
  return;
59
59
 
60
60
  log(`%c action terminate X ${this.name}`, 'color: orange');
@@ -67,11 +67,25 @@ class ModulesStatesManagerRace extends Action {
67
67
  }
68
68
 
69
69
  _onFinish() {
70
+ if(this._forceDestroying)
71
+ return;
72
+
70
73
  this.finished = true;
71
74
  const elapsedTime = Urso.time.get() - this._startTime;
72
75
  log(`%c action finish <--- ${this.name} (${elapsedTime}ms)`, 'color: orange');
73
76
  this._onFinishCallback();
74
77
  }
78
+
79
+ // Interrupts currently active actions on states manager stop
80
+ forceDestroy() {
81
+ this._forceDestroying = true;
82
+
83
+ for (let action of this._actions)
84
+ if (!action.finished)
85
+ action.forceDestroy();
86
+
87
+ log(`%c action forceDestroyed <--- ${this.name}`, 'color: #F39986');
88
+ }
75
89
  }
76
90
 
77
91
  module.exports = ModulesStatesManagerRace;
@@ -32,7 +32,7 @@ class ModulesStatesManagerSequence extends All {
32
32
  }
33
33
 
34
34
  terminate() {
35
- if (this._terminating)
35
+ if (this._terminating || this._forceDestroying)
36
36
  return;
37
37
 
38
38
  log(`%c action terminate X ${this.name}`, 'color: orange');