@urso/core 0.2.1-dev → 0.2.5

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.
@@ -0,0 +1,169 @@
1
+
2
+ const UrsoCoreModulesObjectsModelsButton = require('./button');
3
+
4
+ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
5
+ constructor(params) {
6
+ super(params);
7
+
8
+ this._toggleStatus = 'unpressed';
9
+
10
+ this.type = Urso.types.objects.TOGGLE;
11
+ this._addBaseObject();
12
+
13
+ this.enable = this.enable.bind(this);
14
+ this.disable = this.disable.bind(this);
15
+ }
16
+
17
+ setupParams(params) {
18
+ super.setupParams(params);
19
+
20
+ this.action = Urso.helper.recursiveGet('action', params, () => {
21
+ this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this._toggleStatus })
22
+ });
23
+
24
+ this.buttonFrames = {
25
+ pressedOver: Urso.helper.recursiveGet('buttonFrames.pressedOver', params, false),
26
+ pressedOut: Urso.helper.recursiveGet('buttonFrames.pressedOut', params, false),
27
+ unpressedOver: Urso.helper.recursiveGet('buttonFrames.unpressedOver', params, false),
28
+ unpressedOut: Urso.helper.recursiveGet('buttonFrames.unpressedOut', params, false),
29
+ pressedDown: Urso.helper.recursiveGet('buttonFrames.pressedDown', params, false),
30
+ unpressedDown: Urso.helper.recursiveGet('buttonFrames.unpressedDown', params, false),
31
+ pressedDisabled: Urso.helper.recursiveGet('buttonFrames.pressedDisabled', params, false),
32
+ unpressedDisabled: Urso.helper.recursiveGet('buttonFrames.unpressedDisabled', params, false),
33
+ }
34
+ }
35
+
36
+ setButtonFrame(key, assetKey) {
37
+ this.buttonFrames[key] = assetKey;
38
+
39
+ if (this._isOver)
40
+ this._changeTexture(`${this._toggleStatus}Over`);
41
+ else if(this._isDown)
42
+ this._changeTexture(`${this._toggleStatus}Down`);
43
+ else if(this._isDisabled)
44
+ this._changeTexture(`${this._toggleStatus}Disabled`);
45
+ else
46
+ this._changeTexture(`${this._toggleStatus}Out`);
47
+ }
48
+
49
+ enable() {
50
+ if (!this._isDisabled)
51
+ return false;
52
+
53
+ if (this._isOver)
54
+ this._changeTexture(`${this._toggleStatus}Over`);
55
+ else
56
+ this._changeTexture(`${this._toggleStatus}Out`);
57
+
58
+ this._isDisabled = false;
59
+ }
60
+
61
+ disable() {
62
+ if (this._isDisabled)
63
+ return false;
64
+
65
+ this._changeTexture(`${this._toggleStatus}Disabled`);
66
+ this._isDisabled = true;
67
+ }
68
+
69
+ _addBaseObject() {
70
+ this._baseObject = new PIXI.Sprite();
71
+ this._changeTexture('unpressedOut');
72
+
73
+ this._baseObject.interactive = true;
74
+ this._baseObject.buttonMode = true;
75
+
76
+ if (this.pixelPerfectOver) {
77
+ //todo
78
+ }
79
+
80
+ if (this.pixelPerfectClick) {
81
+ //todo
82
+ }
83
+
84
+ this._baseObject
85
+ .on('pointerdown', this._onButtonDown.bind(this))
86
+ .on('pointerup', this._onButtonUp.bind(this))
87
+ .on('pointerupoutside', this._onButtonUp.bind(this))
88
+ .on('pointerover', this._onButtonOver.bind(this))
89
+ .on('pointerout', this._onButtonOut.bind(this));
90
+ };
91
+
92
+ _onButtonDown() {
93
+ if (this._isDisabled)
94
+ return false;
95
+
96
+ this._isDown = true;
97
+
98
+ if (this.keyDownAction)
99
+ this.keyDownAction();
100
+
101
+ if (this._isDisabled) //can be disabled after keyDownAction
102
+ return false;
103
+
104
+ this._changeTexture(`${this._toggleStatus}Down`);
105
+
106
+ this._toggleStatus = this._toggleStatus === 'pressed' ? 'unpressed' : 'pressed';
107
+ }
108
+
109
+ _onButtonUp() {
110
+ if (this._isDisabled)
111
+ return false;
112
+
113
+ this._isDown = false;
114
+
115
+ if (this.action)
116
+ this.action();
117
+
118
+ if (this._isDisabled) //can be disabled after action
119
+ return false;
120
+
121
+ if (this._isOver)
122
+ this._changeTexture(`${this._toggleStatus}Over`);
123
+ else
124
+ this._changeTexture(`${this._toggleStatus}Out`);
125
+ }
126
+
127
+ _onButtonOver() {
128
+ this._isOver = true;
129
+
130
+ if (this._isDisabled || this._isDown)
131
+ return false;
132
+
133
+ if (this.mouseOverAction)
134
+ this.mouseOverAction();
135
+
136
+ this._changeTexture(`${this._toggleStatus}Over`);
137
+ }
138
+
139
+ _onButtonOut() {
140
+ this._isOver = false;
141
+
142
+ if (this._isDisabled || this._isDown)
143
+ return false;
144
+
145
+ if (this.mouseOutAction)
146
+ this.mouseOutAction();
147
+
148
+ this._changeTexture(`${this._toggleStatus}Out`);
149
+ }
150
+
151
+ _changeTexture(key) {
152
+ let texture = Urso.cache.getTexture(this.buttonFrames[key]);
153
+
154
+ if (!texture) {
155
+ if (key === `${this._toggleStatus}Out`) {
156
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
157
+ return false;
158
+ }
159
+
160
+ this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
161
+ return false;
162
+ }
163
+
164
+ this._baseObject.texture = texture;
165
+ return true;
166
+ }
167
+ }
168
+
169
+ module.exports = ModulesObjectsModelsToggle;
@@ -31,7 +31,9 @@ class PropertyAdapter {
31
31
  Urso.types.objects.COMPONENT,
32
32
  Urso.types.objects.CONTAINER,
33
33
  Urso.types.objects.GROUP,
34
- Urso.types.objects.WORLD
34
+ Urso.types.objects.WORLD,
35
+ Urso.types.objects.SLIDER,
36
+ Urso.types.objects.SCROLLBOX,
35
37
  ];
