@urso/core 0.3.0 → 0.3.4

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.0",
3
+ "version": "0.3.4",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -27,11 +27,11 @@
27
27
  "howler": "^2.2.1",
28
28
  "pixi-particles": "^4.3.0",
29
29
  "pixi-projection": "0.3.15",
30
- "pixi-spine": "^3.0.13",
31
- "pixi.js": "^6.2.0",
32
30
  "pixi-scrollbox": "^2.3.1",
31
+ "pixi-spine": "^3.0.13",
32
+ "pixi-text-input": "^1.0.6",
33
33
  "pixi-viewport": "^4.34.0",
34
- "pixi-text-input": "^1.0.6"
34
+ "pixi.js": "^6.2.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.12.10",
@@ -22,7 +22,7 @@ class ModulesObjectsModelsCheckbox extends UrsoCoreModulesObjectsModelsToggle {
22
22
  this.contents = [];
23
23
 
24
24
  this.action = Urso.helper.recursiveGet('action', params, () => {
25
- this.emit(Urso.events.MODULES_OBJECTS_CHECKBOX_PRESS, { name: this.name, status: this._toggleStatus })
25
+ this.emit(Urso.events.MODULES_OBJECTS_CHECKBOX_PRESS, { name: this.name, status: this.status })
26
26
  });
27
27
 
28
28
  this.lable = Urso.helper.recursiveGet('lable', params, false);
@@ -31,7 +31,7 @@ class ModulesObjectsModelsCheckbox extends UrsoCoreModulesObjectsModelsToggle {
31
31
  }
32
32
 
33
33
  _createCheckbox() {
34
- this._toggleStatus = this.defaultStatus;
34
+ this.status = this.defaultStatus;
35
35
  this._checkbox = this._createObject(this.buttonFrames[`${this.defaultStatus}Out`])
36
36
 
37
37
  if (this.lable)
@@ -77,14 +77,15 @@ class ModulesObjectsModelsCheckbox extends UrsoCoreModulesObjectsModelsToggle {
77
77
 
78
78
  _changeTexture(key) {
79
79
  if (!this.buttonFrames[key]) {
80
- if (key === `${this._toggleStatus}Out`) {
80
+ if (key === `${this.status}Out`) {
81
81
  Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
82
82
  return false;
83
83
  }
84
84
 
85
- this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
85
+ this._changeTexture(`${this.status}Out`); // load default texture for this key
86
86
  return false;
87
87
  }
88
+
88
89
  if (this.buttonFrames[key].type === Urso.types.objects.GRAPHICS)
89
90
  this._drawGraphics(this.buttonFrames[key].figure);
90
91
  else
@@ -188,7 +188,7 @@ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
188
188
  this.currentValueText.text = value;
189
189
 
190
190
  this._setFillMask();
191
- this.emit(Urso.events.MODULES_OBJECTS_SLIDER_SET_NEW_VALUE, { name: this.name, value: value });
191
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_SET_NEW_VALUE, { name: this.name, value: value, class: this.class });
192
192
  }
193
193
 
194
194
  _subscribeOnce() {
@@ -16,6 +16,7 @@ class ModulesObjectsModelsTextInput extends Urso.Core.Modules.Objects.BaseModel
16
16
  this.numbersOnly = Urso.helper.recursiveGet('numbersOnly', params, false);
17
17
  this.allowedSymbols = Urso.helper.recursiveGet('allowedSymbols', params, false);
18
18
  this.substituteText = Urso.helper.recursiveGet('substituteText', params, false);
19
+ this.maxLength = Urso.helper.recursiveGet('maxLength', params, false);
19
20
  }
20
21
 
21
22
  restrictInput(allowedSymbols) {
@@ -40,15 +41,25 @@ class ModulesObjectsModelsTextInput extends Urso.Core.Modules.Objects.BaseModel
40
41
  }
41
42
 
42
43
  _onBlur(){
43
- this.text = this._baseObject.text;
44
44
  const data = {name: this.name, class: this.class, id: this.id, text: this.text};
45
45
  this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_BLUR, data);
46
46
  }
47
47
 
48
+ _onInput() {
49
+ this.text = this._baseObject.text;
50
+ const data = {name: this.name, class: this.class, id: this.id, text: this.text};
51
+ this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_INPUT, data);
52
+ }
53
+
48
54
  _addBaseObject() {
49
55
  this._baseObject = new PIXI.TextInput({ input: this.input, box: this.box });
50
56
  this._baseObject.substituteText = this.substituteText;
57
+
58
+ if(this.maxLength)
59
+ this._baseObject.maxLength = this.maxLength
60
+
51
61
  this._baseObject.on('blur', this._onBlur.bind(this))
62
+ this._baseObject.on('input', this._onInput.bind(this))
52
63
  };
53
64
  }
