@urso/core 0.5.11 → 0.5.12

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 (159) hide show
  1. package/.babelrc +11 -11
  2. package/LICENSE +20 -20
  3. package/README.md +220 -220
  4. package/build/js/index.js +1 -1
  5. package/build/js/index.js.LICENSE.txt +222 -38
  6. package/package.json +52 -52
  7. package/src/js/app.js +78 -78
  8. package/src/js/components/_info.js +10 -10
  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 +34 -34
  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 +12 -12
  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 +148 -148
  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 +539 -539
  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 +54 -54
  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 +18 -18
  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 +13 -13
  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 +365 -365
  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 +261 -261
  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 +198 -198
  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 +44 -44
  93. package/src/js/modules/objects/models/container.js +19 -19
  94. package/src/js/modules/objects/models/dragContainer.js +675 -675
  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 +276 -276
  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 +587 -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 +51 -51
  119. package/src/js/modules/scenes/_info.js +8 -8
  120. package/src/js/modules/scenes/controller.js +103 -103
  121. package/src/js/modules/scenes/model.js +28 -28
  122. package/src/js/modules/scenes/pixiWrapper.js +237 -237
  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 +250 -250
  129. package/src/js/modules/statesManager/_info.js +12 -12
  130. package/src/js/modules/statesManager/action.js +60 -60
  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
  157. package/src/js/components/editor/_info.js +0 -4
  158. package/src/js/components/editor/api.js +0 -72
  159. package/src/js/components/editor/controller.js +0 -13
