@urso/core 0.4.45 → 0.4.49

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 +220 -220
  4. package/build/js/index.js +1 -1
  5. package/build/js/index.js.LICENSE.txt +32 -32
  6. package/package.json +51 -51
  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/editor/_info.js +4 -0
  20. package/src/js/components/editor/api.js +72 -0
  21. package/src/js/components/editor/controller.js +13 -0
  22. package/src/js/components/fullscreen/_info.js +6 -6
  23. package/src/js/components/fullscreen/android.js +104 -104
  24. package/src/js/components/fullscreen/controller.js +76 -76
  25. package/src/js/components/fullscreen/desktop.js +49 -49
  26. package/src/js/components/fullscreen/ios.js +115 -115
  27. package/src/js/components/layersSwitcher/_info.js +4 -4
  28. package/src/js/components/layersSwitcher/config.js +26 -26
  29. package/src/js/components/layersSwitcher/controller.js +34 -34
  30. package/src/js/components/loader/_info.js +4 -4
  31. package/src/js/components/loader/controller.js +66 -66
  32. package/src/js/components/loader/template.js +70 -70
  33. package/src/js/components/soundInitialPopup/_info.js +3 -3
  34. package/src/js/components/soundInitialPopup/controller.js +42 -42
  35. package/src/js/components/soundInitialPopup/template.js +109 -109
  36. package/src/js/components/stateDriven/_info.js +3 -3
  37. package/src/js/components/stateDriven/controller.js +118 -118
  38. package/src/js/config/load.js +5 -5
  39. package/src/js/config/main.js +11 -10
  40. package/src/js/extra/_info.js +24 -24
  41. package/src/js/extra/browserEvents.js +38 -38
  42. package/src/js/extra/pixiPatch.js +79 -79
  43. package/src/js/extra/setTimeout.js +7 -7
  44. package/src/js/index.js +8 -8
  45. package/src/js/lib/_info.js +13 -13
  46. package/src/js/lib/cache.js +105 -105
  47. package/src/js/lib/composition.js +85 -85
  48. package/src/js/lib/device.js +1286 -1286
  49. package/src/js/lib/helper.js +539 -539
  50. package/src/js/lib/loader.js +136 -131
  51. package/src/js/lib/localData.js +15 -15
  52. package/src/js/lib/logger.js +22 -22
  53. package/src/js/lib/math.js +35 -35
  54. package/src/js/lib/objectPool.js +54 -54
  55. package/src/js/lib/time.js +18 -18
  56. package/src/js/lib/tween.js +147 -147
  57. package/src/js/modules/_info.js +12 -12
  58. package/src/js/modules/assets/_info.js +7 -7
  59. package/src/js/modules/assets/baseModel.js +18 -18
  60. package/src/js/modules/assets/config.js +37 -37
  61. package/src/js/modules/assets/controller.js +46 -46
  62. package/src/js/modules/assets/models/_info.js +11 -11
  63. package/src/js/modules/assets/models/atlas.js +8 -8
  64. package/src/js/modules/assets/models/audiosprite.js +27 -27
  65. package/src/js/modules/assets/models/bitmapFont.js +8 -8
  66. package/src/js/modules/assets/models/container.js +16 -16
  67. package/src/js/modules/assets/models/font.js +8 -8
  68. package/src/js/modules/assets/models/image.js +13 -13
  69. package/src/js/modules/assets/models/json.js +8 -8
  70. package/src/js/modules/assets/models/sound.js +14 -14
  71. package/src/js/modules/assets/models/spine.js +14 -14
  72. package/src/js/modules/assets/service.js +365 -365
  73. package/src/js/modules/i18n/_info.js +4 -4
  74. package/src/js/modules/i18n/config.js +17 -17
  75. package/src/js/modules/i18n/controller.js +79 -79
  76. package/src/js/modules/instances/_info.js +3 -3
  77. package/src/js/modules/instances/controller.js +261 -261
  78. package/src/js/modules/logic/_info.js +4 -4
  79. package/src/js/modules/logic/config/_info.js +2 -2
  80. package/src/js/modules/logic/config/sounds.js +23 -23
  81. package/src/js/modules/logic/controller.js +48 -48
  82. package/src/js/modules/logic/sounds.js +103 -103
  83. package/src/js/modules/objects/_info.js +11 -11
  84. package/src/js/modules/objects/baseModel.js +197 -197
  85. package/src/js/modules/objects/cache.js +99 -99
  86. package/src/js/modules/objects/controller.js +131 -131
  87. package/src/js/modules/objects/create.js +237 -237
  88. package/src/js/modules/objects/find.js +140 -140
  89. package/src/js/modules/objects/models/_info.js +25 -25
  90. package/src/js/modules/objects/models/atlasImage.js +50 -50
  91. package/src/js/modules/objects/models/bitmapText.js +39 -39
  92. package/src/js/modules/objects/models/button.js +189 -189
  93. package/src/js/modules/objects/models/buttonComposite.js +35 -35
  94. package/src/js/modules/objects/models/checkbox.js +96 -96
  95. package/src/js/modules/objects/models/collection.js +54 -54
  96. package/src/js/modules/objects/models/component.js +44 -44
  97. package/src/js/modules/objects/models/container.js +19 -19
  98. package/src/js/modules/objects/models/emitter.js +67 -54
  99. package/src/js/modules/objects/models/graphics.js +38 -38
  100. package/src/js/modules/objects/models/group.js +19 -19
  101. package/src/js/modules/objects/models/hitArea.js +104 -104
  102. package/src/js/modules/objects/models/image.js +34 -34
  103. package/src/js/modules/objects/models/imagesAnimation.js +113 -113
  104. package/src/js/modules/objects/models/mask.js +38 -38
  105. package/src/js/modules/objects/models/nineSlicePlane.js +30 -30
  106. package/src/js/modules/objects/models/scrollbox.js +61 -61
  107. package/src/js/modules/objects/models/slider.js +253 -253
  108. package/src/js/modules/objects/models/spine.js +271 -271
  109. package/src/js/modules/objects/models/text.js +59 -59
  110. package/src/js/modules/objects/models/textInput.js +66 -66
  111. package/src/js/modules/objects/models/toggle.js +180 -180
  112. package/src/js/modules/objects/models/world.js +19 -19
  113. package/src/js/modules/objects/propertyAdapter.js +422 -422
  114. package/src/js/modules/objects/proxy.js +282 -282
  115. package/src/js/modules/objects/styles.js +120 -120
  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 +44 -44
  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 +139 -139
  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 +243 -243
  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 +45 -45
  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,197 +1,197 @@
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
-
49
- this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
50
- this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
51
- this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
52
-
53
- this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
54
- this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
55
- }
56
-
57
- getAbsoluteSize() {
58
- return { width: this._baseObject.width, height: this._baseObject.height };
59
- }
60
-
61
- destroy(doNotRefreshStylesFlag) {
62
- Urso.objects.destroy(this, doNotRefreshStylesFlag);
63
- }
64
-
65
- _customDestroy() { }
66
-
67
- addChild(childObject, doNotRefreshStylesFlag) {
68
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
69
- }
70
-
71
- get transform() {
72
- return this._baseObject.transform;
73
- }
74
-
75
- addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
76
- //TODO zIndex
77
- Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
78
- }
79
-
80
- removeChild(childObject, doNotRefreshStylesFlag) {
81
- Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
82
- }
83
-
84
- setId(id, doNotRefreshStylesFlag) {
85
- if (this.id)
86
- Urso.objects.removeIdFromCache(this.id, this);
87
-
88
- Urso.objects._safeSetValueToTarget(this, 'id', id);
89
-
90
- if (id)
91
- Urso.objects.addIdToCache(id, this);
92
-
93
- if (!doNotRefreshStylesFlag)
94
- Urso.objects.refreshStyles();
95
-
96
- return this;
97
- }
98
-
99
- setName(name, doNotRefreshStylesFlag) {
100
- if (this.name)
101
- Urso.objects.removeNameFromCache(this.name, this);
102
-
103
- Urso.objects._safeSetValueToTarget(this, 'name', name);
104
-
105
- if (name)
106
- Urso.objects.addNameToCache(name, this);
107
-
108
- if (!doNotRefreshStylesFlag)
109
- Urso.objects.refreshStyles();
110
-
111
- return this;
112
- }
113
-
114
- addClass(className, doNotRefreshStylesFlag) {
115
- let currentClass = this.class;
116
- let newClassName;
117
-
118
- if (!currentClass)
119
- newClassName = className;
120
- else {
121
- if (currentClass.split(' ').includes(className))
122
- return this;
123
-
124
- newClassName = this.class + ' ' + className;
125
- }
126
-
127
- Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
128
-
129
- Urso.objects.addClassToCache(className, this);
130
-
131
- if (!doNotRefreshStylesFlag)
132
- Urso.objects.refreshByChangedClassName(className);
133
-
134
- return this;
135
- };
136
-
137
- removeClass(className, doNotRefreshStylesFlag) {
138
- if (!this.class)
139
- return this;
140
-
141
- let classArray = this.class.split(' ');
142
- let classIndex = classArray.indexOf(className);
143
-
144
- if (classIndex === -1)
145
- return this;
146
-
147
- classArray.splice(classIndex, 1);
148
- Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
149
- Urso.objects.removeClassFromCache(className, this);
150
-
151
- if (!doNotRefreshStylesFlag)
152
- Urso.objects.refreshByChangedClassName(className);
153
-
154
- return this;
155
- };
156
-
157
- toGlobal() {
158
- const world = Urso.objects.getWorld();
159
- const worldScale = world._baseObject.scale;
160
- const worldPoint = { x: world.x, y: world.y };
161
- const globalPoint = this._baseObject.toGlobal(worldPoint);
162
-
163
- const x = Math.floor(globalPoint.x / worldScale.x);
164
- const y = Math.floor(globalPoint.y / worldScale.y);
165
-
166
- return { x, y };
167
- }
168
-
169
- toLocal(from) {
170
- const world = Urso.objects.getWorld();
171
- const worldPoint = { x: world.x, y: world.y };
172
- const parent = this.parent ? this.parent._baseObject : world._baseObject;
173
- const fromObj = from ? from._baseObject : parent;
174
- const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
175
-
176
- const x = -~~localPoint.x;
177
- const y = -~~localPoint.y;
178
-
179
- return { x, y };
180
- }
181
-
182
- /**
183
- * generate texture from current object
184
- * @param {String} [key]
185
- * @returns {Object} - pixi.Texture
186
- */
187
- generateTexture(key = '') {
188
- const newTexture = Urso.scenes.generateTexture(this._baseObject);
189
-
190
- if (key)
191
- Urso.cache.addTexture(key, newTexture);
192
-
193
- return newTexture;
194
- }
195
- }
196
-
197
- 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
+
49
+ this.transitionDelay = Urso.helper.recursiveGet('transitionDelay', params, false); //time in ms
50
+ this.transitionDuration = Urso.helper.recursiveGet('transitionDuration', params, false); //time in ms
51
+ this.transitionProperty = Urso.helper.recursiveGet('transitionProperty', params, false); //props list ex: 'x', 'x y', 'x y alpha'
52
+
53
+ this.append = Urso.helper.recursiveGet('append', params, true); //if false - object will not created //TODO
54
+ this.custom = Urso.helper.recursiveGet('custom', params, {}); //custom params
55
+ }
56
+
57
+ getAbsoluteSize() {
58
+ return { width: this._baseObject.width, height: this._baseObject.height };
59
+ }
60
+
61
+ destroy(doNotRefreshStylesFlag) {
62
+ Urso.objects.destroy(this, doNotRefreshStylesFlag);
63
+ }
64
+
65
+ _customDestroy() { }
66
+
67
+ addChild(childObject, doNotRefreshStylesFlag) {
68
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
69
+ }
70
+
71
+ get transform() {
72
+ return this._baseObject.transform;
73
+ }
74
+
75
+ addChildAt(childObject, zIndex, doNotRefreshStylesFlag) {
76
+ //TODO zIndex
77
+ Urso.objects.addChild(this, childObject, doNotRefreshStylesFlag);
78
+ }
79
+
80
+ removeChild(childObject, doNotRefreshStylesFlag) {
81
+ Urso.objects.removeChild(this, childObject, doNotRefreshStylesFlag);
82
+ }
83
+
84
+ setId(id, doNotRefreshStylesFlag) {
85
+ if (this.id)
86
+ Urso.objects.removeIdFromCache(this.id, this);
87
+
88
+ Urso.objects._safeSetValueToTarget(this, 'id', id);
89
+
90
+ if (id)
91
+ Urso.objects.addIdToCache(id, this);
92
+
93
+ if (!doNotRefreshStylesFlag)
94
+ Urso.objects.refreshStyles();
95
+
96
+ return this;
97
+ }
98
+
99
+ setName(name, doNotRefreshStylesFlag) {
100
+ if (this.name)
101
+ Urso.objects.removeNameFromCache(this.name, this);
102
+
103
+ Urso.objects._safeSetValueToTarget(this, 'name', name);
104
+
105
+ if (name)
106
+ Urso.objects.addNameToCache(name, this);
107
+
108
+ if (!doNotRefreshStylesFlag)
109
+ Urso.objects.refreshStyles();
110
+
111
+ return this;
112
+ }
113
+
114
+ addClass(className, doNotRefreshStylesFlag) {
115
+ let currentClass = this.class;
116
+ let newClassName;
117
+
118
+ if (!currentClass)
119
+ newClassName = className;
120
+ else {
121
+ if (currentClass.split(' ').includes(className))
122
+ return this;
123
+
124
+ newClassName = this.class + ' ' + className;
125
+ }
126
+
127
+ Urso.objects._safeSetValueToTarget(this, 'class', newClassName);
128
+
129
+ Urso.objects.addClassToCache(className, this);
130
+
131
+ if (!doNotRefreshStylesFlag)
132
+ Urso.objects.refreshByChangedClassName(className);
133
+
134
+ return this;
135
+ };
136
+
137
+ removeClass(className, doNotRefreshStylesFlag) {
138
+ if (!this.class)
139
+ return this;
140
+
141
+ let classArray = this.class.split(' ');
142
+ let classIndex = classArray.indexOf(className);
143
+
144
+ if (classIndex === -1)
145
+ return this;
146
+
147
+ classArray.splice(classIndex, 1);
148
+ Urso.objects._safeSetValueToTarget(this, 'class', classArray.join(' '));
149
+ Urso.objects.removeClassFromCache(className, this);
150
+
151
+ if (!doNotRefreshStylesFlag)
152
+ Urso.objects.refreshByChangedClassName(className);
153
+
154
+ return this;
155
+ };
156
+
157
+ toGlobal() {
158
+ const world = Urso.objects.getWorld();
159
+ const worldScale = world._baseObject.scale;
160
+ const worldPoint = { x: world.x, y: world.y };
161
+ const globalPoint = this._baseObject.toGlobal(worldPoint);
162
+
163
+ const x = Math.floor(globalPoint.x / worldScale.x);
164
+ const y = Math.floor(globalPoint.y / worldScale.y);
165
+
166
+ return { x, y };
167
+ }
168
+
169
+ toLocal(from) {
170
+ const world = Urso.objects.getWorld();
171
+ const worldPoint = { x: world.x, y: world.y };
172
+ const parent = this.parent ? this.parent._baseObject : world._baseObject;
173
+ const fromObj = from ? from._baseObject : parent;
174
+ const localPoint = this._baseObject.toLocal(worldPoint, fromObj);
175
+
176
+ const x = -~~localPoint.x;
177
+ const y = -~~localPoint.y;
178
+
179
+ return { x, y };
180
+ }
181
+
182
+ /**
183
+ * generate texture from current object
184
+ * @param {String} [key]
185
+ * @returns {Object} - pixi.Texture
186
+ */
187
+ generateTexture(key = '') {
188
+ const newTexture = Urso.scenes.generateTexture(this._baseObject);
189
+
190
+ if (key)
191
+ Urso.cache.addTexture(key, newTexture);
192
+
193
+ return newTexture;
194
+ }
195
+ }
196
+
197
+ 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;