@urso/core 0.3.12 → 0.4.0

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.3.12",
3
+ "version": "0.4.0",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -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
- get base() { return _bases; }
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
- LibComposition.copy(this, obj);
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
- LibComposition.copy(classes, base);
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
- for (let key of Reflect.ownKeys(_source))
39
- {
40
- if (key !== "constructor" && key !== "prototype" && key !== "name")
41
- {
42
- let desc = Object.getOwnPropertyDescriptor(_source, key);
43
- Object.defineProperty(_target, key, desc);
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
 
@@ -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
- if (!noModes && this._modes && entitiesIndex === entitiesArray.length - 1)
187
- testMode = this._checkPathWithModes(currentTestObject, entitiesArray, entitiesIndex);
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,6 +12,7 @@ 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
 
17
18
  setupParams(params) {
@@ -11,16 +11,17 @@ class ModulesObjectsController {
11
11
  this._applyClassesToWorld = this._applyClassesToWorld.bind(this);
12
12
  };
13
13
 
14
- create(objects, parent, doNotRefreshStylesFlag) { //TODO parse template for assets and objects (groups, components)
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.getInstance('Create').add(object, parent));
21
+ result.push(this._createSingleObject(object, parent, doNotRefreshStylesFlag));
21
22
  }
22
23
  } else
23
- result = this.getInstance('Create').add(objects, parent);
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
  }
@@ -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._currentTemplate;
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