@vnejs/plugins.canvas.sprite 0.1.1 → 0.1.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/modules/change.js +1 -1
- package/modules/hide.js +1 -1
- package/modules/move.js +1 -1
- package/modules/show.js +1 -1
- package/modules/state.js +18 -9
- package/package.json +1 -1
package/modules/change.js
CHANGED
|
@@ -27,7 +27,7 @@ export class LayerSpriteChange extends Module {
|
|
|
27
27
|
|
|
28
28
|
await this.emit(this.EVENTS.INTERACT.PUSH_POP, {
|
|
29
29
|
key: `${this.name}_${layer}_${variation}`,
|
|
30
|
-
skipHandler: () => this.emit(this.EVENTS.LAYER.
|
|
30
|
+
skipHandler: () => this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer }).then(skipResolve),
|
|
31
31
|
handler: () => Promise.race([this.emitChildChange(layer, id, Number(duration), propsChange), skipPromise]),
|
|
32
32
|
});
|
|
33
33
|
await this.emitChildChange(layer, id, 0, { parts: partsReal, transition: 0 });
|
package/modules/hide.js
CHANGED
|
@@ -27,7 +27,7 @@ export class LayerSpriteHide extends Module {
|
|
|
27
27
|
|
|
28
28
|
await this.emit(this.EVENTS.INTERACT.PUSH_POP, {
|
|
29
29
|
key: `${this.name}_${layer}`,
|
|
30
|
-
skipHandler: () => this.emit(this.EVENTS.LAYER.
|
|
30
|
+
skipHandler: () => this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer }).then(skipResolve),
|
|
31
31
|
handler: () => Promise.race([this.emitChildChange(layer, id, duration, { boxProps: { ...newBoxProps, ...finishProps } }), skipPromise]),
|
|
32
32
|
});
|
|
33
33
|
|
package/modules/move.js
CHANGED
|
@@ -25,7 +25,7 @@ export class LayerSpriteMove extends Module {
|
|
|
25
25
|
|
|
26
26
|
return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
|
|
27
27
|
key: `${this.name}_${layer}_${id}`,
|
|
28
|
-
skipHandler: () => this.emit(this.EVENTS.LAYER.
|
|
28
|
+
skipHandler: () => this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer }).then(skipResolve),
|
|
29
29
|
handler: () => Promise.race([this.emitChildChange(layer, id, duration, newProps), skipPromise]),
|
|
30
30
|
});
|
|
31
31
|
};
|
package/modules/show.js
CHANGED
|
@@ -27,7 +27,7 @@ export class LayerSpriteShow extends Module {
|
|
|
27
27
|
|
|
28
28
|
return this.emit(this.EVENTS.INTERACT.PUSH_POP, {
|
|
29
29
|
key: `${this.name}_${layer}_${variation}`,
|
|
30
|
-
skipHandler: () => this.emit(this.EVENTS.LAYER.
|
|
30
|
+
skipHandler: () => this.emit(this.EVENTS.LAYER.UPDATE_FORCE, { layer }).then(skipResolve),
|
|
31
31
|
handler: () => Promise.race([this.emitChildChange(layer, id, duration, { boxProps: { ...newBoxProps, ...finishProps } }), skipPromise]),
|
|
32
32
|
});
|
|
33
33
|
};
|
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.
|
|
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 =
|
|
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.
|
|
48
|
+
if (!oldSprites.find((s) => s.id === sprite.id)) return promises.push(this.cloneSpriteAndShow(sprite));
|
|
47
49
|
|
|
48
|
-
promises.push(this.
|
|
49
|
-
promises.push(this.
|
|
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.
|
|
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.
|
|
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.
|
|
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);
|