@vnejs/plugins.canvas.sprite 0.1.2 → 0.1.4

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/const/const.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export const ACTIONS = { SHOW: "show", HIDE: "hide", CHANGE: "change", MOVE: "move" };
2
2
 
3
- export const LINE_MOVE_REG = /^(?<id>[a-zA-Z_0-9-]+) move (?<position>[a-zA-Z_0-9-]+)( (?<duration>\d+))?( async)?$/;
3
+ export const LINE_MOVE_REG = /^(?<id>[a-zA-Z_0-9-]+) move (?<position>[a-zA-Z_0-9-]+)( (?<duration>\d+))?$/;
4
4
  export const LINE_SHOW_REG =
5
- /^(?<id>[a-zA-Z_0-9-]+) show (?<position>[a-zA-Z_0-9-]+) {(?<variation>[a-zA-Z_0-9-/]+)}( (?<transition>[a-zA-Z_0-9-]+)[:](?<duration>\d+))?( async)?$/;
6
- export const LINE_HIDE_REG = /^(?<id>[a-zA-Z_0-9-]+) hide( (?<transition>[a-zA-Z_0-9-]+)[:](?<duration>\d+))?( async)?$/;
7
- export const LINE_CHANGE_REG = /^(?<id>[a-zA-Z_0-9-]+) change {(?<variation>[a-zA-Z_0-9-/]+)}( (?<duration>\d+))?( async)?$/;
5
+ /^(?<id>[a-zA-Z_0-9-]+) show (?<position>[a-zA-Z_0-9-]+) {(?<variation>[a-zA-Z_0-9-/]+)}( (?<transition>[a-zA-Z_0-9-]+)[:](?<duration>\d+))?$/;
6
+ export const LINE_HIDE_REG = /^(?<id>[a-zA-Z_0-9-]+) hide( (?<transition>[a-zA-Z_0-9-]+)[:](?<duration>\d+))?$/;
7
+ export const LINE_CHANGE_REG = /^(?<id>[a-zA-Z_0-9-]+) change {(?<variation>[a-zA-Z_0-9-/]+)}( (?<duration>\d+))?$/;
8
8
 
9
9
  export const LAYER_CHILD_TYPE = "sprite";
package/modules/state.js CHANGED
@@ -27,11 +27,13 @@ export class LayerSpriteState extends Module {
27
27
  };
28
28
  onSpriteStateGet = ({ id } = {}) => this.state.sprites.find((e) => e.id === id);
29
29
 
30
- onStateSet = async ({ [this.name]: state }) => {
31
- await this.preloadState(state);
30
+ onStateSet = async ({ [this.name]: state } = {}) => {
31
+ const clonedState = await this.emitOne(this.EVENTS.VENDORS.CLONE, state);
32
+
33
+ await this.preloadState(clonedState);
32
34
 
33
35
  const oldSpritesByLayer = this.state.sprites.reduce(this.getSpritesByLayerFromState, {});
34
- const newSpritesByLayer = state.sprites.reduce(this.getSpritesByLayerFromState, {});
36
+ const newSpritesByLayer = clonedState.sprites.reduce(this.getSpritesByLayerFromState, {});
35
37
 
36
38
  const [promises, uniqLayers, oldLayers, newLayers] = [[], new Set(), Object.keys(oldSpritesByLayer), Object.keys(newSpritesByLayer)];
37
39
 
@@ -43,12 +45,12 @@ export class LayerSpriteState extends Module {
43
45
  const newSprites = newSpritesByLayer[layer] || [];
44
46
 
45
47
  newSprites.forEach((sprite) => {
46
- if (!oldSprites.find((s) => s.id === sprite.id)) return promises.push(this.emitSpriteShow(sprite));
48
+ if (!oldSprites.find((s) => s.id === sprite.id)) return promises.push(this.cloneSpriteAndShow(sprite));
47
49
 
48
- promises.push(this.emitSpriteChange(sprite));
49
- promises.push(this.emitSpriteMove(sprite));
50
+ promises.push(this.cloneSpriteAndChange(sprite));
51
+ promises.push(this.cloneSpriteAndMove(sprite));
50
52
  });
51
- oldSprites.forEach((sprite) => !newSprites.find((s) => s.id === sprite.id) && promises.push(this.emitSpriteHide(sprite)));
53
+ oldSprites.forEach((sprite) => !newSprites.find((s) => s.id === sprite.id) && promises.push(this.cloneSpriteAndHide(sprite)));
52
54
  });
53
55
 
54
56
  this.shared.viewForceAnimationSources.push(`${this.name}.set`);
@@ -61,23 +63,30 @@ export class LayerSpriteState extends Module {
61
63
  onMemoryCleared = async () => {
62
64
  await this.preloadState(this.state);
63
65
  this.shared.viewForceAnimationSources.push(`${this.name}.memory`);
64
- await Promise.all(this.state.sprites.map(this.emitSpriteChange));
66
+ await Promise.all(this.state.sprites.map(this.cloneSpriteAndChange));
65
67
  this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter((i) => i !== `${this.name}.memory`);
66
68
  };
67
69
 
68
70
  clearState = async () => {
69
71
  this.shared.viewForceAnimationSources.push(`${this.name}.clear`);
70
- await Promise.all(this.state.sprites.map(this.emitSpriteHide));
72
+ await Promise.all(this.state.sprites.map(this.cloneSpriteAndHide));
71
73
  this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter((i) => i !== `${this.name}.clear`);
72
74
  };
73
75
  preloadState = (state) => Promise.all(state.sprites.map(this.emitSpriteSrcGet));
74
76
 
77
+ cloneSpriteAndChange = async (sprite) => this.emitEventWithSprite(await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite), this.emitSpriteChange);
78
+ cloneSpriteAndHide = async (sprite) => this.emitEventWithSprite(await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite), this.emitSpriteHide);
79
+ cloneSpriteAndShow = async (sprite) => this.emitEventWithSprite(await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite), this.emitSpriteShow);
80
+ cloneSpriteAndMove = async (sprite) => this.emitEventWithSprite(await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite), this.emitSpriteMove);
81
+
75
82
  emitSpriteSrcGet = (sprite) => this.emit(this.EVENTS.LAYER_SPRITE.SRC_GET, sprite);
76
83
  emitSpriteChange = (sprite) => this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, sprite);
77
84
  emitSpriteMove = (sprite) => this.emit(this.EVENTS.LAYER_SPRITE.MOVE, sprite);
78
85
  emitSpriteHide = (sprite) => this.emit(this.EVENTS.LAYER_SPRITE.HIDE, sprite);
79
86
  emitSpriteShow = (sprite) => this.emit(this.EVENTS.LAYER_SPRITE.SHOW, sprite);
80
87
 
88
+ emitEventWithSprite = (sprite, cb) => cb(sprite);
89
+
81
90
  getSpritesByLayerFromState = (acc, sprite) => {
82
91
  if (!acc[sprite.layer]) acc[sprite.layer] = [];
83
92
  acc[sprite.layer].push(sprite);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.canvas.sprite",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",