54
65
 
@@ -5,7 +5,7 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
5
5
  constructor(params) {
6
6
  super(params);
7
7
 
8
- this._toggleStatus = 'unpressed';
8
+ this.status = 'unpressed';
9
9
 
10
10
  this.type = Urso.types.objects.TOGGLE;
11
11
  this._addBaseObject();
@@ -18,7 +18,7 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
18
18
  super.setupParams(params);
19
19
 
20
20
  this.action = Urso.helper.recursiveGet('action', params, () => {
21
- this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this._toggleStatus })
21
+ this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this.status })
22
22
  });
23
23
 
24
24
  this.buttonFrames = {
@@ -37,13 +37,13 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
37
37
  this.buttonFrames[key] = assetKey;
38
38
 
39
39
  if (this._isOver)
40
- this._changeTexture(`${this._toggleStatus}Over`);
40
+ this._changeTexture(`${this.status}Over`);
41
41
  else if(this._isDown)
42
- this._changeTexture(`${this._toggleStatus}Down`);
42
+ this._changeTexture(`${this.status}Down`);
43
43
  else if(this._isDisabled)
44
- this._changeTexture(`${this._toggleStatus}Disabled`);
44
+ this._changeTexture(`${this.status}Disabled`);
45
45
  else
46
- this._changeTexture(`${this._toggleStatus}Out`);
46
+ this._changeTexture(`${this.status}Out`);
47
47
  }
48
48
 
49
49
  enable() {
@@ -51,9 +51,9 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
51
51
  return false;
52
52
 
53
53
  if (this._isOver)
54
- this._changeTexture(`${this._toggleStatus}Over`);
54
+ this._changeTexture(`${this.status}Over`);
55
55
  else
56
- this._changeTexture(`${this._toggleStatus}Out`);
56
+ this._changeTexture(`${this.status}Out`);
57
57
 
58
58
  this._isDisabled = false;
59
59
  }
@@ -62,7 +62,7 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
62
62
  if (this._isDisabled)
63
63
  return false;
64
64
 
65
- this._changeTexture(`${this._toggleStatus}Disabled`);
65
+ this._changeTexture(`${this.status}Disabled`);
66
66
  this._isDisabled = true;
67
67
  }
68
68
 
@@ -101,9 +101,9 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
101
101
  if (this._isDisabled) //can be disabled after keyDownAction
102
102
  return false;
103
103
 
104
- this._changeTexture(`${this._toggleStatus}Down`);
104
+ this._changeTexture(`${this.status}Down`);
105
105
 
106
- this._toggleStatus = this._toggleStatus === 'pressed' ? 'unpressed' : 'pressed';
106
+ this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
107
107
  }
108
108
 
109
109
  _onButtonUp() {
@@ -119,9 +119,9 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
119
119
  return false;
120
120
 
121
121
  if (this._isOver)
122
- this._changeTexture(`${this._toggleStatus}Over`);
122
+ this._changeTexture(`${this.status}Over`);
123
123
  else
124
- this._changeTexture(`${this._toggleStatus}Out`);
124
+ this._changeTexture(`${this.status}Out`);
125
125
  }
126
126
 
127
127
  _onButtonOver() {
@@ -133,7 +133,7 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
133
133
  if (this.mouseOverAction)
134
134
  this.mouseOverAction();
135
135
 
136
- this._changeTexture(`${this._toggleStatus}Over`);
136
+ this._changeTexture(`${this.status}Over`);
137
137
  }
