@urso/core 0.7.81 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.7.81",
3
+ "version": "0.7.82-dev",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -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
  }
@@ -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
- texture: {},
12
- file: {}
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
  };
@@ -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.SPINE && asset.noAtlas) {
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;
@@ -9,8 +9,9 @@ class ModulesTemplateTypes {
9
9
  FONT: 5,
10
10
  IMAGE: 6,
11
11
  JSON: 7,
12
- SOUND: 8,
13
- SPINE: 9,
12
+ JSONATLAS: 8,
13
+ SOUND: 9,
14
+ SPINE: 10,
14
15
  HTML: 100
15
16
  },
16
17