@@ -1,198 +1,198 @@
1
- class ModulesObjectsBaseModel {
2
- constructor(params) {
3
- this.setupParams(params);
4
-
5
- this.parent = false;
6
- this.destroyed = false;
7
-
8
- //system
9
- this._originalModel = params;
10
- this._classes = [];
11
- this._styles = {};
12
- this._baseObject = null; //link to pixi object
13
- this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
14
- this._templatePath = false;
15
- this._parsed = false;
16
- this._transitions = { tweens: {} };
17
- }
18
-
19
- /**
20
- * setup params to object model
21
- * @param {Object} params
22
- */
23
- setupParams(params) {
24
- this.type = Urso.helper.recursiveGet('type', params, null);
25
-
26
- this.id = Urso.helper.recursiveGet('id', params, false);
27
- this.name = Urso.helper.recursiveGet('name', params, false);
28
- this.class = Urso.helper.recursiveGet('class', params, false);
29
-
30
- this.x = Urso.helper.recursiveGet('x', params, 0); //number or persents (40%)
31
- this.y = Urso.helper.recursiveGet('y', params, 0); //number or persents (40%)
32
- this.z = Urso.helper.recursiveGet('z', params, 0); //number
33
- this.anchorX = Urso.helper.recursiveGet('anchorX', params, 0);
34
- this.anchorY = Urso.helper.recursiveGet('anchorY', params, 0);
35
- this.scaleX = Urso.helper.recursiveGet('scaleX', params, 1);
36
- this.scaleY = Urso.helper.recursiveGet('scaleY', params, 1);
37
- this.alignX = Urso.helper.recursiveGet('alignX', params, 'left'); //or right or center
38
- this.alignY = Urso.helper.recursiveGet('alignY', params, 'top'); //or bottom or center
39
- this.width = Urso.helper.recursiveGet('width', params, false); //or 40% or 1456 // highest priority then scale
40
- this.height = Urso.helper.recursiveGet('height', params, false); //or 40% or 568 // highest priority then scale
41
- 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.
42
- 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.
43
- this.stretchingType = Urso.helper.recursiveGet('stretchingType', params, false); //or inscribed or circumscribed //works only if width=height=100%
44
- this.angle = Urso.helper.recursiveGet('angle', params, 0);
45
- this.visible = Urso.helper.recursiveGet('visible', params, true);
46
- this.alpha = Urso.helper.recursiveGet('alpha', params, 1);
47
- this.blendMode = Urso.helper.recursiveGet('blendMode', params, 1);
48
- this.ignoreParentMask = Urso.helper.recursiveGet('ignoreParentMask', params, false); //if true - do not apply parent mask on rendering
49
-
50
- this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
51
- this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
52
- this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
53
-
54
- this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
55
- this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
56
- }
57
-
58
- getAbsoluteSize() {
59
- return { width: this._baseObject.width, height: this._baseObject.height };
60
- }
61
-
62
- destroy(doNotRefreshStylesFlag) {
63
- Urso.objects.destroy(this, doNotRefreshStylesFlag);
64
- }
65
-
66
- _customDestroy() { }
67
-
68
- addChild(childObject, doNotRefreshStylesFlag) {
69
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
70
- }
71
-
72
- get transform() {
73
- return this._baseObject.transform;
74
- }
75
-
76
- addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
77
- //TODO zIndex
78
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
79
- }
80
-
81
- removeChild(childObject, doNotRefreshStylesFlag) {
82
- Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
83
- }
84
-
85
- setId(id, doNotRefreshStylesFlag) {
86
- if (this.id)
87
- Urso.objects.removeIdFromCache(this.id, this);
88
-
89
- Urso.objects._safeSetValueToTarget(this, 'id', id);
90
-
91
- if (id)
92
- Urso.objects.addIdToCache(id, this);
93
-
94
- if (!doNotRefreshStylesFlag)
95
- Urso.objects.refreshStyles();
96
-
97
- return this;
98
- }
99
-
100
- setName(name, doNotRefreshStylesFlag) {
101
- if (this.name)
102
- Urso.objects.removeNameFromCache(this.name, this);
103
-
104
- Urso.objects._safeSetValueToTarget(this, 'name', name);
105
-
106
- if (name)
107
- Urso.objects.addNameToCache(name, this);
108
-
109
- if (!doNotRefreshStylesFlag)
110
- Urso.objects.refreshStyles();
111
-
112
- return this;
113
- }
114
-
115
- addClass(className, doNotRefreshStylesFlag) {
116
- let currentClass = this.class;
117
- let newClassName;
118
-
119
- if (!currentClass)
120
- newClassName = className;
121
- else {
122
- if (currentClass.split(' ').includes(className))
123
- return this;
124
-
125
- newClassName = this.class + ' ' + className;
126
- }
127
-
128
- Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
129
-
130
- Urso.objects.addClassToCache(className, this);
131
-
132
- if (!doNotRefreshStylesFlag)
133
- Urso.objects.refreshByChangedClassName(className);
134
-
135
- return this;
136
- };
137
-
138
- removeClass(className, doNotRefreshStylesFlag) {
139
- if (!this.class)
140
- return this;
141
-
142
- let classArray = this.class.split(' ');
143
- let classIndex = classArray.indexOf(className);
144
-
145
- if (classIndex === -1)
146
- return this;
147
-
148
- classArray.splice(classIndex, 1);
149
- Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
150
- Urso.objects.removeClassFromCache(className, this);
151
-
152
- if (!doNotRefreshStylesFlag)
153
- Urso.objects.refreshByChangedClassName(className);
154
-
155
- return this;
156
- };
157
-
158
- toGlobal() {
159
- const world = Urso.objects.getWorld();
160
- const worldScale = world._baseObject.scale;
161
- const worldPoint = { x: world.x, y: world.y };
162
- const globalPoint = this._baseObject.toGlobal(worldPoint);
163
-
164
- const x = Math.floor(globalPoint.x / worldScale.x);
165
- const y = Math.floor(globalPoint.y / worldScale.y);
166
-
167
- return { x, y };
168
- }
169
-
170
- toLocal(from) {
171
- const world = Urso.objects.getWorld();
172
- const worldPoint = { x: world.x, y: world.y };
173
- const parent = this.parent ? this.parent._baseObject : world._baseObject;
174
- const fromObj = from ? from._baseObject : parent;
175
- const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
176
-
177
- const x = -~~localPoint.x;
178
- const y = -~~localPoint.y;
179
-
180
- return { x, y };
181
- }
182
-
183
- /**
184
- * generate texture from current object
185
- * @param {String} [key]
186
- * @returns {Object} - pixi.Texture
187
- */
188
- generateTexture(key = '') {
189
- const newTexture = Urso.scenes.generateTexture(this._baseObject);
190
-
191
- if (key)
192
- Urso.cache.addTexture(key, newTexture);
193
-
194
- return newTexture;
195
- }
196
- }
197
-
198
- module.exports = ModulesObjectsBaseModel;
1
+ class ModulesObjectsBaseModel {
2
+ constructor(params) {
3
+ this.setupParams(params);
4
+
5
+ this.parent = false;
6
+ this.destroyed = false;
7
+
8
+ //system
9
+ this._originalModel = params;
10
+ this._classes = [];
11
+ this._styles = {};
12
+ this._baseObject = null; //link to pixi object
13
+ this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
14
+ this._templatePath = false;
15
+ this._parsed = false;
16
+ this._transitions = { tweens: {} };
17
+ }
18
+
19
+ /**
20
+ * setup params to object model
21
+ * @param {Object} params
22
+ */
23
+ setupParams(params) {
24
+ this.type = Urso.helper.recursiveGet('type', params, null);
25
+
26
+ this.id = Urso.helper.recursiveGet('id', params, false);
27
+ this.name = Urso.helper.recursiveGet('name', params, false);
28
+ this.class = Urso.helper.recursiveGet('class', params, false);
29
+
30
+ this.x = Urso.helper.recursiveGet('x', params, 0); //number or persents (40%)
31
+ this.y = Urso.helper.recursiveGet('y', params, 0); //number or persents (40%)
32
+ this.z = Urso.helper.recursiveGet('z', params, 0); //number
33
+ this.anchorX = Urso.helper.recursiveGet('anchorX', params, 0);
34
+ this.anchorY = Urso.helper.recursiveGet('anchorY', params, 0);
35
+ this.scaleX = Urso.helper.recursiveGet('scaleX', params, 1);
36
+ this.scaleY = Urso.helper.recursiveGet('scaleY', params, 1);
37
+ this.alignX = Urso.helper.recursiveGet('alignX', params, 'left'); //or right or center
38
+ this.alignY = Urso.helper.recursiveGet('alignY', params, 'top'); //or bottom or center
39
+ this.width = Urso.helper.recursiveGet('width', params, false); //or 40% or 1456 // highest priority then scale
40
+ this.height = Urso.helper.recursiveGet('height', params, false); //or 40% or 568 // highest priority then scale
41
+ 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.
42
+ 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.
43
+ this.stretchingType = Urso.helper.recursiveGet('stretchingType', params, false); //or inscribed or circumscribed //works only if width=height=100%
44
+ this.angle = Urso.helper.recursiveGet('angle', params, 0);
45
+ this.visible = Urso.helper.recursiveGet('visible', params, true);
46
+ this.alpha = Urso.helper.recursiveGet('alpha', params, 1);
47
+ this.blendMode = Urso.helper.recursiveGet('blendMode', params, 1);
48
+ this.ignoreParentMask = Urso.helper.recursiveGet('ignoreParentMask', params, false); //if true - do not apply parent mask on rendering
49
+
50
+ this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
51
+ this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
52
+ this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
53
+
54
+ this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
55
+ this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
56
+ }
57
+
58
+ getAbsoluteSize() {
59
+ return { width: this._baseObject.width, height: this._baseObject.height };
60
+ }
61
+
62
+ destroy(doNotRefreshStylesFlag) {
63
+ Urso.objects.destroy(this, doNotRefreshStylesFlag);
64
+ }
65
+
66
+ _customDestroy() { }
67
+
68
+ addChild(childObject, doNotRefreshStylesFlag) {
69
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
70
+ }
71
+
72
+ get transform() {
73
+ return this._baseObject.transform;
74
+ }
75
+
76
+ addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
77
+ //TODO zIndex
78
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
79
+ }
80
+
81
+ removeChild(childObject, doNotRefreshStylesFlag) {
82
+ Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
83
+ }
84
+
85
+ setId(id, doNotRefreshStylesFlag) {
86
+ if (this.id)
87
+ Urso.objects.removeIdFromCache(this.id, this);
88
+
89
+ Urso.objects._safeSetValueToTarget(this, 'id', id);
90
+
91
+ if (id)
92
+ Urso.objects.addIdToCache(id, this);
93
+
94
+ if (!doNotRefreshStylesFlag)
95
+ Urso.objects.refreshStyles();
96
+
97
+ return this;
98
+ }
99
+
100
+ setName(name, doNotRefreshStylesFlag) {
101
+ if (this.name)
102
+ Urso.objects.removeNameFromCache(this.name, this);
103
+
104
+ Urso.objects._safeSetValueToTarget(this, 'name', name);
105
+
106
+ if (name)
107
+ Urso.objects.addNameToCache(name, this);
108
+
109
+ if (!doNotRefreshStylesFlag)
110
+ Urso.objects.refreshStyles();
111
+
112
+ return this;
113
+ }
114
+
115
+ addClass(className, doNotRefreshStylesFlag) {
116
+ let currentClass = this.class;
117
+ let newClassName;
118
+
119
+ if (!currentClass)
120
+ newClassName = className;
121
+ else {
122
+ if (currentClass.split(' ').includes(className))
123
+ return this;
124
+
125
+ newClassName = this.class + ' ' + className;
126
+ }
127
+
128
+ Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
129
+
130
+ Urso.objects.addClassToCache(className, this);
131
+
132
+ if (!doNotRefreshStylesFlag)
133
+ Urso.objects.refreshByChangedClassName(className);
134
+
135
+ return this;
136
+ };
137
+
138
+ removeClass(className, doNotRefreshStylesFlag) {
139
+ if (!this.class)
140
+ return this;
141
+
142
+ let classArray = this.class.split(' ');
143
+ let classIndex = classArray.indexOf(className);
144
+
145
+ if (classIndex === -1)
146
+ return this;
147
+
148
+ classArray.splice(classIndex, 1);
149
+ Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
150
+ Urso.objects.removeClassFromCache(className, this);
151
+
152
+ if (!doNotRefreshStylesFlag)
153
+ Urso.objects.refreshByChangedClassName(className);
154
+
155
+ return this;
156
+ };
157
+
158
+ toGlobal() {
159
+ const world = Urso.objects.getWorld();
160
+ const worldScale = world._baseObject.scale;
161
+ const worldPoint = { x: world.x, y: world.y };
162
+ const globalPoint = this._baseObject.toGlobal(worldPoint);
163
+
164
+ const x = Math.floor(globalPoint.x / worldScale.x);
165
+ const y = Math.floor(globalPoint.y / worldScale.y);
166
+
167
+ return { x, y };
168
+ }
169
+
170
+ toLocal(from) {
171
+ const world = Urso.objects.getWorld();
172
+ const worldPoint = { x: world.x, y: world.y };
173
+ const parent = this.parent ? this.parent._baseObject : world._baseObject;
174
+ const fromObj = from ? from._baseObject : parent;
175
+ const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
176
+
177
+ const x = -~~localPoint.x;
178
+ const y = -~~localPoint.y;
179
+
180
+ return { x, y };
181
+ }
182
+
183
+ /**
184
+ * generate texture from current object
185
+ * @param {String} [key]
186
+ * @returns {Object} - pixi.Texture
187
+ */
188
+ generateTexture(key = '') {
189
+ const newTexture = Urso.scenes.generateTexture(this._baseObject);
190
+
191
+ if (key)
192
+ Urso.cache.addTexture(key, newTexture);
193
+
194
+ return newTexture;
195
+ }
196
+ }
197
+
198
+ 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;