138
138
 
139
139
  _onButtonOut() {
@@ -145,19 +145,28 @@ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
145
145
  if (this.mouseOutAction)
146
146
  this.mouseOutAction();
147
147
 
148
- this._changeTexture(`${this._toggleStatus}Out`);
148
+ this._changeTexture(`${this.status}Out`);
149
+ }
150
+
151
+ swithStatus() {
152
+ this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
153
+
154
+ if (this._isOver)
155
+ this._changeTexture(`${this.status}Over`);
156
+ else
157
+ this._changeTexture(`${this.status}Out`);
149
158
  }
150
159
 
151
160
  _changeTexture(key) {
152
161
  let texture = Urso.cache.getTexture(this.buttonFrames[key]);
153
162
 
154
163
  if (!texture) {
155
- if (key === `${this._toggleStatus}Out`) {
164
+ if (key === `${this.status}Out`) {
156
165
  Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
157
166
  return false;
158
167
  }
159
168
 
160
- this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
169
+ this._changeTexture(`${this.status}Out`); // load default texture for this key
161
170
  return false;
162
171
  }
163
172
 
@@ -12,11 +12,14 @@ class ModulesObserverConfig {
12
12
  MODULES_OBJECTS_SLIDER_SET_NEW_VALUE: 'modules.objects.slider.setNewValue',
13
13
  MODULES_OBJECTS_TOGGLE_PRESS: 'modules.objects.toggle.press',
14
14
  MODULES_OBJECTS_TEXTINPUT_BLUR: 'modules.objects.textinput.blur',
15
+ MODULES_OBJECTS_TEXTINPUT_INPUT: 'modules.objects.textinput.input',
15
16
  MODULES_OBJECTS_CHECKBOX_PRESS: 'modules.objects.checkbox.press',
16
17
  MODULES_LOGIC_SOUNDS_DO: 'modules.soundManager.do',
17
18
  MODULES_SOUND_MANAGER_UPDATE_CFG: 'modules.soundManager.updateCfg',
18
19
  MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME: 'modules.soundManager.setGlobalVolume',
19
20
  MODULES_STATES_MANAGER_STATE_CHANGE: 'modules.statesManager.stateChange',
21
+ MODULES_STATES_MANAGER_ACTION_START: 'modules.statesManager.actionStart',
22
+ MODULES_STATES_MANAGER_ACTION_FINISH: 'modules.statesManager.actionFinish',
20
23
  MODULES_SCENES_ORIENTATION_CHANGE: 'modules.scenes.orientation.change',
21
24
  MODULES_SCENES_NEW_RESOLUTION: 'modules.scenes.newResolution',
22
25
  MODULES_SCENES_NEW_SCENE_INIT: 'modules.scenes.newSceneInit',
@@ -18,6 +18,8 @@ class ModulesStatesManagerAction {
18
18
  run(onFinishCallback) {
19
19
  log(`%c action run ---> ${this.name}`, 'color: blue');
20
20
 
21
+ this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_START, this.name);
22
+
21
23
  this.finished = false;
22
24
  this._onFinishCallback = onFinishCallback;
23
25
 
@@ -47,6 +49,9 @@ class ModulesStatesManagerAction {
47
49
 
48
50
  this._terminating = false;
49
51
  this.finished = true;
52
+
53
+ this.emit(Urso.events.MODULES_STATES_MANAGER_ACTION_FINISH, this.name);
54
+
50
55
  log(`%c action finish <--- ${this.name}`, 'color: blue');
51
56
  this._onFinishCallback();
52
57
  }
@@ -27,6 +27,16 @@ class ModulesStatesManagerController {
27
27
 
28
28
  _iteratorConstructor() {
29
29
  let nextIndex = 0;
30
+
31
+
32
+ const getNextStateByOrder = () => {
33
+ let statesArray = Object.keys(this._configStates);
34
+
35
+ if (nextIndex === statesArray.length)
36
+ nextIndex = 0;
37
+
38
+ return statesArray[nextIndex++];
39
+ }
30
40
 
31
41
  return {
32
42
  next: (() => {
@@ -36,7 +46,7 @@ class ModulesStatesManagerController {
36
46
  if (this._currentState) {
37
47
  const currentState = this._configStates[this._currentState];
38
48
 
39
- if (this.checkStateGuard(this._currentState) && currentState.nextState) { //nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"]
49
+ if (currentState.nextState) { //nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"]
40
50
  for (const stateKey of currentState.nextState) {
41
51
  if (this.checkStateGuard(stateKey)) {
42
52
  nextIndex = statesArray.indexOf(stateKey) + 1;
@@ -52,11 +62,14 @@ class ModulesStatesManagerController {
52
62
  }
53
63
  }
54
64
 
55
- //regular round logic
56
- if (nextIndex === statesArray.length)
57
- nextIndex = 0;
65
+ //go next state by order
66
+ let stateName;
58
67
 
59
- return statesArray[nextIndex++];
68
+ do {
69
+ stateName = getNextStateByOrder();
70
+ } while (!this.checkStateGuard(stateName));
71
+
72
+ return stateName;
60
73
  }).bind(this)
61
74
  }
62
75
  }
@@ -71,10 +84,6 @@ class ModulesStatesManagerController {
71
84
  let config = this._configStates[this._currentState];
72
85
  let classInstance = this.getInstance('Helper').getActionByConfig(config);
73
86
 
74
- //state guard
75
- if (!this.checkStateGuard(this._currentState))
76
- return this._nextState();
77
-
78
87
  //actions instances guard
79
88
  if (!classInstance.guard())
80
89
  return this._nextState();
@@ -1,22 +1,13 @@
1
1
  class ModulesTransportConfig {
2
- constructor() {
3
- this._setDefaultConfig();
4
- }
5
2
 
6
3
  getConfig() {
7
- return this._config;
8
- };
9
-
10
- _setDefaultConfig() {
11
- this._config = {
12
- autoReconnection: true,
13
- autoReconnectionDelay: 5000,
14
- hosts: {
15
- wsHost: Urso.helper.parseGetParams('wsHost') || 'ws://localhost:9100/',
16
- xhrHost: 'https://reqres.in/api/users/2'
4
+ return {
5
+ autoReconnect: true,
6
+ reconnectTimeout: 5000,
7
+ type: 'websocket', // websocket | xhr
8
+ host: Urso.helper.parseGetParams('wsHost')
17
9
  }
18
- };
19
- };
10
+ }
20
11
  }
21
12
 
22
13
  module.exports = ModulesTransportConfig;
@@ -4,6 +4,7 @@ class ModulesTransportConnectionTypesXhr extends Urso.Core.Modules.Transport.Bas
4
4
 
5
5
  this._xhr = null;
6
6
  this._ready = true;
7
+ this._runCallback('ready');
7
8
  }
8
9
 
9
10
  send(message){
@@ -13,13 +14,15 @@ class ModulesTransportConnectionTypesXhr extends Urso.Core.Modules.Transport.Bas
13
14
  log('[XHR] SEND:', preparedMessage);
14
15
  };
15
16
 
17
+ _getMethod(){
18
+ return 'POST';
19
+ };
16
20
 
17
21
  _createXhr(){
18
22
  this._xhr = new XMLHttpRequest();
19
23
  this._xhr.onerror = this._onError.bind(this);
20
24
  this._xhr.onreadystatechange = this._onReadyStateChange.bind(this);
21
- this._xhr.open('GET', this._host, true);
22
- log('[XHR]: CREATED');
25
+ this._xhr.open(this._getMethod(), this._host, true);
23
26
  };
24
27
 
25
28
  _onMessage(message){
@@ -1,5 +1,6 @@
1
1
  class ModulesTransportDecorator {
2
- constructor() {
2
+ constructor({ callbacks }) {
3
+ this._callbacks = callbacks;
3
4
  this.singleton = true;
4
5
  }
5
6
 
@@ -2,10 +2,6 @@ class ModulesTransportService {
2
2
  constructor() {
3
3
  this._callbacks = {};
4
4
  this._config = this.getInstance('Config').getConfig();
5
-
6
- this.WEBSOCKET = 'websocket';
7
- this.XHR = 'xhr';
8
-
9
5
  this._communicator = null;
10
6
  }
11
7
 
@@ -15,17 +11,25 @@ class ModulesTransportService {
15
11
  };
16
12
 
17
13
  init() {
18
- if(Urso.config.useTransport){
19
- this._createConnection();
20
- }
14
+ this._createConnection();
21
15
  };
22
16
 
23
17
  send(message) {
24
18
  if (!this._checkCommunicator() || !this._checkCommunicatorReady())
25
19
  return false;
26
20
 
27
- const decoratedMessage = this.getInstance('Decorator').toServer(message);
21
+ const decoratedMessage = this.getInstance('Decorator', { callbacks: this._callbacks }).toServer(message);
22
+
23
+ if(!decoratedMessage) {
24
+ return false;
25
+ }
26
+
28
27
  const validatedMessage = this._validateMessage(decoratedMessage);
28
+
29
+ if(!validatedMessage) {
30
+ return false;
31
+ }
32
+
29
33
  this._communicator.send(validatedMessage);
30
34
 
31
35
  return true;
@@ -35,7 +39,7 @@ class ModulesTransportService {
35
39
  if (!this._checkCommunicator())
36
40
  return false;
37
41
 
38
- this._communicator.reconnect(this._config.autoReconnectionDelay || 0);
42
+ this._communicator.reconnect(this._getAutoReconnetionDelay());
39
43
 
40
44
  return true;
41
45
  };
@@ -85,7 +89,12 @@ class ModulesTransportService {
85
89
  _runMiddleWare(event, data) {
86
90
  switch (event) {
87
91
  case 'response':
88
- const decoratedMessage = this.getInstance('Decorator').toFront(JSON.parse(data));
92
+ const decoratedMessage = this.getInstance('Decorator', { callbacks: this._callbacks }).toFront(data);
93
+
94
+ if(!decoratedMessage) {
95
+ return;
96
+ }
97
+
89
98
  return this._validateMessage(decoratedMessage);
90
99
 
91
100
  case 'close':
@@ -96,11 +105,19 @@ class ModulesTransportService {
96
105
  }
97
106
  };
98
107
 
108
+ _autoReconnectCheck() {
109
+ return this._config.reconnectTimeout;
110
+ }
111
+
112
+ _getAutoReconnetionDelay() {
113
+ return this._config.autoReconnect || 0;
114
+ }
115
+
99
116
  _tryReconnect() {
100
- if (!this._config.autoReconnection)
117
+ if (!this._autoReconnectCheck())
101
118
  return false;
102
119
 
103
- this._communicator.reconnect(this._config.autoReconnectionDelay);
120
+ this._communicator.reconnect(this._getAutoReconnetionDelay());
104
121
  };
105
122
 
106
123
  _setCallback(event, callback) {
@@ -112,24 +129,20 @@ class ModulesTransportService {
112
129
  return { ...message };
113
130
  };
114
131
 
115
- _getHost(type) {
116
- const hosts = this._config.hosts;
117
-
118
- switch (type) {
119
- case this.WEBSOCKET:
120
- return hosts.wsHost;
121
- case this.XHR:
122
- return hosts.xhrHost;
123
- default:
124
- return false;
125
- }
132
+ _getHost() {
133
+ return this._config.host;
126
134
  };
127
135
 
128
- _createConnection(type = this.WEBSOCKET) {
129
- const host = this._getHost(type);
136
+ _getType() {
137
+ return this._config.type;
138
+ }
139
+
140
+ _createConnection() {
141
+ const host = this._getHost();
142
+ const type = this._getType();
130
143
  const callbacks = this._callbacks;
131
144
  const capitalizedType = Urso.helper.capitaliseFirstLetter(type);
132
-
145
+
133
146
  this._communicator = this.getInstance(`ConnectionTypes.${capitalizedType}`, { callbacks, host });
134
147
 
135
148
  if (!this._communicator)