36
38
 
37
39
  this._typesWithoutAnchor = [
@@ -40,7 +42,10 @@ class PropertyAdapter {
40
42
  Urso.types.objects.HITAREA,
41
43
  Urso.types.objects.MASK,
42
44
  Urso.types.objects.SPINE,
43
- Urso.types.objects.WORLD
45
+ Urso.types.objects.SLIDER,
46
+ Urso.types.objects.TEXTINPUT,
47
+ Urso.types.objects.CHECKBOX,
48
+ Urso.types.objects.WORLD,
44
49
  ];
45
50
  }
46
51
 
@@ -8,6 +8,10 @@ class ModulesObserverConfig {
8
8
  MODULES_ASSETS_LAZYLOAD_FINISHED: 'modules.assets.lazyLoad.finished',
9
9
  MODULES_OBJECTS_BUTTON_PRESS: 'modules.objects.button.press',
10
10
  MODULES_OBJECTS_HIT_AREA_PRESS: 'modules.objects.hitArea.press',
11
+ MODULES_OBJECTS_SLIDER_SET_NEW_VALUE: 'modules.objects.slider.setNewValue',
12
+ MODULES_OBJECTS_TOGGLE_PRESS: 'modules.objects.toggle.press',
13
+ MODULES_OBJECTS_TEXTINPUT_BLUR: 'modules.objects.textinput.blur',
14
+ MODULES_OBJECTS_CHECKBOX_PRESS: 'modules.objects.checkbox.press',
11
15
  MODULES_LOGIC_SOUNDS_DO: 'modules.soundManager.do',
12
16
  MODULES_SOUND_MANAGER_UPDATE_CFG: 'modules.soundManager.updateCfg',
13
17
  MODULES_SOUND_MANAGER_SET_GLOBAL_VOLUME: 'modules.soundManager.setGlobalVolume',
@@ -22,7 +22,7 @@ class ModulesStatesManagerConfigStates {
22
22
  { action: 'showPickGame' }, //showPickGame --> addActionGuard(showPickGame, funk)
23
23
  { action: 'showBIGWin' }
24
24
  ],
25
- nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"] //setGuardState(PICK_GAME2, func)
25
+ nextState: ["PICK_GAME2", "PICK_GAME1", "IDLE"] //nextState is optional //setGuardState(PICK_GAME2, func)
26
26
  },
27
27
 
28
28
  PICK_GAME2: {
@@ -30,7 +30,7 @@ class ModulesStatesManagerConfigStates {
30
30
  { action: 'showWheel' }, //showWheel --> addActionGuard(showWheel, funk)
31
31
  { action: 'showBIGWin' }
32
32
  ],
33
- nextState: ["PICK_GAME1", "IDLE"]
33
+ nextState: ["PICK_GAME1", "IDLE"] //nextState is optional
34
34
  },
35
35
 
36
36
  WINLINES_ANIMATE_BY_ONE: { action: 'showWinlinesAnimation' },
@@ -85,7 +85,7 @@ class ModulesStatesManagerController {
85
85
 
86
86
  //actions guards
87
87
  addActionGuard(key, guard) {
88
- this.actionsGuards.add(key, guard);
88
+ this.actionsGuards.add(key, guard, true);
89
89
  }
90
90
 
91
91
  checkActionGuard(key) {
@@ -116,7 +116,7 @@ class ModulesStatesManagerController {
116
116
 
117
117
  //states guards
118
118
  setStateGuard(key, guard) {
119
- this.statesGuards.add(key, guard);
119
+ this.statesGuards.add(key, guard, true);
120
120
  }
121
121
 
122
122
  checkStateGuard(key) {
@@ -6,8 +6,8 @@ class ModulesStatesManagerFunctionsStorage {
6
6
  }
7
7
 
8
8
  //guards
9
- add(key, guard) {
10
- this._addToStorage(key, guard, true);
9
+ add(key, guard, onlyOneFlag = false) {
10
+ this._addToStorage(key, guard, onlyOneFlag);
11
11
  }
12
12
 
13
13
  run(key) {
@@ -32,7 +32,12 @@ class ModulesTemplateTypes {
32
32
  GROUP: 15,
33
33
  IMAGES_ANIMATION: 16,
34
34
  DRAGONBONES: 17,
35
- ATLASIMAGE: 18
35
+ ATLASIMAGE: 18,
36
+ SLIDER: 19,
37
+ TOGGLE: 20,
38
+ CHECKBOX: 21,
39
+ SCROLLBOX: 22,
40
+ TEXTINPUT: 23
36
41
  }
37
42
  }
38
43
  }
@@ -1,7 +0,0 @@
1
- class ComponentsStateDrivenActionConfig {
2
-
3
- //TODO run logic and save finish callback and autocall it
4
-
5
- }
6
-
7
- module.exports = ComponentsStateDrivenActionConfig;