@urso/core 0.6.16-dev → 0.6.17

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 (156) 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/build/js/index.js.LICENSE.txt +0 -48
  6. package/package.json +52 -52
  7. package/src/js/app.js +79 -79
  8. package/src/js/components/_info.js +11 -11
  9. package/src/js/components/base/_info.js +3 -3
  10. package/src/js/components/base/controller.js +78 -78
  11. package/src/js/components/debug/_info.js +7 -7
  12. package/src/js/components/debug/controller.js +38 -38
  13. package/src/js/components/debug/coords.js +23 -23
  14. package/src/js/components/debug/fps.js +36 -36
  15. package/src/js/components/debug/template.js +55 -55
  16. package/src/js/components/debug/timescale.js +60 -60
  17. package/src/js/components/deviceRotate/_info.js +3 -3
  18. package/src/js/components/deviceRotate/controller.js +86 -86
  19. package/src/js/components/fullscreen/_info.js +6 -6
  20. package/src/js/components/fullscreen/android.js +104 -104
  21. package/src/js/components/fullscreen/controller.js +76 -76
  22. package/src/js/components/fullscreen/desktop.js +49 -49
  23. package/src/js/components/fullscreen/ios.js +115 -115
  24. package/src/js/components/layersSwitcher/_info.js +4 -4
  25. package/src/js/components/layersSwitcher/config.js +26 -26
  26. package/src/js/components/layersSwitcher/controller.js +34 -34
  27. package/src/js/components/loader/_info.js +4 -4
  28. package/src/js/components/loader/controller.js +65 -65
  29. package/src/js/components/loader/template.js +70 -70
  30. package/src/js/components/soundInitialPopup/_info.js +3 -3
  31. package/src/js/components/soundInitialPopup/controller.js +42 -42
  32. package/src/js/components/soundInitialPopup/template.js +109 -109
  33. package/src/js/components/stateDriven/_info.js +3 -3
  34. package/src/js/components/stateDriven/controller.js +118 -118
  35. package/src/js/config/load.js +5 -5
  36. package/src/js/config/main.js +16 -16
  37. package/src/js/extra/_info.js +26 -26
  38. package/src/js/extra/browserEvents.js +51 -51
  39. package/src/js/extra/pixiPatch.js +150 -150
  40. package/src/js/extra/setTimeout.js +7 -7
  41. package/src/js/index.js +8 -8
  42. package/src/js/lib/_info.js +13 -13
  43. package/src/js/lib/cache.js +105 -105
  44. package/src/js/lib/composition.js +85 -85
  45. package/src/js/lib/device.js +1286 -1286
  46. package/src/js/lib/helper.js +556 -556
  47. package/src/js/lib/loader.js +136 -136
  48. package/src/js/lib/localData.js +15 -15
  49. package/src/js/lib/logger.js +69 -69
  50. package/src/js/lib/math.js +35 -35
  51. package/src/js/lib/objectPool.js +207 -203
  52. package/src/js/lib/time.js +18 -18
  53. package/src/js/lib/tween.js +147 -147
  54. package/src/js/modules/_info.js +12 -12
  55. package/src/js/modules/assets/_info.js +7 -7
  56. package/src/js/modules/assets/baseModel.js +20 -20
  57. package/src/js/modules/assets/config.js +37 -37
  58. package/src/js/modules/assets/controller.js +46 -46
  59. package/src/js/modules/assets/models/_info.js +11 -11
  60. package/src/js/modules/assets/models/atlas.js +8 -8
  61. package/src/js/modules/assets/models/audiosprite.js +27 -27
  62. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  63. package/src/js/modules/assets/models/container.js +16 -16
  64. package/src/js/modules/assets/models/font.js +8 -8
  65. package/src/js/modules/assets/models/image.js +15 -15
  66. package/src/js/modules/assets/models/json.js +8 -8
  67. package/src/js/modules/assets/models/sound.js +14 -14
  68. package/src/js/modules/assets/models/spine.js +14 -14
  69. package/src/js/modules/assets/service.js +366 -366
  70. package/src/js/modules/i18n/_info.js +4 -4
  71. package/src/js/modules/i18n/config.js +17 -17
  72. package/src/js/modules/i18n/controller.js +79 -79
  73. package/src/js/modules/instances/_info.js +3 -3
  74. package/src/js/modules/instances/controller.js +357 -357
  75. package/src/js/modules/logic/_info.js +4 -4
  76. package/src/js/modules/logic/config/_info.js +2 -2
  77. package/src/js/modules/logic/config/sounds.js +23 -23
  78. package/src/js/modules/logic/controller.js +48 -48
  79. package/src/js/modules/logic/sounds.js +103 -103
  80. package/src/js/modules/objects/_info.js +13 -13
  81. package/src/js/modules/objects/baseModel.js +200 -200
  82. package/src/js/modules/objects/cache.js +99 -99
  83. package/src/js/modules/objects/controller.js +131 -131
  84. package/src/js/modules/objects/find.js +58 -58
  85. package/src/js/modules/objects/models/_info.js +27 -27
  86. package/src/js/modules/objects/models/atlasImage.js +50 -50
  87. package/src/js/modules/objects/models/bitmapText.js +37 -37
  88. package/src/js/modules/objects/models/button.js +189 -189
  89. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  90. package/src/js/modules/objects/models/checkbox.js +96 -96
  91. package/src/js/modules/objects/models/collection.js +54 -54
  92. package/src/js/modules/objects/models/component.js +46 -46
  93. package/src/js/modules/objects/models/container.js +19 -19
  94. package/src/js/modules/objects/models/dragContainer.js +667 -667
  95. package/src/js/modules/objects/models/emitter.js +67 -67
  96. package/src/js/modules/objects/models/emitterFx.js +99 -99
  97. package/src/js/modules/objects/models/graphics.js +38 -38
  98. package/src/js/modules/objects/models/group.js +19 -19
  99. package/src/js/modules/objects/models/hitArea.js +104 -104
  100. package/src/js/modules/objects/models/image.js +34 -34
  101. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  102. package/src/js/modules/objects/models/mask.js +38 -38
  103. package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
  104. package/src/js/modules/objects/models/scrollbox.js +64 -64
  105. package/src/js/modules/objects/models/slider.js +253 -253
  106. package/src/js/modules/objects/models/spine.js +296 -287
  107. package/src/js/modules/objects/models/text.js +59 -59
  108. package/src/js/modules/objects/models/textInput.js +66 -66
  109. package/src/js/modules/objects/models/toggle.js +180 -180
  110. package/src/js/modules/objects/models/world.js +19 -19
  111. package/src/js/modules/objects/propertyAdapter.js +588 -587
  112. package/src/js/modules/objects/proxy.js +294 -294
  113. package/src/js/modules/objects/selector.js +136 -136
  114. package/src/js/modules/objects/service.js +242 -242
  115. package/src/js/modules/objects/styles.js +210 -210
  116. package/src/js/modules/observer/_info.js +4 -4
  117. package/src/js/modules/observer/controller.js +99 -99
  118. package/src/js/modules/observer/events.js +52 -52
  119. package/src/js/modules/scenes/_info.js +8 -8
  120. package/src/js/modules/scenes/controller.js +119 -119
  121. package/src/js/modules/scenes/model.js +28 -28
  122. package/src/js/modules/scenes/pixiWrapper.js +336 -336
  123. package/src/js/modules/scenes/resolutions.js +173 -173
  124. package/src/js/modules/scenes/resolutionsConfig.js +73 -73
  125. package/src/js/modules/scenes/service.js +142 -142
  126. package/src/js/modules/soundManager/_info.js +3 -3
  127. package/src/js/modules/soundManager/controller.js +100 -100
  128. package/src/js/modules/soundManager/soundSprite.js +251 -251
  129. package/src/js/modules/statesManager/_info.js +12 -12
  130. package/src/js/modules/statesManager/action.js +68 -68
  131. package/src/js/modules/statesManager/actions/_info.js +3 -3
  132. package/src/js/modules/statesManager/all.js +23 -23
  133. package/src/js/modules/statesManager/configStates.js +71 -71
  134. package/src/js/modules/statesManager/controller.js +170 -170
  135. package/src/js/modules/statesManager/functionsStorage.js +82 -82
  136. package/src/js/modules/statesManager/helper.js +27 -27
  137. package/src/js/modules/statesManager/race.js +75 -75
  138. package/src/js/modules/statesManager/sequence.js +47 -47
  139. package/src/js/modules/template/_info.js +6 -6
  140. package/src/js/modules/template/controller.js +28 -28
  141. package/src/js/modules/template/model.js +11 -11
  142. package/src/js/modules/template/service.js +137 -137
  143. package/src/js/modules/template/types.js +46 -46
  144. package/src/js/modules/transport/_info.js +8 -8
  145. package/src/js/modules/transport/baseConnectionType.js +24 -24
  146. package/src/js/modules/transport/config.js +13 -13
  147. package/src/js/modules/transport/connectionTypes/_info.js +3 -3
  148. package/src/js/modules/transport/connectionTypes/websocket.js +74 -74
  149. package/src/js/modules/transport/connectionTypes/xhr.js +44 -44
  150. package/src/js/modules/transport/controller.js +48 -48
  151. package/src/js/modules/transport/decorator.js +17 -17
  152. package/src/js/modules/transport/service.js +153 -153
  153. package/src/js/templates/_info.js +4 -4
  154. package/src/js/templates/groups/_info.js +1 -1
  155. package/src/js/templates/scenes/_info.js +1 -1
  156. package/webpack.config.js +47 -47
