@urso/core 0.2.0-dev → 0.2.4-dev

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.
@@ -26,14 +26,6 @@ object-assign
26
26
  * MIT License
27
27
  */
28
28
 
29
- /*!
30
- * @pixi/accessibility - v5.3.10
31
- * Compiled Mon, 07 Jun 2021 22:37:25 UTC
32
- *
33
- * @pixi/accessibility is licensed under the MIT License.
34
- * http://www.opensource.org/licenses/mit-license
35
- */
36
-
37
29
  /*!
38
30
  * @pixi/constants - v5.3.10
39
31
  * Compiled Mon, 07 Jun 2021 22:37:25 UTC
@@ -172,6 +164,16 @@ object-assign
172
164
  * http://www.opensource.org/licenses/mit-license
173
165
  */
174
166
 
167
+ /*!
168
+ * pixi-viewport - v4.34.3
169
+ * Compiled Wed, 01 Dec 2021 19:28:04 UTC
170
+ *
171
+ * pixi-viewport is licensed under the MIT License.
172
+ * http://www.opensource.org/licenses/mit-license
173
+ *
174
+ * Copyright 2019-2020, David Figatner, All Rights Reserved
175
+ */
176
+
175
177
  /*!
176
178
  * resource-loader - v3.0.1
177
179
  * https://github.com/pixijs/pixi-sound
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.2.00-dev",
3
+ "version": "0.2.04-dev",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -29,7 +29,10 @@
29
29
  "pixi-projection": "0.3.15",
30
30
  "pixi-spine": "^2.1.11",
31
31
  "pixi.js": "^5.1.3",
32
- "pixi5-dragonbones": "5.7.0-2"
32
+ "pixi5-dragonbones": "5.7.0-2",
33
+ "pixi-scrollbox": "^2.3.1",
34
+ "pixi-viewport": "^4.34.0",
35
+ "pixi-text-input": "^1.0.6"
33
36
  },
34
37
  "devDependencies": {
35
38
  "@babel/core": "^7.12.10",
@@ -2,12 +2,16 @@ ComponentsBaseController = require('./../base/controller.js');
2
2
 
3
3
  class ComponentsStateDrivenController extends ComponentsBaseController {
4
4
 
5
+ //config for the states guards
5
6
  configStates = {
6
7
  /*IDLE: {
7
8
  guard: () => { log(123, 'IDLE guard'); return true; }
8
9
  }*/
9
10
  };
10
11
 
12
+ //config for the actions configs. Guard and terminate functions are optional. Run will called when action starts.
13
+ //call finish callback in the run handler to immidiately finish this action
14
+ //use this.callFinish(actionKey) when its need after run handler called to delayed finish this action
11
15
  configActions = {
12
16
  /*startSpin: {
13
17
  guard: () => { log(123, 'guard'); return true; },
@@ -16,12 +20,22 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
16
20
  }*/
17
21
  };
18
22
 
