@urso/core 0.7.80 → 0.7.82-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/config/load.js +3 -0
- package/src/js/lib/cache.js +18 -5
- package/src/js/lib/loader.js +45 -1
- package/src/js/modules/assets/models/jsonAtlas.js +11 -0
- package/src/js/modules/assets/service.js +3 -0
- package/src/js/modules/objects/config.js +10 -0
- package/src/js/modules/objects/pool.js +68 -0
- package/src/js/modules/objects/service.js +13 -3
- package/src/js/modules/template/types.js +3 -2
package/package.json
CHANGED
package/src/js/config/load.js
CHANGED
|
@@ -78,6 +78,7 @@ window.Urso = {
|
|
|
78
78
|
Html: require('../modules/assets/models/html'),
|
|
79
79
|
Image: require('../modules/assets/models/image'),
|
|
80
80
|
Json: require('../modules/assets/models/json'),
|
|
81
|
+
JsonAtlas: require('../modules/assets/models/jsonAtlas'),
|
|
81
82
|
Sound: require('../modules/assets/models/sound'),
|
|
82
83
|
Spine: require('../modules/assets/models/spine')
|
|
83
84
|
}
|
|
@@ -100,8 +101,10 @@ window.Urso = {
|
|
|
100
101
|
Objects: {
|
|
101
102
|
BaseModel: require('../modules/objects/baseModel'),
|
|
102
103
|
Cache: require('../modules/objects/cache'),
|
|
104
|
+
Config: require('../modules/objects/config'),
|
|
103
105
|
Controller: require('../modules/objects/controller'),
|
|
104
106
|
Find: require('../modules/objects/find'),
|
|
107
|
+
Pool: require('../modules/objects/pool'),
|
|
105
108
|
PropertyAdapter: require('../modules/objects/propertyAdapter'),
|
|
106
109
|
Proxy: require('../modules/objects/proxy'),
|
|
107
110
|
Selector: require('../modules/objects/selector'),
|
package/src/js/lib/cache.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
class LibCache {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.assetsList = {
|
|
4
|
-
image: {},
|
|
5
4
|
atlas: {},
|
|
6
|
-
json: {},
|
|
7
5
|
binary: {},
|
|
8
|
-
spine: {},
|
|
9
6
|
bitmapFont: {},
|
|
7
|
+
file: {},
|
|
8
|
+
image: {},
|
|
9
|
+
json: {},
|
|
10
|
+
jsonAtlas: {},
|
|
10
11
|
sound: {},
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
spine: {},
|
|
13
|
+
texture: {}
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
this.globalAtlas = new PIXI.spine.TextureAtlas();
|
|
@@ -50,6 +51,10 @@ class LibCache {
|
|
|
50
51
|
this._setDataToAssetsList('json', key, someData);
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
addJsonAtlas(key, someData) {
|
|
55
|
+
this._setDataToAssetsList('jsonAtlas', key, someData);
|
|
56
|
+
};
|
|
57
|
+
|
|
53
58
|
addSound(key, someData) {
|
|
54
59
|
this._setDataToAssetsList('sound', key, someData);
|
|
55
60
|
};
|
|
@@ -91,6 +96,14 @@ class LibCache {
|
|
|
91
96
|
return this.assetsList.json[key];
|
|
92
97
|
};
|
|
93
98
|
|
|
99
|
+
getJsonAtlas(key) {
|
|
100
|
+
return this.assetsList.jsonAtlas[key];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
getJsonAtlases() {
|
|
104
|
+
return this.assetsList.jsonAtlas;
|
|
105
|
+
};
|
|
106
|
+
|
|
94
107
|
getSound(key) {
|
|
95
108
|
return this.assetsList.sound[key];
|
|
96
109
|
};
|
package/src/js/lib/loader.js
CHANGED
|
@@ -120,11 +120,27 @@ class LibLoader {
|
|
|
120
120
|
|
|
121
121
|
let params = asset.params || false; // TODO: Set params field in base mode
|
|
122
122
|
|
|
123
|
-
if (asset.type === Urso.types.assets.
|
|
123
|
+
if (asset.type === Urso.types.assets.JSON) { // check json in JSONATLAS
|
|
124
|
+
const jsonData = this._getJsonDataFromJsonAtlases(asset.key);
|
|
125
|
+
|
|
126
|
+
if (jsonData) {
|
|
127
|
+
Urso.cache.addJson(asset.key, { data: jsonData });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (asset.type === Urso.types.assets.SPINE && asset.noAtlas) { // check SPINE in JSONATLAS
|
|
124
133
|
if (!params)
|
|
125
134
|
params = {};
|
|
126
135
|
|
|
127
136
|
params.metadata = { spineAtlas: Urso.cache.getGlobalAtlas() };
|
|
137
|
+
//check for json in JSONATLAS
|
|
138
|
+
const jsonData = this._getJsonDataFromJsonAtlases(asset.key);
|
|
139
|
+
|
|
140
|
+
if (jsonData) {
|
|
141
|
+
this._loadSpineFromExistingResourses(asset, jsonData, params);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
128
144
|
}
|
|
129
145
|
|
|
130
146
|
const loadPath = this._getLoadPath(asset);
|
|
@@ -146,6 +162,34 @@ class LibLoader {
|
|
|
146
162
|
}.bind(this));
|
|
147
163
|
};
|
|
148
164
|
|
|
165
|
+
_getJsonDataFromJsonAtlases(key) {
|
|
166
|
+
const jsonAtlases = Urso.cache.getJsonAtlases();
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < jsonAtlases.length; i++) {
|
|
169
|
+
if (jsonAtlases[i].data.hasOwnProperty(key)) {
|
|
170
|
+
return jsonAtlases[i].data[key];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
_loadSpineFromExistingResourses(asset, jsonData, params) {
|
|
178
|
+
const rawSkeletonData = jsonData; //skeleton
|
|
179
|
+
const rawAtlasData = params.metadata.spineAtlas; //atlas file
|
|
180
|
+
|
|
181
|
+
const spineAtlas = new PIXI.spine.core.TextureAtlas(rawAtlasData, function (line, callback) {
|
|
182
|
+
// pass the image here.
|
|
183
|
+
callback(PIXI.BaseTexture.fromImage(line));
|
|
184
|
+
}); // specify path, image.png will be added automatically
|
|
185
|
+
|
|
186
|
+
const spineAtlasLoader = new PIXI.spine.core.AtlasAttachmentLoader(spineAtlas)
|
|
187
|
+
const spineJsonParser = new PIXI.spine.core.SkeletonJson(spineAtlasLoader);
|
|
188
|
+
|
|
189
|
+
const spineData = spineJsonParser.readSkeletonData(rawSkeletonData);
|
|
190
|
+
Urso.cache.addSpine(asset.key, spineData);
|
|
191
|
+
}
|
|
192
|
+
|
|
149
193
|
_onError(error) {
|
|
150
194
|
Urso.logger.warn('LibLoader file load error: ', error);
|
|
151
195
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const ModulesAssetsBaseModel = require('./../baseModel');
|
|
2
|
+
|
|
3
|
+
class ModulesAssetsModelsJsonAtlas extends ModulesAssetsBaseModel {
|
|
4
|
+
constructor(params) {
|
|
5
|
+
super(params);
|
|
6
|
+
|
|
7
|
+
this.type = Urso.types.assets.JSON;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = ModulesAssetsModelsJsonAtlas;
|
|
@@ -366,6 +366,9 @@ class ModulesAssetsService {
|
|
|
366
366
|
case Urso.types.assets.JSON:
|
|
367
367
|
model = this.getInstance('Models.Json', asset)
|
|
368
368
|
break;
|
|
369
|
+
case Urso.types.assets.JSONATLAS:
|
|
370
|
+
model = this.getInstance('Models.JsonAtlas', asset)
|
|
371
|
+
break;
|
|
369
372
|
case Urso.types.assets.SOUND:
|
|
370
373
|
model = this.getInstance('Models.Sound', asset)
|
|
371
374
|
break;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
class ModulesObjectsPool {
|
|
2
|
+
|
|
3
|
+
_objectsCache = {};
|
|
4
|
+
_objectsCounter = 0;
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this.singleton = true;
|
|
8
|
+
|
|
9
|
+
this._objectsPool = new Urso.Game.Lib.ObjectPool(
|
|
10
|
+
this._constructorFunction.bind(this),
|
|
11
|
+
this._resetFunction.bind(this)
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
getElement(object, parent) {
|
|
16
|
+
const poolElement = this._objectsPool.getElement(object.assetKey, { object, parent });
|
|
17
|
+
this._objectsCounter++;
|
|
18
|
+
this._objectsCache[this._objectsCounter] = poolElement;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const newObject = poolElement.data;
|
|
22
|
+
newObject._poolCacheId = this._objectsCounter;
|
|
23
|
+
|
|
24
|
+
if (typeof object.x === 'number') newObject.x = object.x; else newObject.x = 0;
|
|
25
|
+
if (typeof object.y === 'number') newObject.y = object.y; else newObject.y = 0;
|
|
26
|
+
if (typeof object.angle === 'number') newObject.angle = object.angle; else newObject.angle = 0;
|
|
27
|
+
if (typeof object.anchorX === 'number') newObject.anchorX = object.anchorX; else newObject.anchorX = 0;
|
|
28
|
+
if (typeof object.anchorY === 'number') newObject.anchorY = object.anchorY; else newObject.anchorY = 0;
|
|
29
|
+
if (typeof object.visible === 'boolean') newObject.visible = object.visible; else newObject.visible = true;
|
|
30
|
+
|
|
31
|
+
if (object?.type === Urso.types.objects.SPINE)
|
|
32
|
+
newObject.setAnimationConfig(object.animation); //setup oncomplete
|
|
33
|
+
|
|
34
|
+
this.getInstance('Service').addChild(parent, newObject, true);
|
|
35
|
+
return newObject;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
putElement(object, doNotRefreshStylesFlag) {
|
|
39
|
+
if (object._poolCacheId) {
|
|
40
|
+
this._objectsPool.putElement(this._objectsCache[object._poolCacheId]);
|
|
41
|
+
delete this._objectsCache[object._poolCacheId];
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.error('ModulesObjectsPool something goes wrong: object must be in pool');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_constructorFunction(_, { object, parent }) {
|
|
49
|
+
return this.getInstance('Service').add(object, parent, true);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_resetFunction(object) {
|
|
53
|
+
if (object.parent)
|
|
54
|
+
this.getInstance('Service').removeChild(object.parent, object, true);
|
|
55
|
+
|
|
56
|
+
if (object?.type === Urso.types.objects.SPINE) {
|
|
57
|
+
object.setToSetupPose();
|
|
58
|
+
object.stop();
|
|
59
|
+
object.clearListeners();
|
|
60
|
+
object._baseObject.lastTime = null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return object;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = ModulesObjectsPool;
|
|
@@ -62,7 +62,12 @@ class ModulesObjectsService {
|
|
|
62
62
|
return this._world;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
add(object, parent) {
|
|
65
|
+
add(object, parent, _ignorePool = false) {
|
|
66
|
+
const { objectsToCache } = this.getInstance('Config');
|
|
67
|
+
|
|
68
|
+
if (!_ignorePool && objectsToCache.includes(object.type))
|
|
69
|
+
return this.getInstance('Pool').getElement(object, parent);
|
|
70
|
+
|
|
66
71
|
const world = this._checkWorld();
|
|
67
72
|
|
|
68
73
|
if (!parent)
|
|
@@ -94,7 +99,7 @@ class ModulesObjectsService {
|
|
|
94
99
|
break;
|
|
95
100
|
case Urso.types.objects.EMITTERFX:
|
|
96
101
|
model = this.getInstance('Models.EmitterFx', object);
|
|
97
|
-
break;
|
|
102
|
+
break;
|
|
98
103
|
case Urso.types.objects.HITAREA:
|
|
99
104
|
model = this.getInstance('Models.HitArea', object);
|
|
100
105
|
break;
|
|
@@ -181,6 +186,11 @@ class ModulesObjectsService {
|
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
destroy(object, doNotRefreshStylesFlag) {
|
|
189
|
+
const { objectsToCache } = this.getInstance('Config');
|
|
190
|
+
|
|
191
|
+
if (objectsToCache.includes(object.type))
|
|
192
|
+
return this.getInstance('Pool').putElement(object, doNotRefreshStylesFlag);
|
|
193
|
+
|
|
184
194
|
if (object.parent)
|
|
185
195
|
this.removeChild(object.parent, object, true);
|
|
186
196
|
|
|
@@ -191,7 +201,7 @@ class ModulesObjectsService {
|
|
|
191
201
|
this.destroy(object.contents[0], true);
|
|
192
202
|
|
|
193
203
|
object._customDestroy();
|
|
194
|
-
object._baseObject && object._baseObject.destroy({children: true});
|
|
204
|
+
object._baseObject && object._baseObject.destroy({ children: true });
|
|
195
205
|
this._removeFromCache(object);
|
|
196
206
|
this.getInstance('Styles').removeFromCache(object);
|
|
197
207
|
|