@urso/core 0.7.90 → 0.7.91

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.
Files changed (133) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +227 -227
  4. package/build/js/index.js +1 -1
  5. package/package.json +50 -50
  6. package/src/js/app.js +104 -104
  7. package/src/js/components/base/controller.js +78 -78
  8. package/src/js/components/debug/controller.js +38 -38
  9. package/src/js/components/debug/coords.js +23 -23
  10. package/src/js/components/debug/fps.js +36 -36
  11. package/src/js/components/debug/template.js +55 -55
  12. package/src/js/components/debug/timescale.js +60 -60
  13. package/src/js/components/deviceRotate/controller.js +95 -95
  14. package/src/js/components/editor/api.js +127 -127
  15. package/src/js/components/editor/controller.js +12 -12
  16. package/src/js/components/fullscreen/android.js +104 -104
  17. package/src/js/components/fullscreen/controller.js +76 -76
  18. package/src/js/components/fullscreen/desktop.js +49 -49
  19. package/src/js/components/fullscreen/ios.js +115 -115
  20. package/src/js/components/layersSwitcher/config.js +26 -26
  21. package/src/js/components/layersSwitcher/controller.js +36 -36
  22. package/src/js/components/loader/controller.js +66 -66
  23. package/src/js/components/loader/template.js +70 -70
  24. package/src/js/components/soundInitialPopup/controller.js +42 -42
  25. package/src/js/components/soundInitialPopup/template.js +109 -109
  26. package/src/js/components/stateDriven/controller.js +123 -123
  27. package/src/js/config/load.js +194 -194
  28. package/src/js/config/main.js +17 -17
  29. package/src/js/extra/browserEvents.js +57 -57
  30. package/src/js/extra/main.js +19 -19
  31. package/src/js/extra/pixiPatch.js +171 -171
  32. package/src/js/index.js +7 -7
  33. package/src/js/lib/cache.js +125 -125
  34. package/src/js/lib/composition.js +85 -85
  35. package/src/js/lib/device.js +1215 -1215
  36. package/src/js/lib/helper.js +678 -678
  37. package/src/js/lib/loader.js +211 -211
  38. package/src/js/lib/localData.js +28 -28
  39. package/src/js/lib/logger.js +69 -69
  40. package/src/js/lib/math.js +161 -161
  41. package/src/js/lib/objectPool.js +207 -207
  42. package/src/js/lib/time.js +18 -18
  43. package/src/js/lib/tween.js +152 -152
  44. package/src/js/modules/assets/baseModel.js +20 -20
  45. package/src/js/modules/assets/config.js +38 -38
  46. package/src/js/modules/assets/controller.js +65 -65
  47. package/src/js/modules/assets/models/atlas.js +18 -18
  48. package/src/js/modules/assets/models/audiosprite.js +28 -28
  49. package/src/js/modules/assets/models/bitmapFont.js +10 -10
  50. package/src/js/modules/assets/models/container.js +18 -18
  51. package/src/js/modules/assets/models/font.js +10 -10
  52. package/src/js/modules/assets/models/html.js +10 -10
  53. package/src/js/modules/assets/models/image.js +17 -17
  54. package/src/js/modules/assets/models/json.js +10 -10
  55. package/src/js/modules/assets/models/jsonAtlas.js +10 -10
  56. package/src/js/modules/assets/models/sound.js +16 -16
  57. package/src/js/modules/assets/models/spine.js +16 -16
  58. package/src/js/modules/assets/service.js +541 -541
  59. package/src/js/modules/i18n/config.js +17 -17
  60. package/src/js/modules/i18n/controller.js +71 -71
  61. package/src/js/modules/instances/controller.js +357 -357
  62. package/src/js/modules/logic/config/sounds.js +23 -23
  63. package/src/js/modules/logic/controller.js +52 -52
  64. package/src/js/modules/logic/main.js +8 -8
  65. package/src/js/modules/logic/sounds.js +103 -103
  66. package/src/js/modules/objects/baseModel.js +207 -207
  67. package/src/js/modules/objects/cache.js +99 -99
  68. package/src/js/modules/objects/config.js +9 -9
  69. package/src/js/modules/objects/controller.js +139 -139
  70. package/src/js/modules/objects/find.js +58 -58
  71. package/src/js/modules/objects/models/atlasImage.js +52 -52
  72. package/src/js/modules/objects/models/bitmapText.js +48 -48
  73. package/src/js/modules/objects/models/button.js +196 -196
  74. package/src/js/modules/objects/models/buttonComposite.js +37 -37
  75. package/src/js/modules/objects/models/checkbox.js +96 -96
  76. package/src/js/modules/objects/models/collection.js +54 -54
  77. package/src/js/modules/objects/models/component.js +48 -48
  78. package/src/js/modules/objects/models/container.js +21 -21
  79. package/src/js/modules/objects/models/dragContainer.js +664 -664
  80. package/src/js/modules/objects/models/emitter.js +69 -69
  81. package/src/js/modules/objects/models/emitterFx.js +114 -114
  82. package/src/js/modules/objects/models/graphics.js +40 -40
  83. package/src/js/modules/objects/models/group.js +21 -21
  84. package/src/js/modules/objects/models/hitArea.js +119 -119
  85. package/src/js/modules/objects/models/image.js +36 -36
  86. package/src/js/modules/objects/models/imagesAnimation.js +115 -115
  87. package/src/js/modules/objects/models/mask.js +40 -40
  88. package/src/js/modules/objects/models/nineSlicePlane.js +32 -32
  89. package/src/js/modules/objects/models/scrollbox.js +66 -66
  90. package/src/js/modules/objects/models/slider.js +352 -352
  91. package/src/js/modules/objects/models/spine.js +338 -338
  92. package/src/js/modules/objects/models/text.js +70 -70
  93. package/src/js/modules/objects/models/textInput.js +68 -68
  94. package/src/js/modules/objects/models/toggle.js +179 -179
  95. package/src/js/modules/objects/models/world.js +21 -21
  96. package/src/js/modules/objects/pool.js +68 -68
  97. package/src/js/modules/objects/propertyAdapter.js +588 -588
  98. package/src/js/modules/objects/proxy.js +298 -298
  99. package/src/js/modules/objects/selector.js +136 -136
  100. package/src/js/modules/objects/service.js +254 -254
  101. package/src/js/modules/objects/styles.js +210 -210
  102. package/src/js/modules/observer/controller.js +167 -167
  103. package/src/js/modules/observer/events.js +56 -56
  104. package/src/js/modules/scenes/controller.js +127 -127
  105. package/src/js/modules/scenes/model.js +28 -28
  106. package/src/js/modules/scenes/pixiWrapper.js +351 -351
  107. package/src/js/modules/scenes/resolutions.js +173 -173
  108. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  109. package/src/js/modules/scenes/service.js +146 -146
  110. package/src/js/modules/soundManager/controller.js +103 -103
  111. package/src/js/modules/soundManager/soundSprite.js +285 -285
  112. package/src/js/modules/statesManager/action.js +97 -97
  113. package/src/js/modules/statesManager/all.js +23 -23
  114. package/src/js/modules/statesManager/configStates.js +77 -77
  115. package/src/js/modules/statesManager/controller.js +218 -218
  116. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  117. package/src/js/modules/statesManager/helper.js +27 -27
  118. package/src/js/modules/statesManager/race.js +91 -91
  119. package/src/js/modules/statesManager/sequence.js +48 -48
  120. package/src/js/modules/template/controller.js +28 -28
  121. package/src/js/modules/template/model.js +11 -11
  122. package/src/js/modules/template/service.js +137 -137
  123. package/src/js/modules/template/types.js +48 -48
  124. package/src/js/modules/transport/baseConnectionType.js +25 -25
  125. package/src/js/modules/transport/config.js +13 -13
  126. package/src/js/modules/transport/connectionTypes/websocket.js +76 -76
  127. package/src/js/modules/transport/connectionTypes/xhr.js +46 -46
  128. package/src/js/modules/transport/controller.js +48 -48
  129. package/src/js/modules/transport/decorator.js +17 -17
  130. package/src/js/modules/transport/service.js +150 -150
  131. package/webpack.config.js +47 -47
  132. package/build/162.js/index.js +0 -1
  133. package/build/24.js/index.js +0 -1