19
- //TODO subscribe to N actions
20
- constructor(options) {
21
- super(options);
23
+ //system callbacks storage
24
+ _finishCallbacks = {};
22
25
 
23
- this._processStates();
24
- this._processActions();
26
+
27
+ /**
28
+ * caller for delayed finish callback
29
+ * @param {String} actionKey
30
+ */
31
+ callFinish(actionKey) {
32
+ if (!this._finishCallbacks.actionKey) {
33
+ Urso.logger.error('ComponentsStateDrivenController: no finish for actionKey', actionKey, this);
34
+ return;
35
+ }
36
+
37
+ this._finishCallbacks.actionKey();
38
+ delete this._finishCallbacks.actionKey;
25
39
  }
26
40
 
27
41
  _processStates() {
@@ -37,7 +51,10 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
37
51
  const actionCfg = this.configActions[actionKey];
38
52
 
39
53
  if (actionCfg.run)
40
- Urso.statesManager.addActionRun(actionKey, actionCfg.run.bind(this));
54
+ Urso.statesManager.addActionRun(actionKey, (finish) => {
55
+ this._saveFinish(actionKey, finish);
56
+ actionCfg.run(() => this.callFinish(actionKey));
57
+ });
41
58
  else {
42
59
  Urso.logger.error('ComponentsStateDrivenController: no run function in config', actionKey, this);
43
60
  continue;
@@ -51,6 +68,24 @@ class ComponentsStateDrivenController extends ComponentsBaseController {
51
68
  }
52
69
  }
53
70
 
71
+ /**
72
+ * saver for delayed finish callback
73
+ * @param {String} actionKey
74
+ * @param {Function} finish
75
+ */
76
+ _saveFinish(actionKey, finish) {
77
+ if (this._finishCallbacks.actionKey)
78
+ Urso.logger.error('ComponentsStateDrivenController: actionKey alredy exists', actionKey, finish, this);
79
+
80
+ this._finishCallbacks.actionKey = finish;
81
+ }
82
+
83
+ _subscribeOnce() {
84
+ //do not forget use super._subscribeOnce() , if you will use _subscribeOnce in the component
85
+ this._processStates();
86
+ this._processActions();
87
+ }
88
+
54
89
  //todo
55
90
  destroy() {
56
91
  Urso.logger.error('ComponentsStateDrivenController will remove States and Actions by configs');
@@ -8,6 +8,7 @@ PIXI.filters['DropShadowFilter'] = DropShadowFilter;
8
8
 
9
9
  require("pixi-spine");
10
10
  require("pixi-projection");
11
+ require("pixi-text-input");
11
12
 
12
13
  Urso.DragonBones = require("pixi5-dragonbones");
13
14
 
@@ -201,6 +201,17 @@ class LibHelper {
201
201
  return true;
202
202
  }
203
203
 
204
+ /**
205
+ * tranpose matrix (rows to cols)
206
+ * @param {Array} matrix
207
+ * @returns {Array}
208
+ */
209
+ transpose(matrix) {
210
+ return Object.keys(matrix[0])
211
+ .map(colNumber => matrix
212
+ .map(rowNumber => rowNumber[colNumber]));
213
+ }
214
+
204
215
  /**
205
216
  * recursive merge two objects into one
206
217
  * @param {Object} obj1
@@ -105,6 +105,21 @@ class ModulesObjectsCreate {
105
105
  case Urso.types.objects.EMITTER:
106
106
  model = this.getInstance('Models.Emitter', object);
107
107
  break;
108
+ case Urso.types.objects.SLIDER:
109
+ model = this.getInstance('Models.Slider', object);
110
+ break;
111
+ case Urso.types.objects.TOGGLE:
112
+ model = this.getInstance('Models.Toggle', object);
113
+ break;
114
+ case Urso.types.objects.CHECKBOX:
115
+ model = this.getInstance('Models.Checkbox', object);
116
+ break;
117
+ case Urso.types.objects.SCROLLBOX:
118
+ model = this.getInstance('Models.Scrollbox', object);
119
+ break;
120
+ case Urso.types.objects.TEXTINPUT:
121
+ model = this.getInstance('Models.TextInput', object);
122
+ break;
108
123
  default:
109
124
  break;
110
125
  }
@@ -16,5 +16,10 @@ Urso.Core.Modules.Objects.Models = {
16
16
  Mask: require('./mask.js'),
17
17
  Spine: require('./spine.js'),
18
18
  Text: require('./text.js'),
19
+ Slider: require('./slider.js'),
20
+ Toggle: require('./toggle.js'),
21
+ Checkbox: require('./checkbox.js'),
22
+ Scrollbox: require('./scrollbox.js'),
23
+ TextInput: require('./textInput.js'),
19
24
  World: require('./world.js')
20
25
  };
@@ -0,0 +1,96 @@
1
+ const UrsoCoreModulesObjectsModelsToggle = require('./toggle');
2
+
3
+ class ModulesObjectsModelsCheckbox extends UrsoCoreModulesObjectsModelsToggle {
4
+ constructor(params) {
5
+ super(params);
6
+
7
+ this._isDisabled = false;
8
+ this._lable = null;
9
+ this._checkbox = null;
10
+
11
+ this.type = Urso.types.objects.CHECKBOX;
12
+
13
+ this._createCheckbox();
14
+
15
+ this.enable = this.enable.bind(this);
16
+ this.disable = this.disable.bind(this);
17
+ }
18
+
19
+ setupParams(params) {
20
+ super.setupParams(params);
21
+
22
+ this.contents = [];
23
+
24
+ this.action = Urso.helper.recursiveGet('action', params, () => {
25
+ this.emit(Urso.events.MODULES_OBJECTS_CHECKBOX_PRESS, { name: this.name, status: this._toggleStatus })
26
+ });
27
+
28
+ this.action = Urso.helper.recursiveGet('action', params, () => { this.emit(Urso.events.MODULES_OBJECTS_CHECKBOX_PRESS, this.name) });
29
+ this.lable = Urso.helper.recursiveGet('lable', params, false);
30
+
31
+ this.defaultStatus = Urso.helper.recursiveGet('defaultStatus', params, 'unpressed'); //pressed or unpressed
32
+ }
33
+
34
+ _createCheckbox() {
35
+ this._toggleStatus = this.defaultStatus;
36
+ this._checkbox = this._createObject(this.buttonFrames[`${this.defaultStatus}Out`])
37
+
38
+ if (this.lable)
39
+ this._lable = this._createObject(this.lable);
40
+ }
41
+
42
+ _createObject(model) {
43
+ model = Urso.helper.objectClone(model);
44
+ let object = Urso.objects.create(model, this);
45
+
46
+ object._baseObject.interactive = true;
47
+ object._baseObject.buttonMode = true;
48
+
49
+ object._baseObject
50
+ .on('pointerdown', this._onButtonDown.bind(this))
51
+ .on('pointerup', this._onButtonUp.bind(this))
52
+ .on('pointerupoutside', this._onButtonUp.bind(this))
53
+ .on('pointerover', this._onButtonOver.bind(this))
54
+ .on('pointerout', this._onButtonOut.bind(this));
55
+
56
+ return object;
57
+ }
58
+
59
+ _addBaseObject() {
60
+ this._baseObject = new PIXI.Container();
61
+ };
62
+
63
+ _drawGraphics({ polygon, rectangle, fillColor }) {
64
+ if (!polygon && !rectangle)
65
+ return;
66
+
67
+ this._checkbox._baseObject.clear();
68
+ this._checkbox._baseObject.beginFill(fillColor);
69
+
70
+ if (polygon && polygon.length) {
71
+ this._checkbox._baseObject.drawPolygon(polygon);
72
+ } else if (rectangle && rectangle.length) {
73
+ this._checkbox._baseObject.drawRect(...rectangle)
74
+ }
75
+
76
+ this._checkbox._baseObject.endFill();
77
+ };
78
+
79
+ _changeTexture(key) {
80
+ if (!this.buttonFrames[key]) {
81
+ if (key === `${this._toggleStatus}Out`) {
82
+ Urso.logger.error('ModulesObjectsModelsButton assets error: no out image ' + this.buttonFrames.out);
83
+ return false;
84
+ }
85
+
86
+ this._changeTexture(`${this._toggleStatus}Out`); // load default texture for this key
87
+ return false;
88
+ }
89
+ if (this.buttonFrames[key].type === Urso.types.objects.GRAPHICS)
90
+ this._drawGraphics(this.buttonFrames[key].figure);
91
+ else
92
+ this._checkbox.changeTexture(this.buttonFrames[key].assetKey);
93
+ }
94
+ }
95
+
96
+ module.exports = ModulesObjectsModelsCheckbox;
@@ -0,0 +1,62 @@
1
+ class ModulesObjectsModelsScrollbox extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.SCROLLBOX;
6
+ this._addBaseObject();
7
+ this._createContent();
8
+ }
9
+
10
+ setupParams(params) {
11
+ super.setupParams(params);
12
+
13
+ this.content = Urso.helper.recursiveGet('content', params, []);
14
+ this.dragScroll = Urso.helper.recursiveGet('dragScroll', params, true);
15
+ this.scrollType = Urso.helper.recursiveGet('scrollType', params, 3);
16
+ }
17
+
18
+ _getScrollboxParams(){
19
+ return {
20
+ boxWidth: this.width,
21
+ boxHeight: this.height,
22
+ dragScroll: this.dragScroll,
23
+ fade: true,
24
+ fadeScrollbarTime: 300
25
+ }
26
+ }
27
+
28
+ _setScrollWidth(){
29
+ if(this.scrollType === 1 || this.scrollType === 0){
30
+ this._baseObject.scrollWidth = this.width;
31
+ this._baseObject.overflowX = 'hidden';
32
+ }
33
+ }
34
+
35
+ _setScrollHeight(){
36
+ if(this.scrollType === 2 || this.scrollType === 0){
37
+ this._baseObject.scrollHeight = this.height;
38
+ this._baseObject.overflowY = 'hidden'
39
+ }
40
+ }
41
+
42
+ _createContent(){
43
+ this.content.forEach(child => {
44
+ let object = Urso.objects.create(child)
45
+ this._baseObject.content.addChild(object._baseObject)
46
+ })
47
+
48
+ this._baseObject.update();
49
+ }
50
+
51
+ _addBaseObject() {
52
+ const params = this._getScrollboxParams();
53
+
54
+ const Scrollbox = require('pixi-scrollbox').Scrollbox;
55
+ this._baseObject = new Scrollbox(params);
56
+
57
+ this._setScrollHeight();
58
+ this._setScrollWidth();
59
+ };
60
+ }
61
+
62
+ module.exports = ModulesObjectsModelsScrollbox
@@ -0,0 +1,154 @@
1
+ class ModulesObjectsModelsSlider extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.SLIDER;
6
+ this._sliderBg = null;
7
+ this._sliderHandle = null;
8
+ this._baseObject = null;
9
+ this._handleIsPulling = false;
10
+
11
+ this._addBaseObject();
12
+ this._createSliderTextures();
13
+ this._createValueText();
14
+ this._setDefaultValue();
15
+ }
16
+
17
+ setupParams(params) {
18
+ super.setupParams(params);
19
+ this.contents = [];
20
+ this.points = Urso.helper.recursiveGet('points', params, [0, 1]);
21
+ this.defaultValue = Urso.helper.recursiveGet('defaultValue', params, this.points[0]);
22
+ this.bgTexture = Urso.helper.recursiveGet('bgTexture', params, false);
23
+ this.handleTexture = Urso.helper.recursiveGet('handleTexture', params, false);
24
+ this.minValueTextModel = Urso.helper.recursiveGet('minValueTextModel', params, false);
25
+ this.maxValueTextModel = Urso.helper.recursiveGet('maxValueTextModel', params, false);
26
+ this.currentValueTextModel = Urso.helper.recursiveGet('currentValueTextModel', params, false);
27
+ }
28
+
29
+ _createSliderTextures() {
30
+ this._sliderBg = this._createTexture(this.bgTexture);
31
+ this._sliderHandle = this._createTexture(this.handleTexture);
32
+
33
+ this._setEvents(this._sliderBg._baseObject);
34
+ this._setEvents(this._sliderHandle._baseObject);
35
+ }
36
+
37
+ _createValueText() {
38
+ if (this.minValueTextModel) {
39
+ this.minValueText = Urso.objects.create(this.minValueTextModel, this);
40
+ this.minValueText.text = this.points[0];
41
+ }
42
+
43
+ if (this.maxValueTextModel) {
44
+ this.maxValueText = Urso.objects.create(this.maxValueTextModel, this);
45
+ this.maxValueText.text = this.points.length <= 2 ? '100' : this.points[this.points.length - 1];
46
+ }
47
+
48
+ if(this.currentValueTextModel){
49
+ this.currentValueText = Urso.objects.create(this.currentValueTextModel, this);
50
+ }
51
+ }
52
+
53
+ _createTexture(model) {
54
+ if (model.type === Urso.types.objects.GRAPHICS || model.type === Urso.types.objects.IMAGE)
55
+ return Urso.objects.create(model, this);
56
+ else
57
+ Urso.logger.error('ModulesObjectsModelsSlider objects error: textures should be GRAPHICS or IMAGE type');
58
+ }
59
+
60
+ _setEvents(obj) {
61
+ obj.interactive = true;
62
+ obj.buttonMode = true;
63
+
64
+ obj
65
+ .on('pointerdown', this._onPointerDown.bind(this))
66
+ .on('pointerup', this._onPointerUp.bind(this))
67
+ .on('pointerupoutside', this._onPointerUp.bind(this))
68
+ }
69
+
70
+ _addBaseObject() {
71
+ this._baseObject = new PIXI.Container();
72
+ };
73
+
74
+ _onPointerDown(obj) {
75
+ if (obj.target === this._sliderHandle._baseObject)
76
+ this._handleIsDragging = true;
77
+ }
78
+
79
+ _onMouseMove({ x }) {
80
+ if (!this._handleIsDragging)
81
+ return
82
+
83
+ if (x < this.x)
84
+ this._sliderHandle.x = 0;
85
+ else if (x > this.x + this._sliderBg._baseObject.width)
86
+ this._sliderHandle.x = this._sliderBg._baseObject.width;
87
+ else
88
+ this._sliderHandle.x = x - this.x;
89
+ }
90
+
91
+ _onPointerUp(obj) {
92
+ this._handleIsDragging = false;
93
+ let x;
94
+
95
+ if (obj.target === this._sliderBg._baseObject) {
96
+ x = obj.data.getLocalPosition(obj.target).x;
97
+ } else
98
+ x = this._sliderHandle.x;
99
+
100
+ this._dropHandle(x);
101
+ }
102
+
103
+ _setDefaultValue(){
104
+ if(!this.defaultValue)
105
+ return
106
+
107
+ if(!this.points.includes(this.defaultValue))
108
+ this.defaultValue = this.points[0];
109
+
110
+ let x = this.points.indexOf(this.defaultValue) * this._sliderBg._baseObject.width / (this.points.length - 1);
111
+
112
+ this._setNewValue(x, this.defaultValue);
113
+ }
114
+
115
+ _dropHandle(x) {
116
+ let value;
117
+ let handleX;
118
+
119
+ if(this.points.length <= 2){
120
+ handleX = x;
121
+ value = ~~(100 / this._sliderBg._baseObject.width * x);
122
+ }
123
+ // calculate closest point
124
+ else{
125
+ for (let i = 0; i < this.points.length; i++) {
126
+ let pointX = i * this._sliderBg._baseObject.width / (this.points.length - 1);
127
+
128
+ if (typeof (handleX) === 'number' && x - pointX < handleX - x) {
129
+ handleX = handleX;
130
+ } else {
131
+ handleX = pointX;
132
+ value = this.points[i];
133
+ }
134
+ }
135
+ }
136
+
137
+ this._setNewValue(handleX, value)
138
+ }
139
+
140
+ _setNewValue(x, value){
141
+ this._sliderHandle.x = x;
142
+
143
+ if (this.currentValueText)
144
+ this.currentValueText.text = value;
145
+
146
+ this.emit(Urso.events.MODULES_OBJECTS_SLIDER_SET_NEW_VALUE, { name: this.name, value: value });
147
+ }
148
+
149
+ _subscribeOnce() {
150
+ this.addListener(Urso.events.MODULES_SCENES_MOUSE_NEW_POSITION, this._onMouseMove.bind(this));
151
+ }
152
+ }
153
+
154
+ module.exports = ModulesObjectsModelsSlider;
@@ -0,0 +1,55 @@
1
+ class ModulesObjectsModelsTextInput extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.TEXTINPUT;
6
+ this.text = '';
7
+ this._addBaseObject();
8
+ this._setRestrictedSymbosl();
9
+ }
10
+
11
+ setupParams(params) {
12
+ super.setupParams(params);
13
+
14
+ this.input = Urso.helper.recursiveGet('input', params, false);
15
+ this.box = Urso.helper.recursiveGet('box', params, false);
16
+ this.numbersOnly = Urso.helper.recursiveGet('numbersOnly', params, false);
17
+ this.allowedSymbols = Urso.helper.recursiveGet('allowedSymbols', params, false);
18
+ this.substituteText = Urso.helper.recursiveGet('substituteText', params, false);
19
+ }
20
+
21
+ restrictInput(allowedSymbols) {
22
+ this._baseObject.restrict = allowedSymbols;
23
+ }
24
+
25
+ disable(){
26
+ this._baseObject.disabled = true
27
+ }
28
+
29
+ enable(){
30
+ this._baseObject.disabled = false
31
+ }
32
+
33
+ _setRestrictedSymbosl() {
34
+ if (this.numbersOnly) {
35
+ const regex = new RegExp('^[0-9]*');
36
+ this.restrictInput(regex);
37
+ } else if (this.allowedSymbols) {
38
+ this.restrictInput(this.allowedSymbols);
39
+ }
40
+ }
41
+
42
+ _onBlur(){
43
+ this.text = this._baseObject.text;
44
+ const data = {name: this.name, class: this.class, id: this.id, text: this.text};
45
+ this.emit(Urso.events.MODULES_OBJECTS_TEXTINPUT_BLUR, data);
46
+ }
47
+
48
+ _addBaseObject() {
49
+ this._baseObject = new PIXI.TextInput({ input: this.input, box: this.box });
50
+ this._baseObject.substituteText = this.substituteText;
51
+ this._baseObject.on('blur', this._onBlur.bind(this))
52
+ };
53
+ }
54
+
55
+ module.exports = ModulesObjectsModelsTextInput;