@vnejs/plugins.canvas.sprite.speak 0.1.1

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/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import { LayerSpriteSpeak } from "./modules/speak";
4
+
5
+ regPlugin("LAYER_SPRITE_SPEAK", {}, [LayerSpriteSpeak]);
@@ -0,0 +1,53 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class LayerSpriteSpeak extends Module {
4
+ name = "layer.sprite.speak";
5
+
6
+ inProcessSpeaker = null;
7
+
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.TEXT.EMIT, this.onText);
10
+ this.on(this.EVENTS.TEXT.CICLE, this.onTextCicle);
11
+ this.on(this.EVENTS.TEXT.EMIT_END, this.onTextEndAnimation);
12
+ };
13
+
14
+ onText = ({ speaker = "" } = {}) => {
15
+ if (speaker && !this.shared.textNoAnimationSources.length) this.inProcessSpeaker = speaker;
16
+ };
17
+ onTextCicle = async () => {
18
+ const sprite = await this.getSpeakerSprite();
19
+
20
+ return sprite && this.setSpeakOption(sprite, true);
21
+ };
22
+ onTextEndAnimation = async () => {
23
+ if (!this.inProcessSpeaker || this.shared.textNoAnimationSources.length) return;
24
+
25
+ const sprite = await this.getSpeakerSprite();
26
+
27
+ this.inProcessSpeaker = null;
28
+
29
+ return sprite?.args?.options?.speak && this.setSpeakOption(sprite, false);
30
+ };
31
+
32
+ setSpeakOption = async (sprite, value) => {
33
+ const args = await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite.args);
34
+
35
+ if (!args.options) args.options = {};
36
+ args.options.speak = value;
37
+
38
+ await this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, { ...sprite, args });
39
+ };
40
+ getSpeakerSprite = async () => {
41
+ for (let i = 0; i < 5; i++) {
42
+ const sprite = await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker });
43
+
44
+ if (sprite) {
45
+ await this.waitRerender();
46
+
47
+ return this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker });
48
+ }
49
+
50
+ await this.waitRerender();
51
+ }
52
+ };
53
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.canvas.sprite.speak",
3
+ "version": "0.1.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "publish:patch:plugin": "npm run publish:patch",
10
+ "publish:major": "npm version major && npm publish --access public",
11
+ "publish:minor": "npm version minor && npm publish --access public",
12
+ "publish:patch": "npm version patch && npm publish --access public"
13
+ },
14
+ "author": "",
15
+ "license": "ISC",
16
+ "description": ""
17
+ }