@@ -1,70 +1,70 @@
1
- const ModulesObjectsBaseModel = require('./../baseModel');
2
-
3
- class ModulesObjectsModelsText extends ModulesObjectsBaseModel {
4
- constructor(params) {
5
- super(params);
6
-
7
- this.type = Urso.types.objects.TEXT;
8
- this._addBaseObject();
9
- }
10
-
11
- setupParams(params) {
12
- super.setupParams(params);
13
-
14
- this.text = Urso.helper.recursiveGet('text', params, false);
15
- this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
16
-
17
- this.localeVariables = Urso.helper.recursiveGet('localeVariables', params, {}); //optional variables for localization by localeId
18
-
19
- this.lineHeight = Urso.helper.recursiveGet('lineHeight', params, 0);
20
- this.fontFamily = Urso.helper.recursiveGet('fontFamily', params, 'Arial');
21
- this.fontSize = Urso.helper.recursiveGet('fontSize', params, false);
22
- this.fontStyle = Urso.helper.recursiveGet('fontStyle', params, false); //'italic'
23
- this.fontWeight = Urso.helper.recursiveGet('fontWeight', params, false); // 'bold'
24
- this.fill = Urso.helper.recursiveGet('fill', params, '#000000'); // gradient ['#ffffff', '#00ff99']
25
- this.fillCustomColors = Urso.helper.recursiveGet('fillCustomColors', params, false); //or array [{position:12,color:'#000000'},...]
26
- this.stroke = Urso.helper.recursiveGet('stroke', params, 'black');
27
- this.strokeThickness = Urso.helper.recursiveGet('strokeThickness', params, 0);
28
- this.dropShadow = Urso.helper.recursiveGet('dropShadow', params, false);
29
- this.dropShadowColor = Urso.helper.recursiveGet('dropShadowColor', params, '#000000');
30
- this.dropShadowBlur = Urso.helper.recursiveGet('dropShadowBlur', params, 0);
31
- this.dropShadowAngle = Urso.helper.recursiveGet('dropShadowAngle', params, 0); //Math.PI / 6
32
- this.dropShadowDistance = Urso.helper.recursiveGet('dropShadowBlur', params, 0); // 6
33
- this.wordWrap = Urso.helper.recursiveGet('wordWrap', params, false);
34
- this.wordWrapWidth = Urso.helper.recursiveGet('wordWrapWidth', params, 100);
35
- this.leading = Urso.helper.recursiveGet('leading', params, 0);
36
- this.letterSpacing = Urso.helper.recursiveGet('letterSpacing', params, 0);
37
- this.textAlign = Urso.helper.recursiveGet('textAlign', params, 'left');
38
- }
39
-
40
- _addBaseObject() {
41
- if (this.localeId)
42
- this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
43
-
44
- const styles = { fontFamily: this.fontFamily, leading: this.leading, align: this.textAlign }
45
- this._baseObject = new PIXI.Text(this.text, styles);
46
-
47
- if (this.fillCustomColors) {
48
- this._baseObject.fillCustomColors = this.fillCustomColors;
49
- }
50
- };
51
-
52
- _newLocaleHandler() {
53
- if(!this.proxyObject)
54
- return;
55
-
56
- this.proxyObject.text = Urso.i18n.get(this.localeId, this.localeVariables);
57
- }
58
-
59
- _customDestroy() {
60
- if (this.localeId)
61
- this.removeListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
62
- }
63
-
64
- _subscribeOnce() {
65
- if (this.localeId)
66
- this.addListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
67
- }
68
- }
69
-
70
- module.exports = ModulesObjectsModelsText;
1
+ const ModulesObjectsBaseModel = require('./../baseModel');
2
+
3
+ class ModulesObjectsModelsText extends ModulesObjectsBaseModel {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this.type = Urso.types.objects.TEXT;
8
+ this._addBaseObject();
9
+ }
10
+
11
+ setupParams(params) {
12
+ super.setupParams(params);
13
+
14
+ this.text = Urso.helper.recursiveGet('text', params, false);
15
+ this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
16
+
17
+ this.localeVariables = Urso.helper.recursiveGet('localeVariables', params, {}); //optional variables for localization by localeId
18
+
19
+ this.lineHeight = Urso.helper.recursiveGet('lineHeight', params, 0);
20
+ this.fontFamily = Urso.helper.recursiveGet('fontFamily', params, 'Arial');
21
+ this.fontSize = Urso.helper.recursiveGet('fontSize', params, false);
22
+ this.fontStyle = Urso.helper.recursiveGet('fontStyle', params, false); //'italic'
23
+ this.fontWeight = Urso.helper.recursiveGet('fontWeight', params, false); // 'bold'
24
+ this.fill = Urso.helper.recursiveGet('fill', params, '#000000'); // gradient ['#ffffff', '#00ff99']
25
+ this.fillCustomColors = Urso.helper.recursiveGet('fillCustomColors', params, false); //or array [{position:12,color:'#000000'},...]
26
+ this.stroke = Urso.helper.recursiveGet('stroke', params, 'black');
27
+ this.strokeThickness = Urso.helper.recursiveGet('strokeThickness', params, 0);
28
+ this.dropShadow = Urso.helper.recursiveGet('dropShadow', params, false);
29
+ this.dropShadowColor = Urso.helper.recursiveGet('dropShadowColor', params, '#000000');
30
+ this.dropShadowBlur = Urso.helper.recursiveGet('dropShadowBlur', params, 0);
31
+ this.dropShadowAngle = Urso.helper.recursiveGet('dropShadowAngle', params, 0); //Math.PI / 6
32
+ this.dropShadowDistance = Urso.helper.recursiveGet('dropShadowBlur', params, 0); // 6
33
+ this.wordWrap = Urso.helper.recursiveGet('wordWrap', params, false);
34
+ this.wordWrapWidth = Urso.helper.recursiveGet('wordWrapWidth', params, 100);
35
+ this.leading = Urso.helper.recursiveGet('leading', params, 0);
36
+ this.letterSpacing = Urso.helper.recursiveGet('letterSpacing', params, 0);
37
+ this.textAlign = Urso.helper.recursiveGet('textAlign', params, 'left');
38
+ }
39
+
40
+ _addBaseObject() {
41
+ if (this.localeId)
42
+ this._originalModel.text = this.text = Urso.i18n.get(this.localeId, this.localeVariables);
43
+
44
+ const styles = { fontFamily: this.fontFamily, leading: this.leading, align: this.textAlign }
45
+ this._baseObject = new PIXI.Text(this.text, styles);
46
+
47
+ if (this.fillCustomColors) {
48
+ this._baseObject.fillCustomColors = this.fillCustomColors;
49
+ }
50
+ };
51
+
52
+ _newLocaleHandler() {
53
+ if(!this.proxyObject)
54
+ return;
55
+
56
+ this.proxyObject.text = Urso.i18n.get(this.localeId, this.localeVariables);
57
+ }
58
+
59
+ _customDestroy() {
60
+ if (this.localeId)
61
+ this.removeListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
62
+ }
63
+
64
+ _subscribeOnce() {
65
+ if (this.localeId)
66
+ this.addListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
67
+ }
68
+ }
69
+
70
+ module.exports = ModulesObjectsModelsText;
@@ -1,68 +1,68 @@
1
- const ModulesObjectsBaseModel = require('./../baseModel');
2
-
3
- class ModulesObjectsModelsTextInput extends ModulesObjectsBaseModel {
4
- constructor(params) {
5
- super(params);
6
-
7
- this.type = Urso.types.objects.TEXTINPUT;
8
- this.text = '';
9
- this._addBaseObject();
10
- this._setRestrictedSymbosl();
11
- }
12
-
13
- setupParams(params) {
14
- super.setupParams(params);
15
-
16
- this.input = Urso.helper.recursiveGet('input', params, false);
17
- this.box = Urso.helper.recursiveGet('box', params, false);
18
- this.numbersOnly = Urso.helper.recursiveGet('numbersOnly', params, false);
19
- this.allowedSymbols = Urso.helper.recursiveGet('allowedSymbols', params, false);
20
- //this.substituteText = Urso.helper.recursiveGet('substituteText', params, false); //todo remove this string
21
- this.maxLength = Urso.helper.recursiveGet('maxLength', params, false);
22
- }
23
-
24
- restrictInput(allowedSymbols) {
25
- this._baseObject.restrict = allowedSymbols;
26
- }
27
-
28
- disable() {
29
- this._baseObject.disabled = true
30
- }
31
-
32
- enable() {
33
- this._baseObject.disabled = false
34
- }
35
-
36
- _setRestrictedSymbosl() {
37
- if (this.numbersOnly) {
38
- const regex = new RegExp('^[0-9]*');
39
- this.restrictInput(regex);
40
- } else if (this.allowedSymbols) {
41
- this.restrictInput(this.allowedSymbols);
42
- }
43
- }
44
-
45
- _onBlur() {
46
- const data = { name: this.name, class: this.class, id: this.id, text: this.text };
47
- this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_BLUR, data);
48
- }
49
-
50
- _onInput() {
51
- this.text = this._baseObject.text;
52
- const data = { name: this.name, class: this.class, id: this.id, text: this.text };
53
- this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_INPUT, data);
54
- }
55
-
56
- _addBaseObject() {
57
- this._baseObject = new PIXI.TextInput({ input: this.input, box: this.box });
58
- //this._baseObject.substituteText = this.substituteText; //todo remove this string
59
-
60
- if (this.maxLength)
61
- this._baseObject.maxLength = this.maxLength
62
-
63
- this._baseObject.on('blur', this._onBlur.bind(this))
64
- this._baseObject.on('input', this._onInput.bind(this))
65
- };
66
- }
67
-
68
- module.exports = ModulesObjectsModelsTextInput;
1
+ const ModulesObjectsBaseModel = require('./../baseModel');
2
+
3
+ class ModulesObjectsModelsTextInput extends ModulesObjectsBaseModel {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this.type = Urso.types.objects.TEXTINPUT;
8
+ this.text = '';
9
+ this._addBaseObject();
10
+ this._setRestrictedSymbosl();
11
+ }
12
+
13
+ setupParams(params) {
14
+ super.setupParams(params);
15
+
16
+ this.input = Urso.helper.recursiveGet('input', params, false);
17
+ this.box = Urso.helper.recursiveGet('box', params, false);
18
+ this.numbersOnly = Urso.helper.recursiveGet('numbersOnly', params, false);
19
+ this.allowedSymbols = Urso.helper.recursiveGet('allowedSymbols', params, false);
20
+ //this.substituteText = Urso.helper.recursiveGet('substituteText', params, false); //todo remove this string
21
+ this.maxLength = Urso.helper.recursiveGet('maxLength', params, false);
22
+ }
23
+
24
+ restrictInput(allowedSymbols) {
25
+ this._baseObject.restrict = allowedSymbols;
26
+ }
27
+
28
+ disable() {
29
+ this._baseObject.disabled = true
30
+ }
31
+
32
+ enable() {
33
+ this._baseObject.disabled = false
34
+ }
35
+
36
+ _setRestrictedSymbosl() {
37
+ if (this.numbersOnly) {
38
+ const regex = new RegExp('^[0-9]*');
39
+ this.restrictInput(regex);
40
+ } else if (this.allowedSymbols) {
41
+ this.restrictInput(this.allowedSymbols);
42
+ }
43
+ }
44
+
45
+ _onBlur() {
46
+ const data = { name: this.name, class: this.class, id: this.id, text: this.text };
47
+ this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_BLUR, data);
48
+ }
49
+
50
+ _onInput() {
51
+ this.text = this._baseObject.text;
52
+ const data = { name: this.name, class: this.class, id: this.id, text: this.text };
53
+ this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_INPUT, data);
54
+ }
55
+
56
+ _addBaseObject() {
57
+ this._baseObject = new PIXI.TextInput({ input: this.input, box: this.box });
58
+ //this._baseObject.substituteText = this.substituteText; //todo remove this string
59
+
60
+ if (this.maxLength)
61
+ this._baseObject.maxLength = this.maxLength
62
+
63
+ this._baseObject.on('blur', this._onBlur.bind(this))
64
+ this._baseObject.on('input', this._onInput.bind(this))
65
+ };
66
+ }
67
+
68
+ module.exports = ModulesObjectsModelsTextInput;
@@ -1,179 +1,179 @@
1
- const UrsoCoreModulesObjectsModelsButton = require('./button');
2
-
3
- class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
4
- constructor(params) {
5
- super(params);
6
-
7
- this.status = 'unpressed';
8
-
9
- this.type = Urso.types.objects.TOGGLE;
10
- this._addBaseObject();
11
-
12
- this.enable = this.enable.bind(this);
13
- this.disable = this.disable.bind(this);
14
- }
15
-
16
- setupParams(params) {
17
- super.setupParams(params);
18
-
19
- this.action = Urso.helper.recursiveGet('action', params, () => {
20
- this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this.status, class: this.class })
21
- });
22
-
23
- this.buttonFrames = {
24
- pressedOver: Urso.helper.recursiveGet('buttonFrames.pressedOver', params, false),
25
- pressedOut: Urso.helper.recursiveGet('buttonFrames.pressedOut', params, false),
26
- unpressedOver: Urso.helper.recursiveGet('buttonFrames.unpressedOver', params, false),
27
- unpressedOut: Urso.helper.recursiveGet('buttonFrames.unpressedOut', params, false),
28
- pressedDown: Urso.helper.recursiveGet('buttonFrames.pressedDown', params, false),
29
- unpressedDown: Urso.helper.recursiveGet('buttonFrames.unpressedDown', params, false),
30
- pressedDisabled: Urso.helper.recursiveGet('buttonFrames.pressedDisabled', params, false),
31
- unpressedDisabled: Urso.helper.recursiveGet('buttonFrames.unpressedDisabled', params, false),
32
- }
33
- }
34
-
35
- setButtonFrame(key, assetKey) {
36
- this.buttonFrames[key] = assetKey;
37
-
38
- if (this._isOver)
39
- this._changeTexture(`${this.status}Over`);
40
- else if (this._isDown)
41
- this._changeTexture(`${this.status}Down`);
42
- else if (this._isDisabled)
43
- this._changeTexture(`${this.status}Disabled`);
44
- else
45
- this._changeTexture(`${this.status}Out`);
46
- }
47
-
48
- enable() {
49
- if (!this._isDisabled)
50
- return false;
51
-
52
- if (this._isOver)
53
- this._changeTexture(`${this.status}Over`);
54
- else
55
- this._changeTexture(`${this.status}Out`);
56
-
57
- this._isDisabled = false;
58
- this._baseObject.buttonMode = true;
59
- }
60
-
61
- disable() {
62
- if (this._isDisabled)
63
- return false;
64
-
65
- this._changeTexture(`${this.status}Disabled`);
66
- this._isDisabled = true;
67
- this._baseObject.buttonMode = false;
68
- }
69
-
70
- _addBaseObject() {
71
- this._baseObject = new PIXI.Sprite();
72
- this._changeTexture('unpressedOut');
73
-
74
- this._baseObject.interactive = true;
75
- this._baseObject.buttonMode = true;
76
-
77
- if (this.pixelPerfectOver) {
78
- //todo
79
- }
80
-
81
- if (this.pixelPerfectClick) {
82
- //todo
83
- }
84
-
85
- this._baseObject
86
- .on('pointerdown', this._onButtonDown.bind(this))
87
- .on('pointerup', this._onButtonUp.bind(this))
88
- .on('pointerupoutside', this._onButtonUp.bind(this))
89
- .on('pointerover', this._onButtonOver.bind(this))
90
- .on('pointerout', this._onButtonOut.bind(this));
91
- };
92
-
93
- _onButtonDown() {
94
- if (this._isDisabled)
95
- return false;
96
-
97
- this._isDown = true;
98
-
99
- if (this.keyDownAction)
100
- this.keyDownAction();
101
-
102
- if (this._isDisabled) //can be disabled after keyDownAction
103
- return false;
104
-
105
- this._changeTexture(`${this.status}Down`);
106
-
107
- this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
108
- }
109
-
110
- _onButtonUp() {
111
- if (this._isDisabled)
112
- return false;
113
-
114
- this._isDown = false;
115
-
116
- if (this.action)
117
- this.action();
118
-
119
- if (this._isDisabled) //can be disabled after action
120
- return false;
121
-
122
- if (this._isOver)
123
- this._changeTexture(`${this.status}Over`);
124
- else
125
- this._changeTexture(`${this.status}Out`);
126
- }
127
-
128
- _onButtonOver() {
129
- this._isOver = true;
130
-
131
- if (this._isDisabled || this._isDown)
132
- return false;
133
-
134
- if (this.mouseOverAction)
135
- this.mouseOverAction();
136
-
137
- this._changeTexture(`${this.status}Over`);
138
- }
139
-
140
- _onButtonOut() {
141
- this._isOver = false;
142
-
143
- if (this._isDisabled || this._isDown)
144
- return false;
145
-
146
- if (this.mouseOutAction)
147
- this.mouseOutAction();
148
-
149
- this._changeTexture(`${this.status}Out`);
150
- }
151
-
152
- switchStatus() {
153
- this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
154
-
155
- if (this._isOver)
156
- this._changeTexture(`${this.status}Over`);
157
- else
158
- this._changeTexture(`${this.status}Out`);
159
- }
160
-
161
- _changeTexture(key) {
162
- let texture = Urso.cache.getTexture(this.buttonFrames[key]);
163
-
164
- if (!texture) {
165
- if (key === `${this.status}Out`) {
166
- Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
167
- return false;
168
- }
169
-
170
- this._changeTexture(`${this.status}Out`); // load default texture for this key
171
- return false;
172
- }
173
-
174
- this._baseObject.texture = texture;
175
- return true;
176
- }
177
- }
178
-
179
- module.exports = ModulesObjectsModelsToggle;
1
+ const UrsoCoreModulesObjectsModelsButton = require('./button');
2
+
3
+ class ModulesObjectsModelsToggle extends UrsoCoreModulesObjectsModelsButton {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this.status = 'unpressed';
8
+
9
+ this.type = Urso.types.objects.TOGGLE;
10
+ this._addBaseObject();
11
+
12
+ this.enable = this.enable.bind(this);
13
+ this.disable = this.disable.bind(this);
14
+ }
15
+
16
+ setupParams(params) {
17
+ super.setupParams(params);
18
+
19
+ this.action = Urso.helper.recursiveGet('action', params, () => {
20
+ this.emit(Urso.events.MODULES_OBJECTS_TOGGLE_PRESS, { name: this.name, status: this.status, class: this.class })
21
+ });
22
+
23
+ this.buttonFrames = {
24
+ pressedOver: Urso.helper.recursiveGet('buttonFrames.pressedOver', params, false),
25
+ pressedOut: Urso.helper.recursiveGet('buttonFrames.pressedOut', params, false),
26
+ unpressedOver: Urso.helper.recursiveGet('buttonFrames.unpressedOver', params, false),
27
+ unpressedOut: Urso.helper.recursiveGet('buttonFrames.unpressedOut', params, false),
28
+ pressedDown: Urso.helper.recursiveGet('buttonFrames.pressedDown', params, false),
29
+ unpressedDown: Urso.helper.recursiveGet('buttonFrames.unpressedDown', params, false),
30
+ pressedDisabled: Urso.helper.recursiveGet('buttonFrames.pressedDisabled', params, false),
31
+ unpressedDisabled: Urso.helper.recursiveGet('buttonFrames.unpressedDisabled', params, false),
32
+ }
33
+ }
34
+
35
+ setButtonFrame(key, assetKey) {
36
+ this.buttonFrames[key] = assetKey;
37
+
38
+ if (this._isOver)
39
+ this._changeTexture(`${this.status}Over`);
40
+ else if (this._isDown)
41
+ this._changeTexture(`${this.status}Down`);
42
+ else if (this._isDisabled)
43
+ this._changeTexture(`${this.status}Disabled`);
44
+ else
45
+ this._changeTexture(`${this.status}Out`);
46
+ }
47
+
48
+ enable() {
49
+ if (!this._isDisabled)
50
+ return false;
51
+
52
+ if (this._isOver)
53
+ this._changeTexture(`${this.status}Over`);
54
+ else
55
+ this._changeTexture(`${this.status}Out`);
56
+
57
+ this._isDisabled = false;
58
+ this._baseObject.buttonMode = true;
59
+ }
60
+
61
+ disable() {
62
+ if (this._isDisabled)
63
+ return false;
64
+
65
+ this._changeTexture(`${this.status}Disabled`);
66
+ this._isDisabled = true;
67
+ this._baseObject.buttonMode = false;
68
+ }
69
+
70
+ _addBaseObject() {
71
+ this._baseObject = new PIXI.Sprite();
72
+ this._changeTexture('unpressedOut');
73
+
74
+ this._baseObject.interactive = true;
75
+ this._baseObject.buttonMode = true;
76
+
77
+ if (this.pixelPerfectOver) {
78
+ //todo
79
+ }
80
+
81
+ if (this.pixelPerfectClick) {
82
+ //todo
83
+ }
84
+
85
+ this._baseObject
86
+ .on('pointerdown', this._onButtonDown.bind(this))
87
+ .on('pointerup', this._onButtonUp.bind(this))
88
+ .on('pointerupoutside', this._onButtonUp.bind(this))
89
+ .on('pointerover', this._onButtonOver.bind(this))
90
+ .on('pointerout', this._onButtonOut.bind(this));
91
+ };
92
+
93
+ _onButtonDown() {
94
+ if (this._isDisabled)
95
+ return false;
96
+
97
+ this._isDown = true;
98
+
99
+ if (this.keyDownAction)
100
+ this.keyDownAction();
101
+
102
+ if (this._isDisabled) //can be disabled after keyDownAction
103
+ return false;
104
+
105
+ this._changeTexture(`${this.status}Down`);
106
+
107
+ this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
108
+ }
109
+
110
+ _onButtonUp() {
111
+ if (this._isDisabled)
112
+ return false;
113
+
114
+ this._isDown = false;
115
+
116
+ if (this.action)
117
+ this.action();
118
+
119
+ if (this._isDisabled) //can be disabled after action
120
+ return false;
121
+
122
+ if (this._isOver)
123
+ this._changeTexture(`${this.status}Over`);
124
+ else
125
+ this._changeTexture(`${this.status}Out`);
126
+ }
127
+
128
+ _onButtonOver() {
129
+ this._isOver = true;
130
+
131
+ if (this._isDisabled || this._isDown)
132
+ return false;
133
+
134
+ if (this.mouseOverAction)
135
+ this.mouseOverAction();
136
+
137
+ this._changeTexture(`${this.status}Over`);
138
+ }
139
+
140
+ _onButtonOut() {
141
+ this._isOver = false;
142
+
143
+ if (this._isDisabled || this._isDown)
144
+ return false;
145
+
146
+ if (this.mouseOutAction)
147
+ this.mouseOutAction();
148
+
149
+ this._changeTexture(`${this.status}Out`);
150
+ }
151
+
152
+ switchStatus() {
153
+ this.status = this.status === 'pressed' ? 'unpressed' : 'pressed';
154
+
155
+ if (this._isOver)
156
+ this._changeTexture(`${this.status}Over`);
157
+ else
158
+ this._changeTexture(`${this.status}Out`);
159
+ }
160
+
161
+ _changeTexture(key) {
162
+ let texture = Urso.cache.getTexture(this.buttonFrames[key]);
163
+
164
+ if (!texture) {
165
+ if (key === `${this.status}Out`) {
166
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
167
+ return false;
168
+ }
169
+
170
+ this._changeTexture(`${this.status}Out`); // load default texture for this key
171
+ return false;
172
+ }
173
+
174
+ this._baseObject.texture = texture;
175
+ return true;
176
+ }
177
+ }
178
+
179
+ module.exports = ModulesObjectsModelsToggle;