@@ -1,200 +1,200 @@
1
- class ModulesObjectsBaseModel {
2
- constructor(params) {
3
- this.simpleClass = true;
4
-
5
- this.setupParams(params);
6
-
7
- this.parent = false;
8
- this.destroyed = false;
9
-
10
- //system
11
- this._originalModel = params;
12
- this._classes = [];
13
- this._styles = {};
14
- this._baseObject = null; //link to pixi object
15
- this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
16
- this._templatePath = false;
17
- this._parsed = false;
18
- this._transitions = { tweens: {} };
19
- }
20
-
21
- /**
22
- * setup params to object model
23
- * @param {Object} params
24
- */
25
- setupParams(params) {
26
- this.type = Urso.helper.recursiveGet('type', params, null);
27
-
28
- this.id = Urso.helper.recursiveGet('id', params, false);
29
- this.name = Urso.helper.recursiveGet('name', params, false);
30
- this.class = Urso.helper.recursiveGet('class', params, false);
31
-
32
- this.x = Urso.helper.recursiveGet('x', params, 0); //number or persents (40%)
33
- this.y = Urso.helper.recursiveGet('y', params, 0); //number or persents (40%)
34
- this.z = Urso.helper.recursiveGet('z', params, 0); //number
35
- this.anchorX = Urso.helper.recursiveGet('anchorX', params, 0);
36
- this.anchorY = Urso.helper.recursiveGet('anchorY', params, 0);
37
- this.scaleX = Urso.helper.recursiveGet('scaleX', params, 1);
38
- this.scaleY = Urso.helper.recursiveGet('scaleY', params, 1);
39
- this.alignX = Urso.helper.recursiveGet('alignX', params, 'left'); //or right or center
40
- this.alignY = Urso.helper.recursiveGet('alignY', params, 'top'); //or bottom or center
41
- this.width = Urso.helper.recursiveGet('width', params, false); //or 40% or 1456 // highest priority then scale
42
- this.height = Urso.helper.recursiveGet('height', params, false); //or 40% or 568 // highest priority then scale
43
- this.maxWidth = Urso.helper.recursiveGet('maxWidth', params, false); //maximum width value. If objects width will be higher, it will be downscale. Do not use with scale.
44
- this.maxHeight = Urso.helper.recursiveGet('maxHeight', params, false); //maximum height value. If objects height will be higher, it will be downscale. Do not use with scale.
45
- this.stretchingType = Urso.helper.recursiveGet('stretchingType', params, false); //or inscribed or circumscribed //works only if width=height=100%
46
- this.angle = Urso.helper.recursiveGet('angle', params, 0);
47
- this.visible = Urso.helper.recursiveGet('visible', params, true);
48
- this.alpha = Urso.helper.recursiveGet('alpha', params, 1);
49
- this.blendMode = Urso.helper.recursiveGet('blendMode', params, 1);
50
- this.ignoreParentMask = Urso.helper.recursiveGet('ignoreParentMask', params, false); //if true - do not apply parent mask on rendering
51
-
52
- this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
53
- this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
54
- this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
55
-
56
- this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
57
- this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
58
- }
59
-
60
- getAbsoluteSize() {
61
- return { width: this._baseObject.width, height: this._baseObject.height };
62
- }
63
-
64
- destroy(doNotRefreshStylesFlag) {
65
- Urso.objects.destroy(this, doNotRefreshStylesFlag);
66
- }
67
-
68
- _customDestroy() { }
69
-
70
- addChild(childObject, doNotRefreshStylesFlag) {
71
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
72
- }
73
-
74
- get transform() {
75
- return this._baseObject.transform;
76
- }
77
-
78
- addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
79
- //TODO zIndex
80
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
81
- }
82
-
83
- removeChild(childObject, doNotRefreshStylesFlag) {
84
- Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
85
- }
86
-
87
- setId(id, doNotRefreshStylesFlag) {
88
- if (this.id)
89
- Urso.objects.removeIdFromCache(this.id, this);
90
-
91
- Urso.objects._safeSetValueToTarget(this, 'id', id);
92
-
93
- if (id)
94
- Urso.objects.addIdToCache(id, this);
95
-
96
- if (!doNotRefreshStylesFlag)
97
- Urso.objects.refreshStyles();
98
-
99
- return this;
100
- }
101
-
102
- setName(name, doNotRefreshStylesFlag) {
103
- if (this.name)
104
- Urso.objects.removeNameFromCache(this.name, this);
105
-
106
- Urso.objects._safeSetValueToTarget(this, 'name', name);
107
-
108
- if (name)
109
- Urso.objects.addNameToCache(name, this);
110
-
111
- if (!doNotRefreshStylesFlag)
112
- Urso.objects.refreshStyles();
113
-
114
- return this;
115
- }
116
-
117
- addClass(className, doNotRefreshStylesFlag) {
118
- let currentClass = this.class;
119
- let newClassName;
120
-
121
- if (!currentClass)
122
- newClassName = className;
123
- else {
124
- if (currentClass.split(' ').includes(className))
125
- return this;
126
-
127
- newClassName = this.class + ' ' + className;
128
- }
129
-
130
- Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
131
-
132
- Urso.objects.addClassToCache(className, this);
133
-
134
- if (!doNotRefreshStylesFlag)
135
- Urso.objects.refreshByChangedClassName(className);
136
-
137
- return this;
138
- };
139
-
140
- removeClass(className, doNotRefreshStylesFlag) {
141
- if (!this.class)
142
- return this;
143
-
144
- let classArray = this.class.split(' ');
145
- let classIndex = classArray.indexOf(className);
146
-
147
- if (classIndex === -1)
148
- return this;
149
-
150
- classArray.splice(classIndex, 1);
151
- Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
152
- Urso.objects.removeClassFromCache(className, this);
153
-
154
- if (!doNotRefreshStylesFlag)
155
- Urso.objects.refreshByChangedClassName(className);
156
-
157
- return this;
158
- };
159
-
160
- toGlobal() {
161
- const world = Urso.objects.getWorld();
162
- const worldScale = world._baseObject.scale;
163
- const worldPoint = { x: world.x, y: world.y };
164
- const globalPoint = this._baseObject.toGlobal(worldPoint);
165
-
166
- const x = Math.floor(globalPoint.x / worldScale.x);
167
- const y = Math.floor(globalPoint.y / worldScale.y);
168
-
169
- return { x, y };
170
- }
171
-
172
- toLocal(from) {
173
- const world = Urso.objects.getWorld();
174
- const worldPoint = { x: world.x, y: world.y };
175
- const parent = this.parent ? this.parent._baseObject : world._baseObject;
176
- const fromObj = from ? from._baseObject : parent;
177
- const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
178
-
179
- const x = -~~localPoint.x;
180
- const y = -~~localPoint.y;
181
-
182
- return { x, y };
183
- }
184
-
185
- /**
186
- * generate texture from current object
187
- * @param {String} [key]
188
- * @returns {Object} - pixi.Texture
189
- */
190
- generateTexture(key = '') {
191
- const newTexture = Urso.scenes.generateTexture(this._baseObject);
192
-
193
- if (key)
194
- Urso.cache.addTexture(key, newTexture);
195
-
196
- return newTexture;
197
- }
198
- }
199
-
200
- module.exports = ModulesObjectsBaseModel;
1
+ class ModulesObjectsBaseModel {
2
+ constructor(params) {
3
+ this.simpleClass = true;
4
+
5
+ this.setupParams(params);
6
+
7
+ this.parent = false;
8
+ this.destroyed = false;
9
+
10
+ //system
11
+ this._originalModel = params;
12
+ this._classes = [];
13
+ this._styles = {};
14
+ this._baseObject = null; //link to pixi object
15
+ this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
16
+ this._templatePath = false;
17
+ this._parsed = false;
18
+ this._transitions = { tweens: {} };
19
+ }
20
+
21
+ /**
22
+ * setup params to object model
23
+ * @param {Object} params
24
+ */
25
+ setupParams(params) {
26
+ this.type = Urso.helper.recursiveGet('type', params, null);
27
+
28
+ this.id = Urso.helper.recursiveGet('id', params, false);
29
+ this.name = Urso.helper.recursiveGet('name', params, false);
30
+ this.class = Urso.helper.recursiveGet('class', params, false);
31
+
32
+ this.x = Urso.helper.recursiveGet('x', params, 0); //number or persents (40%)
33
+ this.y = Urso.helper.recursiveGet('y', params, 0); //number or persents (40%)
34
+ this.z = Urso.helper.recursiveGet('z', params, 0); //number
35
+ this.anchorX = Urso.helper.recursiveGet('anchorX', params, 0);
36
+ this.anchorY = Urso.helper.recursiveGet('anchorY', params, 0);
37
+ this.scaleX = Urso.helper.recursiveGet('scaleX', params, 1);
38
+ this.scaleY = Urso.helper.recursiveGet('scaleY', params, 1);
39
+ this.alignX = Urso.helper.recursiveGet('alignX', params, 'left'); //or right or center
40
+ this.alignY = Urso.helper.recursiveGet('alignY', params, 'top'); //or bottom or center
41
+ this.width = Urso.helper.recursiveGet('width', params, false); //or 40% or 1456 // highest priority then scale
42
+ this.height = Urso.helper.recursiveGet('height', params, false); //or 40% or 568 // highest priority then scale
43
+ this.maxWidth = Urso.helper.recursiveGet('maxWidth', params, false); //maximum width value. If objects width will be higher, it will be downscale. Do not use with scale.
44
+ this.maxHeight = Urso.helper.recursiveGet('maxHeight', params, false); //maximum height value. If objects height will be higher, it will be downscale. Do not use with scale.
45
+ this.stretchingType = Urso.helper.recursiveGet('stretchingType', params, false); //or inscribed or circumscribed //works only if width=height=100%
46
+ this.angle = Urso.helper.recursiveGet('angle', params, 0);
47
+ this.visible = Urso.helper.recursiveGet('visible', params, true);
48
+ this.alpha = Urso.helper.recursiveGet('alpha', params, 1);
49
+ this.blendMode = Urso.helper.recursiveGet('blendMode', params, 1);
50
+ this.ignoreParentMask = Urso.helper.recursiveGet('ignoreParentMask', params, false); //if true - do not apply parent mask on rendering
51
+
52
+ this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
53
+ this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
54
+ this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
55
+
56
+ this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
57
+ this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
58
+ }
59
+
60
+ getAbsoluteSize() {
61
+ return { width: this._baseObject.width, height: this._baseObject.height };
62
+ }
63
+
64
+ destroy(doNotRefreshStylesFlag) {
65
+ Urso.objects.destroy(this, doNotRefreshStylesFlag);
66
+ }
67
+
68
+ _customDestroy() { }
69
+
70
+ addChild(childObject, doNotRefreshStylesFlag) {
71
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
72
+ }
73
+
74
+ get transform() {
75
+ return this._baseObject.transform;
76
+ }
77
+
78
+ addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
79
+ //TODO zIndex
80
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
81
+ }
82
+
83
+ removeChild(childObject, doNotRefreshStylesFlag) {
84
+ Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
85
+ }
86
+
87
+ setId(id, doNotRefreshStylesFlag) {
88
+ if (this.id)
89
+ Urso.objects.removeIdFromCache(this.id, this);
90
+
91
+ Urso.objects._safeSetValueToTarget(this, 'id', id);
92
+
93
+ if (id)
94
+ Urso.objects.addIdToCache(id, this);
95
+
96
+ if (!doNotRefreshStylesFlag)
97
+ Urso.objects.refreshStyles();
98
+
99
+ return this;
100
+ }
101
+
102
+ setName(name, doNotRefreshStylesFlag) {
103
+ if (this.name)
104
+ Urso.objects.removeNameFromCache(this.name, this);
105
+
106
+ Urso.objects._safeSetValueToTarget(this, 'name', name);
107
+
108
+ if (name)
109
+ Urso.objects.addNameToCache(name, this);
110
+
111
+ if (!doNotRefreshStylesFlag)
112
+ Urso.objects.refreshStyles();
113
+
114
+ return this;
115
+ }
116
+
117
+ addClass(className, doNotRefreshStylesFlag) {
118
+ let currentClass = this.class;
119
+ let newClassName;
120
+
121
+ if (!currentClass)
122
+ newClassName = className;
123
+ else {
124
+ if (currentClass.split(' ').includes(className))
125
+ return this;
126
+
127
+ newClassName = this.class + ' ' + className;
128
+ }
129
+
130
+ Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
131
+
132
+ Urso.objects.addClassToCache(className, this);
133
+
134
+ if (!doNotRefreshStylesFlag)
135
+ Urso.objects.refreshByChangedClassName(className);
136
+
137
+ return this;
138
+ };
139
+
140
+ removeClass(className, doNotRefreshStylesFlag) {
141
+ if (!this.class)
142
+ return this;
143
+
144
+ let classArray = this.class.split(' ');
145
+ let classIndex = classArray.indexOf(className);
146
+
147
+ if (classIndex === -1)
148
+ return this;
149
+
150
+ classArray.splice(classIndex, 1);
151
+ Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
152
+ Urso.objects.removeClassFromCache(className, this);
153
+
154
+ if (!doNotRefreshStylesFlag)
155
+ Urso.objects.refreshByChangedClassName(className);
156
+
157
+ return this;
158
+ };
159
+
160
+ toGlobal() {
161
+ const world = Urso.objects.getWorld();
162
+ const worldScale = world._baseObject.scale;
163
+ const worldPoint = { x: world.x, y: world.y };
164
+ const globalPoint = this._baseObject.toGlobal(worldPoint);
165
+
166
+ const x = Math.floor(globalPoint.x / worldScale.x);
167
+ const y = Math.floor(globalPoint.y / worldScale.y);
168
+
169
+ return { x, y };
170
+ }
171
+
172
+ toLocal(from) {
173
+ const world = Urso.objects.getWorld();
174
+ const worldPoint = { x: world.x, y: world.y };
175
+ const parent = this.parent ? this.parent._baseObject : world._baseObject;
176
+ const fromObj = from ? from._baseObject : parent;
177
+ const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
178
+
179
+ const x = -~~localPoint.x;
180
+ const y = -~~localPoint.y;
181
+
182
+ return { x, y };
183
+ }
184
+
185
+ /**
186
+ * generate texture from current object
187
+ * @param {String} [key]
188
+ * @returns {Object} - pixi.Texture
189
+ */
190
+ generateTexture(key = '') {
191
+ const newTexture = Urso.scenes.generateTexture(this._baseObject);
192
+
193
+ if (key)
194
+ Urso.cache.addTexture(key, newTexture);
195
+
196
+ return newTexture;
197
+ }
198
+ }
199
+
200
+ module.exports = ModulesObjectsBaseModel;
@@ -1,99 +1,99 @@
1
- class ModulesObjectsCache {
2
- constructor() {
3
- this.singleton = true;
4
- this._data = null;
5
- this.reset();
6
- };
7
-
8
- reset() {
9
- this._data = {
10
- ids: {},
11
- names: {},
12
- classes: {}
13
- }
14
- }
15
-
16
- addId(key, object) {
17
- if (this._data.ids[key])
18
- Urso.logger.error('ModulesObjectsCache error: id will be uniq ' + key);
19
-
20
- this._data.ids[key] = object;
21
- }
22
-
23
- removeId(key, object) {
24
- if (!this._data.ids[key])
25
- Urso.logger.error('ModulesObjectsCache error: no id to remove ' + key);
26
-
27
- if (this._data.ids[key]._uid !== object._uid)
28
- Urso.logger.error('ModulesObjectsCache error: invalid object with id ' + key);
29
-
30
- delete this._data.ids[key];
31
- }
32
-
33
- addName(key, object) {
34
- if (this._data.names[key])
35
- Urso.logger.error('ModulesObjectsCache error: name will be uniq ' + key);
36
-
37
- this._data.names[key] = object;
38
- }
39
-
40
- removeName(key, object) {
41
- if (!this._data.names[key])
42
- Urso.logger.error('ModulesObjectsCache error: no name to remove ' + key);
43
-
44
- if (this._data.names[key]._uid !== object._uid)
45
- Urso.logger.error('ModulesObjectsCache error: invalid object with name ' + key);
46
-
47
- delete this._data.names[key];
48
- }
49
-
50
- addClass(key, object) {
51
- let classNamesArray = key.split(' ');
52
-
53
- for (const className of classNamesArray)
54
- this._addClass(className, object);
55
- }
56
-
57
- removeClass(key, object) {
58
- let classNamesArray = key.split(' ');
59
-
60
- for (const className of classNamesArray)
61
- this._removeClass(className, object);
62
- }
63
-
64
- getId(key) {
65
- return this._data.ids[key] || false;
66
- }
67
-
68
- getName(key) {
69
- return this._data.names[key] || false;
70
- }
71
-
72
- getClass(key) {
73
- if (this._data.classes[key])
74
- return Object.values(this._data.classes[key]);
75
-
76
- return false;
77
- }
78
-
79
- _addClass(key, object) {
80
- if (!this._data.classes[key])
81
- this._data.classes[key] = {};
82
-
83
- if (!this._data.classes[key][object._uid])
84
- this._data.classes[key][object._uid] = object;
85
- }
86
-
87
- _removeClass(key, object) {
88
- if (!this._data.classes[key])
89
- return;
90
-
91
- if (this._data.classes[key][object._uid])
92
- delete this._data.classes[key][object._uid];
93
-
94
- if (!Object.keys(this._data.classes[key]).length)
95
- delete this._data.classes[key];
96
- }
97
- }
98
-
99
- module.exports = ModulesObjectsCache;
1
+ class ModulesObjectsCache {
2
+ constructor() {
3
+ this.singleton = true;
4
+ this._data = null;
5
+ this.reset();
6
+ };
7
+
8
+ reset() {
9
+ this._data = {
10
+ ids: {},
11
+ names: {},
12
+ classes: {}
13
+ }
14
+ }
15
+
16
+ addId(key, object) {
17
+ if (this._data.ids[key])
18
+ Urso.logger.error('ModulesObjectsCache error: id will be uniq ' + key);
19
+
20
+ this._data.ids[key] = object;
21
+ }
22
+
23
+ removeId(key, object) {
24
+ if (!this._data.ids[key])
25
+ Urso.logger.error('ModulesObjectsCache error: no id to remove ' + key);
26
+
27
+ if (this._data.ids[key]._uid !== object._uid)
28
+ Urso.logger.error('ModulesObjectsCache error: invalid object with id ' + key);
29
+
30
+ delete this._data.ids[key];
31
+ }
32
+
33
+ addName(key, object) {
34
+ if (this._data.names[key])
35
+ Urso.logger.error('ModulesObjectsCache error: name will be uniq ' + key);
36
+
37
+ this._data.names[key] = object;
38
+ }
39
+
40
+ removeName(key, object) {
41
+ if (!this._data.names[key])
42
+ Urso.logger.error('ModulesObjectsCache error: no name to remove ' + key);
43
+
44
+ if (this._data.names[key]._uid !== object._uid)
45
+ Urso.logger.error('ModulesObjectsCache error: invalid object with name ' + key);
46
+
47
+ delete this._data.names[key];
48
+ }
49
+
50
+ addClass(key, object) {
51
+ let classNamesArray = key.split(' ');
52
+
53
+ for (const className of classNamesArray)
54
+ this._addClass(className, object);
55
+ }
56
+
57
+ removeClass(key, object) {
58
+ let classNamesArray = key.split(' ');
59
+
60
+ for (const className of classNamesArray)
61
+ this._removeClass(className, object);
62
+ }
63
+
64
+ getId(key) {
65
+ return this._data.ids[key] || false;
66
+ }
67
+
68
+ getName(key) {
69
+ return this._data.names[key] || false;
70
+ }
71
+
72
+ getClass(key) {
73
+ if (this._data.classes[key])
74
+ return Object.values(this._data.classes[key]);
75
+
76
+ return false;
77
+ }
78
+
79
+ _addClass(key, object) {
80
+ if (!this._data.classes[key])
81
+ this._data.classes[key] = {};
82
+
83
+ if (!this._data.classes[key][object._uid])
84
+ this._data.classes[key][object._uid] = object;
85
+ }
86
+
87
+ _removeClass(key, object) {
88
+ if (!this._data.classes[key])
89
+ return;
90
+
91
+ if (this._data.classes[key][object._uid])
92
+ delete this._data.classes[key][object._uid];
93
+
94
+ if (!Object.keys(this._data.classes[key]).length)
95
+ delete this._data.classes[key];
96
+ }
97
+ }
98
+
99
+ module.exports = ModulesObjectsCache;