@urso/core 0.3.12 → 0.4.3
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.
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/app.js +1 -0
- package/src/js/lib/composition.js +22 -26
- package/src/js/modules/_info.js +1 -0
- package/src/js/modules/assets/service.js +1 -1
- package/src/js/modules/i18n/_info.js +4 -0
- package/src/js/modules/i18n/config.js +17 -0
- package/src/js/modules/i18n/controller.js +64 -0
- package/src/js/modules/instances/controller.js +34 -2
- package/src/js/modules/objects/baseModel.js +5 -0
- package/src/js/modules/objects/controller.js +13 -3
- package/src/js/modules/objects/models/bitmapText.js +14 -0
- package/src/js/modules/objects/models/spine.js +118 -12
- package/src/js/modules/objects/models/text.js +13 -0
- package/src/js/modules/observer/events.js +1 -0
- package/src/js/modules/scenes/controller.js +4 -0
- package/src/js/modules/scenes/service.js +14 -1
- package/src/js/modules/template/controller.js +2 -2
- package/src/js/modules/template/service.js +14 -2
package/package.json
CHANGED
package/src/js/app.js
CHANGED
|
@@ -44,6 +44,7 @@ class App {
|
|
|
44
44
|
|
|
45
45
|
//Modules
|
|
46
46
|
Urso.assets = Urso.getInstance('Modules.Assets.Controller');
|
|
47
|
+
Urso.i18n = Urso.getInstance('Modules.I18n.Controller');
|
|
47
48
|
Urso.transport = Urso.getInstance('Modules.Transport.Controller');
|
|
48
49
|
Urso.logic = Urso.getInstance('Modules.Logic.Controller');
|
|
49
50
|
Urso.objects = Urso.getInstance('Modules.Objects.Controller');
|
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
// Class for creating multi inheritance.
|
|
2
|
-
class LibComposition
|
|
3
|
-
{
|
|
2
|
+
class LibComposition {
|
|
4
3
|
// Inherit method to create base classes.
|
|
5
|
-
static inherit(..._bases)
|
|
6
|
-
{
|
|
4
|
+
static inherit(..._bases) {
|
|
7
5
|
class classes {
|
|
8
6
|
|
|
9
7
|
// The base classes
|
|
10
|
-
|
|
8
|
+
get base() { return _bases; }
|
|
11
9
|
|
|
12
|
-
constructor(..._args)
|
|
13
|
-
{
|
|
10
|
+
constructor(..._args) {
|
|
14
11
|
let index = 0;
|
|
15
12
|
|
|
16
|
-
for (let b of this.base)
|
|
17
|
-
{
|
|
13
|
+
for (let b of this.base) {
|
|
18
14
|
let obj = new b(_args[index++]);
|
|
19
|
-
|
|
15
|
+
LibComposition.copy(this, obj);
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
|
|
18
|
+
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
// Copy over properties and methods
|
|
26
|
-
for (let base of _bases)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
LibComposition.copy(classes.prototype, base.prototype);
|
|
22
|
+
for (let base of _bases) {
|
|
23
|
+
LibComposition.copy(classes, base);
|
|
24
|
+
LibComposition.copy(classes.prototype, base.prototype, true);
|
|
30
25
|
}
|
|
31
26
|
|
|
32
27
|
return classes;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
// Copies the properties from one class to another
|
|
36
|
-
static copy(_target, _source)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
static copy(_target, _source, protoFlag) {
|
|
32
|
+
for (let key of Reflect.ownKeys(_source)) {
|
|
33
|
+
if (key !== "constructor" && key !== "prototype" && key !== "name") {
|
|
34
|
+
let desc = Object.getOwnPropertyDescriptor(_source, key);
|
|
35
|
+
Object.defineProperty(_target, key, desc);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (protoFlag && Object.getPrototypeOf(_source) !== Object.prototype) {
|
|
40
|
+
LibComposition.copy(_target, Object.getPrototypeOf(_source));
|
|
41
|
+
}
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -50,7 +46,7 @@ module.exports = LibComposition;
|
|
|
50
46
|
|
|
51
47
|
|
|
52
48
|
/**
|
|
53
|
-
*
|
|
49
|
+
*
|
|
54
50
|
example:
|
|
55
51
|
|
|
56
52
|
|
package/src/js/modules/_info.js
CHANGED
|
@@ -38,7 +38,7 @@ class ModulesAssetsService {
|
|
|
38
38
|
Urso.scenes.loadUpdate(Math.floor(param.progress));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
loadGroup(group, callback) {
|
|
41
|
+
loadGroup(group, callback = () => { }) {
|
|
42
42
|
if (!this.assets[group])
|
|
43
43
|
return Urso.logger.error('ModulesAssetsService group error, no assets:' + group + ' Check ModulesAssetsConfig please');
|
|
44
44
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class ModulesI18nConfig {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.singleton = true;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* example of locales. Set please your keys and paths
|
|
7
|
+
*/
|
|
8
|
+
this.locales = {
|
|
9
|
+
'de': 'i18n/de.json',
|
|
10
|
+
'en': 'i18n/en.json',
|
|
11
|
+
'ru': 'i18n/ru.json'
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = ModulesI18nConfig;
|
|
17
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
class ModulesI18nController {
|
|
2
|
+
|
|
3
|
+
#vocabulary = null;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* get text by localeId
|
|
7
|
+
* @param {String} localeId
|
|
8
|
+
*/
|
|
9
|
+
get(localeId) {
|
|
10
|
+
return this.#vocabulary && this.#vocabulary[localeId] || localeId;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* set alredy loaded as asset locale
|
|
15
|
+
* @param {String} localeKey - loaded json asset key with locale
|
|
16
|
+
*/
|
|
17
|
+
setLocale(localeKey) {
|
|
18
|
+
const jsonResource = Urso.cache.getJson(localeKey);
|
|
19
|
+
|
|
20
|
+
if (!jsonResource)
|
|
21
|
+
return Urso.logger.error('ModulesI18nController setLocale error, no loaded json:' + localeKey + '. Check assets please');
|
|
22
|
+
|
|
23
|
+
this.#vocabulary = jsonResource.data;
|
|
24
|
+
this.emit(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, localeKey);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* load json with locale, store as asset witn localeKey as key and set locale
|
|
29
|
+
* @param {String} localeKey
|
|
30
|
+
* @param {String} [pathToLocaleJson] if this param will not used - we will check localeKey in config
|
|
31
|
+
*/
|
|
32
|
+
loadAndSetLocale(localeKey, pathToLocaleJson) {
|
|
33
|
+
//check if localeKey was alredy loaded
|
|
34
|
+
const jsonResource = Urso.cache.getJson(localeKey);
|
|
35
|
+
|
|
36
|
+
if (jsonResource) {
|
|
37
|
+
this.setLocale(localeKey);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//load locale by path
|
|
41
|
+
if (pathToLocaleJson) {
|
|
42
|
+
this._loadLocaleByPath(localeKey, pathToLocaleJson);
|
|
43
|
+
} else { //we will check localeKey in config
|
|
44
|
+
this._loadLocaleByConfig(localeKey);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_loadLocaleByConfig(localeKey) {
|
|
49
|
+
const locales = this.getInstance('Config').locales;
|
|
50
|
+
const pathToLocaleJson = locales[localeKey];
|
|
51
|
+
|
|
52
|
+
if (!pathToLocaleJson)
|
|
53
|
+
return Urso.logger.error('ModulesI18nController _loadLocaleByConfig error, no locale data in config:' + localeKey + '. Check ModulesI18nConfig please');
|
|
54
|
+
|
|
55
|
+
this._loadLocaleByPath(localeKey, pathToLocaleJson);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_loadLocaleByPath(localeKey, pathToLocaleJson) {
|
|
59
|
+
const localeAsset = { type: Urso.types.assets.JSON, key: localeKey, path: pathToLocaleJson };
|
|
60
|
+
Urso.assets.preload(localeAsset, () => this.setLocale(localeKey));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = ModulesI18nController;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const MODES_NAMESPACE = 'modifications';
|
|
2
|
+
const MIXINS_NAMESPACE = 'mixins';
|
|
3
|
+
|
|
1
4
|
class ModulesInstancesController {
|
|
2
5
|
constructor() {
|
|
3
6
|
this._modes = [];
|
|
@@ -181,10 +184,18 @@ class ModulesInstancesController {
|
|
|
181
184
|
_checkPathExist(entitiesArray, noModes) {
|
|
182
185
|
let currentTestObject = window;
|
|
183
186
|
let testMode;
|
|
187
|
+
let mixins = [];
|
|
184
188
|
|
|
185
189
|
for (let entitiesIndex = 0; entitiesIndex < entitiesArray.length; entitiesIndex++) {
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
const lastElementModesCondition = !noModes && this._modes && entitiesIndex === entitiesArray.length - 1;
|
|
191
|
+
|
|
192
|
+
//get path modification
|
|
193
|
+
if (lastElementModesCondition && currentTestObject[MODES_NAMESPACE])
|
|
194
|
+
testMode = this._checkPathWithModes(currentTestObject[MODES_NAMESPACE], entitiesArray, entitiesIndex);
|
|
195
|
+
|
|
196
|
+
//get path mixins
|
|
197
|
+
if (lastElementModesCondition && currentTestObject[MIXINS_NAMESPACE])
|
|
198
|
+
mixins = this._getMixins(currentTestObject[MIXINS_NAMESPACE], entitiesArray, entitiesIndex);
|
|
188
199
|
|
|
189
200
|
if (testMode)
|
|
190
201
|
currentTestObject = testMode;
|
|
@@ -194,6 +205,13 @@ class ModulesInstancesController {
|
|
|
194
205
|
return false;
|
|
195
206
|
}
|
|
196
207
|
|
|
208
|
+
//mixins
|
|
209
|
+
mixins.forEach((mixin) => {
|
|
210
|
+
//use this mixin constructions:
|
|
211
|
+
//const ComponentsMixinEntitie = (superclass) => class extends superclass { ... }
|
|
212
|
+
currentTestObject = mixin(currentTestObject);
|
|
213
|
+
})
|
|
214
|
+
|
|
197
215
|
return currentTestObject;
|
|
198
216
|
}
|
|
199
217
|
|
|
@@ -214,6 +232,20 @@ class ModulesInstancesController {
|
|
|
214
232
|
|
|
215
233
|
return false;
|
|
216
234
|
}
|
|
235
|
+
|
|
236
|
+
_getMixins(currentTestObject, entitiesArray, entitiesIndex) {
|
|
237
|
+
const mixins = [];
|
|
238
|
+
|
|
239
|
+
for (let mode of this._modes) {
|
|
240
|
+
const capMode = Urso.helper.capitaliseFirstLetter(mode);
|
|
241
|
+
|
|
242
|
+
if (currentTestObject[capMode] && currentTestObject[capMode][entitiesArray[entitiesIndex]]) {
|
|
243
|
+
mixins.push(currentTestObject[capMode][entitiesArray[entitiesIndex]]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return mixins;
|
|
248
|
+
}
|
|
217
249
|
}
|
|
218
250
|
|
|
219
251
|
module.exports = ModulesInstancesController;
|
|
@@ -12,8 +12,13 @@ class ModulesObjectsBaseModel {
|
|
|
12
12
|
this._baseObject = null; //link to pixi object
|
|
13
13
|
this._uid = Urso.helper.recursiveGet('_uid', params, false); //will setup on create
|
|
14
14
|
this._templatePath = false;
|
|
15
|
+
this._parsed = false;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* setup params to object model
|
|
20
|
+
* @param {Object} params
|
|
21
|
+
*/
|
|
17
22
|
setupParams(params) {
|
|
18
23
|
this.type = Urso.helper.recursiveGet('type', params, null);
|
|
19
24
|
|
|
@@ -11,16 +11,17 @@ class ModulesObjectsController {
|
|
|
11
11
|
this._applyClassesToWorld = this._applyClassesToWorld.bind(this);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
create(objects, parent, doNotRefreshStylesFlag) {
|
|
14
|
+
create(objects, parent, doNotRefreshStylesFlag) {
|
|
15
15
|
let result;
|
|
16
16
|
|
|
17
17
|
if (Array.isArray(objects)) {
|
|
18
18
|
result = [];
|
|
19
|
+
|
|
19
20
|
for (const object of objects) {
|
|
20
|
-
result.push(this.
|
|
21
|
+
result.push(this._createSingleObject(object, parent, doNotRefreshStylesFlag));
|
|
21
22
|
}
|
|
22
23
|
} else
|
|
23
|
-
result = this.
|
|
24
|
+
result = this._createSingleObject(objects, parent, doNotRefreshStylesFlag);
|
|
24
25
|
|
|
25
26
|
if (!doNotRefreshStylesFlag)
|
|
26
27
|
this.refreshStyles(parent);
|
|
@@ -28,6 +29,15 @@ class ModulesObjectsController {
|
|
|
28
29
|
return result;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
_createSingleObject(object, parent, doNotRefreshStylesFlag) {
|
|
33
|
+
//parse template for assets and objects (groups, components)
|
|
34
|
+
if (!object._parsed) { //todo only for objects, contains components && groups in future
|
|
35
|
+
return Urso.scenes.addObject(object, parent, doNotRefreshStylesFlag);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this.getInstance('Create').add(object, parent);
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
find(selector) {
|
|
32
42
|
return this.getInstance('Find').do(selector);
|
|
33
43
|
}
|
|
@@ -10,6 +10,8 @@ class ModulesObjectsModelsBitmapText extends Urso.Core.Modules.Objects.BaseModel
|
|
|
10
10
|
super.setupParams(params);
|
|
11
11
|
|
|
12
12
|
this.text = Urso.helper.recursiveGet('text', params, false);
|
|
13
|
+
this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
|
|
14
|
+
|
|
13
15
|
this.fontName = Urso.helper.recursiveGet('fontName', params, false);
|
|
14
16
|
this.fontSize = Urso.helper.recursiveGet('fontSize', params, false);
|
|
15
17
|
|
|
@@ -17,8 +19,20 @@ class ModulesObjectsModelsBitmapText extends Urso.Core.Modules.Objects.BaseModel
|
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
_addBaseObject() {
|
|
22
|
+
if (this.localeId)
|
|
23
|
+
this._originalModel.text = this.text = Urso.i18n.get(this.localeId);
|
|
24
|
+
|
|
20
25
|
this._baseObject = new PIXI.BitmapText(this.text, { fontName: this.fontName, fontSize: this.fontSize });
|
|
21
26
|
};
|
|
27
|
+
|
|
28
|
+
_newLocaleHandler() {
|
|
29
|
+
this.text = this._baseObject.text = Urso.i18n.get(this.localeId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_subscribeOnce() {
|
|
33
|
+
if (this.localeId)
|
|
34
|
+
this.addListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
|
|
35
|
+
}
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
module.exports = ModulesObjectsModelsBitmapText;
|
|
@@ -6,6 +6,10 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
6
6
|
this._addBaseObject();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* setup params to object model
|
|
11
|
+
* @param {Object} params
|
|
12
|
+
*/
|
|
9
13
|
setupParams(params) {
|
|
10
14
|
super.setupParams(params);
|
|
11
15
|
|
|
@@ -21,27 +25,98 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
21
25
|
params.animation = this.animation; //we redefine original property here
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
/**
|
|
29
|
+
* play spine animation
|
|
30
|
+
* @param {String} animationName
|
|
31
|
+
* @param {Boolean} [loopFlag]
|
|
32
|
+
* @param {Number} [track] - you can define track number for current animation
|
|
33
|
+
*/
|
|
24
34
|
play(animationName, loopFlag = false, track = 0) {
|
|
25
35
|
this._baseObject.state.setAnimation(track, animationName, loopFlag);
|
|
26
36
|
}
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
/**
|
|
39
|
+
* play spine animation and execute function after animation completes
|
|
40
|
+
* @param {String} animation - name of the animation to be played
|
|
41
|
+
* @param {Function} func - function to be executed
|
|
42
|
+
*/
|
|
43
|
+
playAndThen(animation, func) {
|
|
44
|
+
this.playInSequenceAndThen([animation], func);
|
|
45
|
+
}
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
/**
|
|
48
|
+
* play spine animations in sequence
|
|
49
|
+
* @param {String[]} animations - names of the animations to be played
|
|
50
|
+
*/
|
|
51
|
+
playInSequence(animations) {
|
|
52
|
+
this.stop();
|
|
53
|
+
const defaultTrack = 0;
|
|
54
|
+
animations.forEach(e => this._baseObject.state.addAnimation(defaultTrack, e));
|
|
55
|
+
}
|
|
35
56
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
57
|
+
/**
|
|
58
|
+
* play spine animations in sequence and execute function after last animation completes
|
|
59
|
+
* @param {String[]} animations - names of the animations to be played
|
|
60
|
+
* @param {Function} func - function to be executed
|
|
61
|
+
*/
|
|
62
|
+
playInSequenceAndThen(animations, func) {
|
|
63
|
+
let animationsLeft = animations.length;
|
|
64
|
+
let removeSelf = () => { };
|
|
65
|
+
let completer = {
|
|
66
|
+
complete: () => {
|
|
67
|
+
if (--animationsLeft === 0) {
|
|
68
|
+
func();
|
|
69
|
+
removeSelf();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
removeSelf = () => this._baseObject.state.removeListener(completer);
|
|
74
|
+
this._baseObject.state.addListener(completer);
|
|
75
|
+
this.playInSequence(animations);
|
|
41
76
|
}
|
|
42
77
|
|
|
43
78
|
/**
|
|
44
|
-
*
|
|
79
|
+
* stop track animation
|
|
80
|
+
* @param {Number} [track] - you can define track number to stop
|
|
81
|
+
*/
|
|
82
|
+
stopTrack(track) {
|
|
83
|
+
this._baseObject.state.clearTrack(track);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* stop all animations
|
|
88
|
+
*/
|
|
89
|
+
stop() {
|
|
90
|
+
this._baseObject.state.clearTracks();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* reset all animations
|
|
95
|
+
*/
|
|
96
|
+
reset() {
|
|
97
|
+
this._baseObject.state.setEmptyAnimations();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* add object to spine slot
|
|
102
|
+
* @param {String} slotName
|
|
103
|
+
* @param {Object} object - created by engine object
|
|
104
|
+
*/
|
|
105
|
+
addToSlot(slotName, object) {
|
|
106
|
+
this._addToSlot(slotName, object, false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* replace spine slot with new object
|
|
111
|
+
* @param {String} slotName
|
|
112
|
+
* @param {Object} object - created by engine object
|
|
113
|
+
*/
|
|
114
|
+
replaceSlotWith(slotName, object) {
|
|
115
|
+
this._addToSlot(slotName, object, true);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* set/update animation config
|
|
45
120
|
* @param {*} config
|
|
46
121
|
* @param {boolean} [noObjectCreate] dont use this flag out of core
|
|
47
122
|
*
|
|
@@ -59,11 +134,18 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
59
134
|
this._baseObject.state.timeScale = config.timeScale;*/ //deprecated - now we use getTimeScale getter
|
|
60
135
|
|
|
61
136
|
if (config.onComplete) {
|
|
137
|
+
if (this._baseObject.state.listeners.length !== 0) {
|
|
138
|
+
Urso.logger.warn('ModulesObjectsModelsSpine setAnimationConfig warning: animation state listeners will be cleared');
|
|
139
|
+
}
|
|
62
140
|
this._baseObject.state.clearListeners();
|
|
63
141
|
this._baseObject.state.addListener({ complete: this.animation.onComplete });
|
|
64
142
|
}
|
|
65
143
|
}
|
|
66
144
|
|
|
145
|
+
/**
|
|
146
|
+
* system function
|
|
147
|
+
* add object to pixi tree
|
|
148
|
+
*/
|
|
67
149
|
_addBaseObject() {
|
|
68
150
|
let spineAsset = Urso.cache.getSpine(this.assetKey);
|
|
69
151
|
|
|
@@ -81,6 +163,30 @@ class ModulesObjectsModelsSpine extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
81
163
|
this.play(this.animation.name, this.animation.loop);
|
|
82
164
|
};
|
|
83
165
|
|
|
166
|
+
_addToSlot(slotName, object, replaceSlotContents) {
|
|
167
|
+
const spine = this._baseObject;
|
|
168
|
+
const slotIndex = spine.spineData.slots.findIndex(({ name }) => name === slotName);
|
|
169
|
+
const currentSlot = spine.slotContainers[slotIndex];
|
|
170
|
+
|
|
171
|
+
if (currentSlot) {
|
|
172
|
+
object._baseObject.scale.y = -1;
|
|
173
|
+
|
|
174
|
+
Urso.objects.removeChild(object.parent, object);
|
|
175
|
+
|
|
176
|
+
if (replaceSlotContents)
|
|
177
|
+
currentSlot.removeChildren(); //todo check if its proxy and reset parent
|
|
178
|
+
|
|
179
|
+
//object.parent = this; //todo && make removeChild
|
|
180
|
+
currentSlot.addChild(object._baseObject);
|
|
181
|
+
} else {
|
|
182
|
+
Urso.logger.warn('ModulesObjectsModelsSpine _addToSlot error: no spine slot ' + slotName);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* get animation timeScale
|
|
188
|
+
* @returns Number
|
|
189
|
+
*/
|
|
84
190
|
getTimeScale() {
|
|
85
191
|
return Urso.scenes.timeScale * this.animation.timeScale;
|
|
86
192
|
}
|
|
@@ -10,6 +10,7 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
10
10
|
super.setupParams(params);
|
|
11
11
|
|
|
12
12
|
this.text = Urso.helper.recursiveGet('text', params, false);
|
|
13
|
+
this.localeId = Urso.helper.recursiveGet('localeId', params, false); //you can use this instead text for localization
|
|
13
14
|
|
|
14
15
|
this.lineHeight = Urso.helper.recursiveGet('lineHeight', params, 0);
|
|
15
16
|
this.fontFamily = Urso.helper.recursiveGet('fontFamily', params, 'Arial');
|
|
@@ -31,8 +32,20 @@ class ModulesObjectsModelsText extends Urso.Core.Modules.Objects.BaseModel {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
_addBaseObject() {
|
|
35
|
+
if (this.localeId)
|
|
36
|
+
this._originalModel.text = this.text = Urso.i18n.get(this.localeId);
|
|
37
|
+
|
|
34
38
|
this._baseObject = new PIXI.Text(this.text);
|
|
35
39
|
};
|
|
40
|
+
|
|
41
|
+
_newLocaleHandler() {
|
|
42
|
+
this.text = this._baseObject.text = Urso.i18n.get(this.localeId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_subscribeOnce() {
|
|
46
|
+
if (this.localeId)
|
|
47
|
+
this.addListener(Urso.events.MODULES_I18N_NEW_LOCALE_WAS_SET, this._newLocaleHandler.bind(this));
|
|
48
|
+
}
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
module.exports = ModulesObjectsModelsText;
|
|
@@ -6,6 +6,7 @@ class ModulesObserverConfig {
|
|
|
6
6
|
MODULES_ASSETS_GROUP_LOADED: 'modules.assets.group.loaded',
|
|
7
7
|
MODULES_ASSETS_LOAD_PROGRESS: 'modules.assets.load.progress',
|
|
8
8
|
MODULES_ASSETS_LAZYLOAD_FINISHED: 'modules.assets.lazyLoad.finished',
|
|
9
|
+
MODULES_I18N_NEW_LOCALE_WAS_SET: 'modules.i18n.new.locale.was.set',
|
|
9
10
|
MODULES_INSTANCES_MODES_CHANGED: 'modules.instances.modes.changed',
|
|
10
11
|
MODULES_OBJECTS_BUTTON_PRESS: 'modules.objects.button.press',
|
|
11
12
|
MODULES_OBJECTS_HIT_AREA_PRESS: 'modules.objects.hitArea.press',
|
|
@@ -30,6 +30,10 @@ class ModulesScenesController {
|
|
|
30
30
|
return this.getInstance('PixiWrapper').getCachedMouseCoords();
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
addObject(objects, parent, doNotRefreshStylesFlag) {
|
|
34
|
+
this._service.addObject(objects, parent, doNotRefreshStylesFlag);
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
get timeScale() {
|
|
34
38
|
return this._service.timeScale;
|
|
35
39
|
}
|
|
@@ -26,6 +26,19 @@ class ModulesScenesService {
|
|
|
26
26
|
gsap.globalTimeline.timeScale(this.timeScale);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
addObject(objects, parent, doNotRefreshStylesFlag) {
|
|
30
|
+
const newTemplatePart = Urso.template.parse({ objects: [objects] }, true);
|
|
31
|
+
Urso.assets.preload(newTemplatePart.assets, () => this._newTemplateAssetsLoadedHandler(newTemplatePart, parent, doNotRefreshStylesFlag));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_newTemplateAssetsLoadedHandler(newTemplatePart, parent, doNotRefreshStylesFlag) {
|
|
35
|
+
Urso.objects.create(newTemplatePart.objects, parent, doNotRefreshStylesFlag);
|
|
36
|
+
|
|
37
|
+
//components create
|
|
38
|
+
newTemplatePart.components.forEach(component => component.create());
|
|
39
|
+
this._currentSceneTemplate.components = Urso.helper.mergeArrays(this._currentSceneTemplate.components, newTemplatePart.components);
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
display(name) {
|
|
30
43
|
if (this._displayInProgress) {
|
|
31
44
|
console.warn("Scenes.display is busy ", this._currentSceneName);
|
|
@@ -68,12 +81,12 @@ class ModulesScenesService {
|
|
|
68
81
|
this.emit(Urso.events.MODULES_SCENES_NEW_SCENE_INIT, name);
|
|
69
82
|
|
|
70
83
|
Urso.assets.preload(this._currentSceneTemplate.assets, this._assetsLoadedHandler);
|
|
71
|
-
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
loadUpdate(loadProgress) {
|
|
75
87
|
if (!this._sceneModel)
|
|
76
88
|
return;
|
|
89
|
+
|
|
77
90
|
this._sceneModel.loadUpdate(loadProgress);
|
|
78
91
|
this.emit(Urso.events.MODULES_ASSETS_LOAD_PROGRESS, loadProgress);
|
|
79
92
|
}
|
|
@@ -19,8 +19,8 @@ class ModulesTemplateController {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
//make template
|
|
22
|
-
parse(template) {
|
|
23
|
-
return this.getInstance('Service').parse(template);
|
|
22
|
+
parse(template, additionalTemplateFlag) {
|
|
23
|
+
return this.getInstance('Service').parse(template, additionalTemplateFlag);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
}
|
|
@@ -3,10 +3,11 @@ class ModulesTemplateService {
|
|
|
3
3
|
this.singleton = true;
|
|
4
4
|
|
|
5
5
|
this._currentTemplate = this.getInstance('Model');
|
|
6
|
+
this._actualTemplate;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
getTemplate() {
|
|
9
|
-
return this.
|
|
10
|
+
return this._actualTemplate;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
getSceneOrGroup(name, namespace) {
|
|
@@ -17,12 +18,21 @@ class ModulesTemplateService {
|
|
|
17
18
|
return entity;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
parse(template) {
|
|
21
|
+
parse(template, additionalTemplateFlag) {
|
|
21
22
|
this._currentTemplate = Urso.helper.mergeObjectsRecursive(this.getInstance('Model'), template);
|
|
22
23
|
|
|
23
24
|
this._parseAssets(this._currentTemplate.assets, template._templatePath);
|
|
24
25
|
this._parseObjects(this._currentTemplate.objects, template._templatePath);
|
|
25
26
|
|
|
27
|
+
if (additionalTemplateFlag) {
|
|
28
|
+
this._actualTemplate.assets = Urso.helper.mergeArrays(this._actualTemplate.assets, this._currentTemplate.assets);
|
|
29
|
+
this._actualTemplate.components = Urso.helper.mergeArrays(this._actualTemplate.components, this._currentTemplate.components);
|
|
30
|
+
this._actualTemplate.objects = Urso.helper.mergeArrays(this._actualTemplate.objects, this._currentTemplate.objects);
|
|
31
|
+
Urso.helper.mergeObjectsRecursive(this._actualTemplate.styles, this._currentTemplate.styles);
|
|
32
|
+
} else {
|
|
33
|
+
this._actualTemplate = this._currentTemplate;
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
return this._currentTemplate;
|
|
27
37
|
}
|
|
28
38
|
|
|
@@ -49,6 +59,8 @@ class ModulesTemplateService {
|
|
|
49
59
|
|
|
50
60
|
if (obj.type === Urso.types.objects.COMPONENT)
|
|
51
61
|
this._processComponent(obj);
|
|
62
|
+
|
|
63
|
+
obj._parsed = true;
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
|