@urso/core 0.6.1 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urso/core",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -1,5 +1,7 @@
1
1
  class ModulesAssetsBaseModel {
2
2
  constructor(params) {
3
+ this.simpleClass = true;
4
+
3
5
  this.setupParams(params);
4
6
  this._templatePath = false;
5
7
  }
@@ -16,6 +16,13 @@ class ModulesInstancesController {
16
16
  this.removeMode = this.removeMode.bind(this);
17
17
  }
18
18
 
19
+ /**
20
+ * get class by Path
21
+ * @param {String} path
22
+ * @param {Boolean} [noModes]
23
+ * @param {String} [modeName]
24
+ * @returns {Class}
25
+ */
19
26
  getByPath(path, noModes, modeName) {
20
27
  let callback = (a) => {
21
28
  return a;
@@ -24,10 +31,19 @@ class ModulesInstancesController {
24
31
  return this._findClass({ path, callback, noModes, modeName });
25
32
  }
26
33
 
34
+ /**
35
+ * get current modes
36
+ * @returns {Array}
37
+ */
27
38
  getModes() {
28
39
  return this._modes;
29
40
  }
30
41
 
42
+ /**
43
+ * add mode to system
44
+ * @param {String} mode
45
+ * @returns {Boolean}
46
+ */
31
47
  addMode(mode) {
32
48
  if (this._modes.indexOf(mode) !== -1)
33
49
  return false;
@@ -40,8 +56,8 @@ class ModulesInstancesController {
40
56
  /**
41
57
  * remove mode from system
42
58
  * @param {String} mode
43
- * @param {Boolean} passiveMode - do not refresh styles
44
- * @returns
59
+ * @param {Boolean} [passiveMode] - do not refresh styles
60
+ * @returns {Boolean}
45
61
  */
46
62
  removeMode(mode, passiveMode) {
47
63
  let index = this._modes.indexOf(mode);
@@ -58,6 +74,14 @@ class ModulesInstancesController {
58
74
  return true;
59
75
  }
60
76
 
77
+ /**
78
+ * get class instance by path
79
+ * @param {String} path
80
+ * @param {mixed} [params]
81
+ * @param {Boolean} [noModes]
82
+ * @param {String} [modeName]
83
+ * @returns {Class | false}
84
+ */
61
85
  getInstance(path, params, noModes, modeName) {
62
86
  let callback = (classObject) => {
63
87
  if (typeof classObject !== "function") { //typeof class is a function
@@ -84,11 +108,20 @@ class ModulesInstancesController {
84
108
  return this._findClass({ path, callback, noModes, modeName });
85
109
  }
86
110
 
111
+ /**
112
+ * get uid for instance
113
+ * @returns {String}
114
+ */
87
115
  _getUid() {
88
116
  this._counter++;
89
117
  return 'instance' + this._counter;
90
118
  }
91
119
 
120
+ /**
121
+ * set common functions to instance
122
+ * @param {Class} classObject
123
+ * @param {String} path
124
+ */
92
125
  _setComonFunctions(classObject, path) {
93
126
  classObject.prototype.getInstance = this._entityGetInstance(path);
94
127
  classObject.prototype.addListener = this._entityAddListener;
@@ -96,6 +129,11 @@ class ModulesInstancesController {
96
129
  classObject.prototype.emit = this._entityEmit;
97
130
  }
98
131
 
132
+ /**
133
+ * set common entities functions to instance
134
+ * @param {Class} classObject
135
+ * @param {ClassInstance} callerObject
136
+ */
99
137
  _setComonEntityFunctions(classObject, callerObject) {
100
138
  if (callerObject.common && !classObject.common) { //components common
101
139
  classObject.common = callerObject.common;
@@ -106,6 +144,10 @@ class ModulesInstancesController {
106
144
  }
107
145
  }
108
146
 
147
+ /**
148
+ * launch default functions after creation
149
+ * @param {ClassInstance} instance
150
+ */
109
151
  _launchDefaultFunctions(instance) {
110
152
  //_subscribe
111
153
  if (instance && instance._subscribe)
@@ -118,6 +160,11 @@ class ModulesInstancesController {
118
160
  }
119
161
  }
120
162
 
163
+ /**
164
+ * entity get instance (with parent deps)
165
+ * @param {String} path
166
+ * @returns {Function}
167
+ */
121
168
  _entityGetInstance(path) {
122
169
  const entityPath = Urso.helper.initial(path.split('.')).join('.');
123
170
  const self = this;
@@ -128,15 +175,21 @@ class ModulesInstancesController {
128
175
  params, noModes, modeName
129
176
  );
130
177
 
131
- self._addEntityToClass(instance, this);
132
-
133
- if (instance)
178
+ //no simpleClasses like ModulesAssetsBaseModel && ModulesObjectsBaseModel
179
+ if (instance && !instance.simpleClass) {
180
+ self._addEntityToClass(instance, this);
134
181
  self._setComonEntityFunctions(instance, this);
182
+ }
135
183
 
136
184
  return instance;
137
185
  };
138
186
  }
139
187
 
188
+ /**
189
+ * add entity to caller class
190
+ * @param {ClassInstance} classObject
191
+ * @param {ClassInstance} callerObject
192
+ */
140
193
  _addEntityToClass(classObject, callerObject) {
141
194
  if (!callerObject.__entities)
142
195
  callerObject.__entities = [];
@@ -145,18 +198,32 @@ class ModulesInstancesController {
145
198
  callerObject.__entities.push(classObject);
146
199
  }
147
200
 
201
+ /**
202
+ * entity addListener function
203
+ */
148
204
  _entityAddListener() {
149
205
  Urso.observer.add.apply(Urso.observer, arguments);
150
206
  }
151
207
 
208
+ /**
209
+ * entity removeListener function
210
+ */
152
211
  _entityRemoveListener() {
153
212
  Urso.observer.remove.apply(Urso.observer, arguments);
154
213
  }
155
214
 
215
+ /**
216
+ * entity emit function
217
+ */
156
218
  _entityEmit() {
157
219
  Urso.observer.fire.apply(Urso.observer, arguments);
158
220
  }
159
221
 
222
+ /**
223
+ * find class by params
224
+ * @param {Object} params
225
+ * @returns {Class | false}
226
+ */
160
227
  _findClass(params) {
161
228
  //put all params exept callback in key
162
229
  let cacheKey = [
@@ -189,6 +256,12 @@ class ModulesInstancesController {
189
256
  return params.callback(this._cache[cacheKey]);
190
257
  }
191
258
 
259
+ /**
260
+ * get class by path
261
+ * @param {String} path
262
+ * @param {Boolean} [noModes]
263
+ * @returns {Class | false}
264
+ */
192
265
  _getClassByPath(path, noModes) {
193
266
  let pathArr = path.split('.');
194
267
  let entitiesArray = Urso.helper.mergeArrays(['Urso', 'Game'], pathArr);
@@ -198,7 +271,7 @@ class ModulesInstancesController {
198
271
  /**
199
272
  * check if object exist
200
273
  * @param {Object} entitiesArray like ['Urso', 'Game', 'Lib', 'Helper']
201
- * @returns {mixed}
274
+ * @returns {Class | false}
202
275
  */
203
276
  _checkPathExist(entitiesArray, noModes) {
204
277
  let currentTestObject = window;
@@ -234,6 +307,13 @@ class ModulesInstancesController {
234
307
  return currentTestObject;
235
308
  }
236
309
 
310
+ /**
311
+ * check path for modes
312
+ * @param {Object} currentTestObject
313
+ * @param {Array} entitiesArray
314
+ * @param {Number} entitiesIndex
315
+ * @returns {Class | false}
316
+ */
237
317
  _checkPathWithModes(currentTestObject, entitiesArray, entitiesIndex) {
238
318
  for (let mode of this._modes) {
239
319
  const capMode = Urso.helper.capitaliseFirstLetter(mode);
@@ -252,6 +332,13 @@ class ModulesInstancesController {
252
332
  return false;
253
333
  }
254
334
 
335
+ /**
336
+ * check path for mixins
337
+ * @param {Object} currentTestObject
338
+ * @param {Array} entitiesArray
339
+ * @param {Number} entitiesIndex
340
+ * @returns {Array}
341
+ */
255
342
  _getMixins(currentTestObject, entitiesArray, entitiesIndex) {
256
343
  const mixins = [];
257
344
 
@@ -1,5 +1,7 @@
1
1
  class ModulesObjectsBaseModel {
2
2
  constructor(params) {
3
+ this.simpleClass = true;
4
+
3
5
  this.setupParams(params);
4
6
 
5
7
  this.parent = false;