@urso/core 0.4.50 → 0.4.53

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.4.50",
3
+ "version": "0.4.53",
4
4
  "description": "HTML5 game engine",
5
5
  "main": "build/js/index.js",
6
6
  "author": "Megbrimef",
@@ -23,6 +23,7 @@
23
23
  "homepage": "https://github.com/megbrimef/urso#readme",
24
24
  "dependencies": {
25
25
  "@pixi/filter-drop-shadow": "^3.2.0",
26
+ "@urso/revolt-fx": "^0.1.0",
26
27
  "gsap": "^3.1.1",
27
28
  "howler": "^2.2.1",
28
29
  "pixi-particles": "^4.3.0",
@@ -2,6 +2,7 @@ let ConfigMain = {
2
2
  title: 'Urso', //game title
3
3
  appVersion: 0, //app version, also used as anticache "appVersion=${appVersion}" when not 0
4
4
  mode: "development", // development/production/testing
5
+ defaultLogLevel: 'ERROR,WARNING,INFO,LOG', //setup custom log level with: ?logLevel=1,2,3,4 OR ?logLevel=ERROR,WARNING,INFO,LOG
5
6
  extendingChain: ['Urso.Core'], //chain that will be set as Urso.Game
6
7
  defaultScene: 'play', //default scene to display
7
8
  useBinPath: false, // use assets from bin directory
@@ -2,6 +2,8 @@ import * as PIXI from 'pixi.js';
2
2
  window.PIXI = PIXI;
3
3
  window.PIXI.particles = require('pixi-particles');
4
4
 
5
+ window.PIXI.particlesFx = require('@urso/revolt-fx');
6
+
5
7
  import { DropShadowFilter } from '@pixi/filter-drop-shadow';
6
8
  PIXI.filters['DropShadowFilter'] = DropShadowFilter;
7
9
 
@@ -1,23 +1,69 @@
1
- class LibLogger {
1
+ //setup custom log level with: ?logLevel=1,2,3,4 OR ?logLevel=ERROR,WARNING,INFO,LOG
2
+
3
+ const LEVELS = [
4
+ 'ERROR',
5
+ 'WARNING',
6
+ 'INFO',
7
+ 'LOG'
8
+ ];
2
9
 
10
+ class LibLogger {
3
11
  constructor() {
12
+ this._logLevel = {};
13
+ this._setupLevels();
14
+
4
15
  //log
5
- window.log = console.log.bind(console); //todo this.log ?!
16
+ if (this._logLevel['LOG']) {
17
+ window.log = console.log.bind(console);
18
+ } else {
19
+ window.log = console.log = () => { }
20
+ }
6
21
  }
7
22
 
8
23
  //todo set log level (dev/prod)
9
24
 
10
25
  log() {
26
+ if (!this._logLevel['LOG']) return;
27
+
11
28
  console.log.apply(console, arguments);
12
29
  }
13
30
 
31
+ info() {
32
+ if (!this._logLevel['INFO']) return;
33
+
34
+ console.info.apply(this, arguments);
35
+ }
36
+
14
37
  warn() {
38
+ if (!this._logLevel['WARNING']) return;
39
+
15
40
  console.warn.apply(this, arguments);
16
41
  }
17
42
 
18
43
  error() {
44
+ if (!this._logLevel['ERROR']) return;
45
+
19
46
  console.error.apply(this, arguments);
20
47
  }
48
+
49
+ /**
50
+ * setup logging levels
51
+ */
52
+ _setupLevels() {
53
+ const logLevelsString = Urso.helper.parseGetParams('logLevel') || Urso.config.defaultLogLevel;
54
+ const logLevelsArray = logLevelsString.split(',');
55
+
56
+ for (const [index, level] of Object.entries(LEVELS)) {
57
+ let levelValue = false;
58
+
59
+ if (logLevelsArray.includes(index) || logLevelsArray.includes(level))
60
+ levelValue = true;
61
+
62
+ this._logLevel[level] = levelValue;
63
+ }
64
+
65
+ console.log(`LibLogger log Level: ${JSON.stringify(this._logLevel)}`);
66
+ }
21
67
  }
22
68
 
23
- module.exports = LibLogger;
69
+ module.exports = LibLogger;
@@ -101,6 +101,9 @@ class ModulesObjectsCreate {
101
101
  case Urso.types.objects.NINESLICEPLANE:
102
102
  model = this.getInstance('Models.NineSlicePlane', object);
103
103
  break;
104
+ case Urso.types.objects.EMITTERFX:
105
+ model = this.getInstance('Models.EmitterFx', object);
106
+ break;
104
107
 
105
108
  default:
106
109
  const objectName = Urso.helper.capitaliseFirstLetter(
@@ -8,6 +8,7 @@ Urso.Core.Modules.Objects.Models = {
8
8
  Component: require('./component.js'),
9
9
  Container: require('./container.js'),
10
10
  Emitter: require('./emitter.js'),
11
+ EmitterFx: require('./emitterFx.js'),
11
12
  Graphics: require('./graphics.js'),
12
13
  Group: require('./group.js'),
13
14
  HitArea: require('./hitArea.js'),
@@ -0,0 +1,99 @@
1
+ class ModulesObjectsModelsEmitterFx extends Urso.Core.Modules.Objects.BaseModel {
2
+ constructor(params) {
3
+ super(params);
4
+
5
+ this.type = Urso.types.objects.EMITTERFX;
6
+
7
+ this.emitter = null;
8
+ this.update = this.update.bind(this);
9
+
10
+ this._addBaseObject();
11
+ this._createBundle();
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param {Object} params
17
+ *
18
+ * - Params have to contain 'cfg' which is a key of JSON config made via
19
+ * https://editor.revoltfx.electronauts.net editor.
20
+ * - In a case config doesn't have textures described in it, you can use spritesheetFilter which should be a
21
+ * string, described common part of texures asset keys. That string will be used as filter to get textures from cache.
22
+ * If textures should be animated, texture's asset key have to be of the next format:
23
+ * mc_commonPart_01 - where 'mc' stands for 'movieclips' allows us use animation, commonPart - described all textures in a spriteSheet,
24
+ * and _01 - number of frame.
25
+ */
26
+ setupParams(params) {
27
+ super.setupParams(params);
28
+
29
+ this.autostart = Urso.helper.recursiveGet('autostart', params, false);
30
+ this.cfg = Urso.helper.recursiveGet('cfg', params, false);
31
+ this.spritesheetFilter = Urso.helper.recursiveGet('spritesheetFilter', params, false);
32
+ }
33
+
34
+ update(deltaTime) {
35
+ if (this._emitter) {
36
+ this._bundle.update(deltaTime * PIXI.settings.TARGET_FPMS);
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @param {String} emitterName
42
+ * Inits emitter by it's name. If no name given - inits first emitter from config.
43
+ */
44
+ play(emitterName) {
45
+ this._isActive = true;
46
+
47
+ emitterName = emitterName || this._defaultEmitterName;
48
+
49
+ this._emitter = this._bundle.getParticleEmitter(emitterName);
50
+ this._emitter.init(this._baseObject, true, 1);
51
+ }
52
+
53
+ /**
54
+ *
55
+ * Stops emitter. If new emitter wasn't inited before particles disappears - clears this._emitter to stop bundle update.
56
+ */
57
+ stop() {
58
+ if(!this._emitter)
59
+ return;
60
+
61
+ this._emitter.stop();
62
+ this._emitter.on.completed.add(() => {
63
+ if(!this._isActive)
64
+ this._emitter = null;
65
+ });
66
+
67
+ this._isActive = false;
68
+ }
69
+
70
+ _addBaseObject() {
71
+ this._baseObject = new PIXI.Container();
72
+ };
73
+
74
+ _createBundle() {
75
+ this._bundle = new PIXI.particlesFx.FX();
76
+ let fx_settings_data = Urso.cache.getJson(this.cfg).data;
77
+
78
+ if(this.spritesheetFilter)
79
+ fx_settings_data.spritesheetFilter = this.spritesheetFilter;
80
+
81
+ this._defaultEmitterName = fx_settings_data.emitters[0].name;
82
+
83
+ this._bundle.initBundle(fx_settings_data);
84
+ this.autostart && this.play();
85
+ }
86
+
87
+ _subscribeOnce() {
88
+ this.addListener(Urso.events.MODULES_SCENES_UPDATE, this.update);
89
+ }
90
+
91
+ _customDestroy() {
92
+ this.removeListener(Urso.events.MODULES_SCENES_UPDATE, this.update);
93
+ this._emitter.stop(false);
94
+ this._bundle = null;
95
+ this._emitter = null;
96
+ }
97
+ }
98
+
99
+ module.exports = ModulesObjectsModelsEmitterFx;
@@ -39,6 +39,7 @@ class PropertyAdapter {
39
39
  this._typesWithoutAnchor = [
40
40
  Urso.types.objects.CHECKBOX,
41
41
  Urso.types.objects.EMITTER,
42
+ Urso.types.objects.EMITTERFX,
42
43
  Urso.types.objects.GRAPHICS,
43
44
  Urso.types.objects.HITAREA,
44
45
  Urso.types.objects.MASK,
@@ -36,7 +36,8 @@ class ModulesTemplateTypes {
36
36
  CHECKBOX: 20,
37
37
  SCROLLBOX: 21,
38
38
  TEXTINPUT: 22,
39
- NINESLICEPLANE: 23
39
+ NINESLICEPLANE: 23,
40
+ EMITTERFX: 24
40
41
  }
41
42
  }
42
43
  }