@urso/core 0.4.50 → 0.4.51

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.51",
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,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
 
@@ -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
  }