@vnejs/plugins.canvas.child.sprite.speak 0.1.17

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.
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { CONSTANTS, PARAMS, SUBSCRIBE_EVENTS, PLUGIN_NAME } from "@vnejs/contracts.canvas.child.sprite.speak";
4
+ import { LayerSpriteSpeakDuration } from "./modules/duration.js";
5
+ import { LayerSpriteSpeakPreload } from "./modules/preload.js";
6
+ import { LayerSpriteSpeak } from "./modules/speak.js";
7
+ import { LayerSpriteSpeakSources } from "./modules/sources.js";
8
+ import { LayerSpriteSpeakStaff } from "./modules/staff.js";
9
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
10
+ LayerSpriteSpeakSources,
11
+ LayerSpriteSpeakDuration,
12
+ LayerSpriteSpeakPreload,
13
+ LayerSpriteSpeakStaff,
14
+ LayerSpriteSpeak,
15
+ ]);
@@ -0,0 +1,9 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
3
+ export declare class LayerSpriteSpeakDuration extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
4
+ name: string;
5
+ timeout: ReturnType<typeof setTimeout> | undefined;
6
+ subscribe: () => void;
7
+ onSpeakStart: () => void;
8
+ onSpeakMinDurationEnd: () => void;
9
+ }
@@ -0,0 +1,18 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class LayerSpriteSpeakDuration extends ModuleCore {
3
+ name = "layer.sprite.speak.duration";
4
+ timeout;
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.START, this.onSpeakStart);
7
+ };
8
+ onSpeakStart = () => {
9
+ if (this.timeout)
10
+ clearTimeout(this.timeout);
11
+ void this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.PUSH, { source: this.CONST.LAYER_SPRITE_SPEAK.SOURCE, silent: true });
12
+ this.timeout = setTimeout(this.onSpeakMinDurationEnd, this.PARAMS.LAYER_SPRITE_SPEAK.MIN_DURATION);
13
+ };
14
+ onSpeakMinDurationEnd = () => {
15
+ this.timeout = undefined;
16
+ void this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.POP, { source: this.CONST.LAYER_SPRITE_SPEAK.SOURCE });
17
+ };
18
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
3
+ import type { SpriteSpeakPreloadPayload } from "../utils/speak.js";
4
+ export declare class LayerSpriteSpeakPreload extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onSpritePreload: ({ variation, args, priority }?: SpriteSpeakPreloadPayload) => false | Promise<[unknown[] | undefined, unknown[] | undefined]>;
8
+ }
@@ -0,0 +1,12 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class LayerSpriteSpeakPreload extends ModuleCore {
3
+ name = "layer.sprite.speak.preload";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.LAYER_SPRITE.PRELOAD, this.onSpritePreload);
6
+ };
7
+ onSpritePreload = ({ variation = "", args = {}, priority } = {}) => !args.options &&
8
+ Promise.all([
9
+ this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: true } } }),
10
+ this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: false } } }),
11
+ ]);
12
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
3
+ import type { SpriteSpeakSourcePayload } from "../utils/speak.js";
4
+ export declare class LayerSpriteSpeakSources extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
5
+ name: string;
6
+ init: () => void;
7
+ subscribe: () => void;
8
+ onPush: ({ source, silent }?: SpriteSpeakSourcePayload) => void;
9
+ onPop: ({ source }?: SpriteSpeakSourcePayload) => void;
10
+ }
@@ -0,0 +1,28 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { SourcesSet } from "@vnejs/sources-set";
3
+ export class LayerSpriteSpeakSources extends ModuleCore {
4
+ name = "layer.sprite.speak.sources";
5
+ init = () => {
6
+ this.shared.layerSpriteSpeakSources = new SourcesSet();
7
+ };
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.PUSH, this.onPush);
10
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.POP, this.onPop);
11
+ };
12
+ onPush = ({ source = "", silent = false } = {}) => {
13
+ if (!source || this.shared.layerSpriteSpeakSources.has(source))
14
+ return;
15
+ const wasEmpty = this.shared.layerSpriteSpeakSources.isEmpty();
16
+ if (!this.shared.layerSpriteSpeakSources.add(source))
17
+ return;
18
+ if (wasEmpty && !silent)
19
+ this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.START);
20
+ };
21
+ onPop = ({ source = "" } = {}) => {
22
+ if (!source || !this.shared.layerSpriteSpeakSources.has(source))
23
+ return;
24
+ this.shared.layerSpriteSpeakSources.rm(source);
25
+ if (this.shared.layerSpriteSpeakSources.isEmpty())
26
+ this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.END);
27
+ };
28
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
3
+ import type { SpriteSpeakSpeakerPayload } from "../utils/speak.js";
4
+ export declare class LayerSpriteSpeak extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
5
+ name: string;
6
+ currentSpeaker: string | null;
7
+ subscribe: () => void;
8
+ onStart: () => Promise<unknown[] | undefined>;
9
+ onEnd: () => Promise<false | unknown[] | undefined>;
10
+ onSpeaker: ({ speaker }?: SpriteSpeakSpeakerPayload) => Promise<void>;
11
+ }
@@ -0,0 +1,31 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class LayerSpriteSpeak extends ModuleCore {
3
+ name = "layer.sprite.speak";
4
+ currentSpeaker = null;
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.END, this.onEnd);
7
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.START, this.onStart);
8
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.SPEAKER, this.onSpeaker);
9
+ };
10
+ onStart = async () => {
11
+ if (!this.currentSpeaker)
12
+ return;
13
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker }));
14
+ return sprite && this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: true });
15
+ };
16
+ onEnd = async () => {
17
+ if (!this.currentSpeaker)
18
+ return;
19
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker }));
20
+ this.currentSpeaker = null;
21
+ return sprite?.args?.options?.speak && this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: false });
22
+ };
23
+ onSpeaker = async ({ speaker = "" } = {}) => {
24
+ if (this.currentSpeaker && this.currentSpeaker !== speaker) {
25
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker }));
26
+ if (sprite?.args?.options?.speak)
27
+ await this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: false });
28
+ }
29
+ this.currentSpeaker = speaker;
30
+ };
31
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
3
+ import type { SpriteSpeakRecord, SpriteSpeakSetOptionPayload, SpriteSpeakSpeakerSpriteGetPayload } from "../utils/speak.js";
4
+ export declare class LayerSpriteSpeakStaff extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onSpriteGet: ({ speaker }?: SpriteSpeakSpeakerSpriteGetPayload) => Promise<SpriteSpeakRecord | undefined>;
8
+ onOptionSet: ({ sprite, value }?: SpriteSpeakSetOptionPayload) => Promise<unknown[] | undefined>;
9
+ }
@@ -0,0 +1,27 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class LayerSpriteSpeakStaff extends ModuleCore {
3
+ name = "layer.sprite.speak.staff";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, this.onSpriteGet);
6
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, this.onOptionSet);
7
+ };
8
+ onSpriteGet = async ({ speaker = "" } = {}) => {
9
+ for (let i = 0; i < 5; i++) {
10
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: speaker }));
11
+ if (sprite) {
12
+ await this.waitRerender();
13
+ return (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: speaker }));
14
+ }
15
+ await this.waitRerender();
16
+ }
17
+ };
18
+ onOptionSet = async ({ sprite, value = false } = {}) => {
19
+ if (!sprite)
20
+ return;
21
+ const args = await this.emitClone(sprite.args);
22
+ if (!args.options)
23
+ args.options = {};
24
+ args.options.speak = value;
25
+ return this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, { ...sprite, args });
26
+ };
27
+ }
@@ -0,0 +1,8 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
2
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
3
+ import type { PluginName as SpritePluginName, SubscribeEvents as SpriteSubscribeEvents } from "@vnejs/contracts.canvas.child.sprite";
4
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.canvas.child.sprite.speak";
5
+ export type SpriteSpeakPluginEvents = ModuleCoreEvents & Record<SpritePluginName, SpriteSubscribeEvents> & Record<PluginName, SubscribeEvents>;
6
+ export type SpriteSpeakPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
7
+ export type SpriteSpeakPluginSettings = ModuleCoreSettings;
8
+ export type SpriteSpeakPluginParams = ModuleCoreParams & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
@@ -0,0 +1,34 @@
1
+ export type SpriteSpeakSourcePayload = {
2
+ source?: string;
3
+ silent?: boolean;
4
+ };
5
+ export type SpriteSpeakSpeakerPayload = {
6
+ speaker?: string;
7
+ };
8
+ export type SpriteSpeakArgs = Record<string, unknown> & {
9
+ parts?: Record<string, string>;
10
+ options?: {
11
+ speak?: boolean;
12
+ };
13
+ };
14
+ export type SpriteSpeakRecord = {
15
+ id: string;
16
+ variation?: string;
17
+ layer?: string;
18
+ mediaType?: string;
19
+ position?: string;
20
+ duration?: number;
21
+ args?: SpriteSpeakArgs;
22
+ };
23
+ export type SpriteSpeakPreloadPayload = {
24
+ variation?: string;
25
+ args?: SpriteSpeakArgs;
26
+ priority?: string;
27
+ };
28
+ export type SpriteSpeakSpeakerSpriteGetPayload = {
29
+ speaker?: string;
30
+ };
31
+ export type SpriteSpeakSetOptionPayload = {
32
+ sprite?: SpriteSpeakRecord;
33
+ value?: boolean;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@vnejs/plugins.canvas.child.sprite.speak",
3
+ "version": "0.1.17",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/contracts.canvas.child.sprite.speak": "~0.1.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/module.core": "~0.1.0",
37
+ "@vnejs/contracts.canvas.child.sprite": "~0.1.0",
38
+ "@vnejs/shared": "~0.1.0",
39
+ "@vnejs/sources-set": "~0.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@vnejs/configs.ts-common": "~0.1.0"
43
+ }
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { CONSTANTS, PARAMS, SUBSCRIBE_EVENTS, PLUGIN_NAME } from "@vnejs/contracts.canvas.child.sprite.speak";
5
+
6
+ import { LayerSpriteSpeakDuration } from "./modules/duration.js";
7
+ import { LayerSpriteSpeakPreload } from "./modules/preload.js";
8
+ import { LayerSpriteSpeak } from "./modules/speak.js";
9
+ import { LayerSpriteSpeakSources } from "./modules/sources.js";
10
+ import { LayerSpriteSpeakStaff } from "./modules/staff.js";
11
+
12
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
13
+ LayerSpriteSpeakSources,
14
+ LayerSpriteSpeakDuration,
15
+ LayerSpriteSpeakPreload,
16
+ LayerSpriteSpeakStaff,
17
+ LayerSpriteSpeak,
18
+ ]);
@@ -0,0 +1,27 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
4
+
5
+ export class LayerSpriteSpeakDuration extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
6
+ name = "layer.sprite.speak.duration";
7
+
8
+ timeout: ReturnType<typeof setTimeout> | undefined;
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.START, this.onSpeakStart);
12
+ };
13
+
14
+ onSpeakStart = () => {
15
+ if (this.timeout) clearTimeout(this.timeout);
16
+
17
+ void this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.PUSH, { source: this.CONST.LAYER_SPRITE_SPEAK.SOURCE, silent: true });
18
+
19
+ this.timeout = setTimeout(this.onSpeakMinDurationEnd, this.PARAMS.LAYER_SPRITE_SPEAK.MIN_DURATION);
20
+ };
21
+
22
+ onSpeakMinDurationEnd = () => {
23
+ this.timeout = undefined;
24
+
25
+ void this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.POP, { source: this.CONST.LAYER_SPRITE_SPEAK.SOURCE });
26
+ };
27
+ }
@@ -0,0 +1,19 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
4
+ import type { SpriteSpeakPreloadPayload } from "../utils/speak.js";
5
+
6
+ export class LayerSpriteSpeakPreload extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
7
+ name = "layer.sprite.speak.preload";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.LAYER_SPRITE.PRELOAD, this.onSpritePreload);
11
+ };
12
+
13
+ onSpritePreload = ({ variation = "", args = {}, priority }: SpriteSpeakPreloadPayload = {}) =>
14
+ !args.options &&
15
+ Promise.all([
16
+ this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: true } } }),
17
+ this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: false } } }),
18
+ ]);
19
+ }
@@ -0,0 +1,36 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { SourcesSet } from "@vnejs/sources-set";
3
+
4
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
5
+ import type { SpriteSpeakSourcePayload } from "../utils/speak.js";
6
+
7
+ export class LayerSpriteSpeakSources extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
8
+ name = "layer.sprite.speak.sources";
9
+
10
+ init = () => {
11
+ this.shared.layerSpriteSpeakSources = new SourcesSet();
12
+ };
13
+
14
+ subscribe = () => {
15
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.PUSH, this.onPush);
16
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.POP, this.onPop);
17
+ };
18
+
19
+ onPush = ({ source = "", silent = false }: SpriteSpeakSourcePayload = {}) => {
20
+ if (!source || this.shared.layerSpriteSpeakSources.has(source)) return;
21
+
22
+ const wasEmpty = this.shared.layerSpriteSpeakSources.isEmpty();
23
+
24
+ if (!this.shared.layerSpriteSpeakSources.add(source)) return;
25
+
26
+ if (wasEmpty && !silent) this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.START);
27
+ };
28
+
29
+ onPop = ({ source = "" }: SpriteSpeakSourcePayload = {}) => {
30
+ if (!source || !this.shared.layerSpriteSpeakSources.has(source)) return;
31
+
32
+ this.shared.layerSpriteSpeakSources.rm(source);
33
+
34
+ if (this.shared.layerSpriteSpeakSources.isEmpty()) this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.END);
35
+ };
36
+ }
@@ -0,0 +1,44 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
4
+ import type { SpriteSpeakRecord, SpriteSpeakSpeakerPayload } from "../utils/speak.js";
5
+
6
+ export class LayerSpriteSpeak extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
7
+ name = "layer.sprite.speak";
8
+
9
+ currentSpeaker: string | null = null;
10
+
11
+ subscribe = () => {
12
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.END, this.onEnd);
13
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.START, this.onStart);
14
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.SPEAKER, this.onSpeaker);
15
+ };
16
+
17
+ onStart = async () => {
18
+ if (!this.currentSpeaker) return;
19
+
20
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker })) as SpriteSpeakRecord | undefined;
21
+
22
+ return sprite && this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: true });
23
+ };
24
+
25
+ onEnd = async () => {
26
+ if (!this.currentSpeaker) return;
27
+
28
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker })) as SpriteSpeakRecord | undefined;
29
+
30
+ this.currentSpeaker = null;
31
+
32
+ return sprite?.args?.options?.speak && this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: false });
33
+ };
34
+
35
+ onSpeaker = async ({ speaker = "" }: SpriteSpeakSpeakerPayload = {}) => {
36
+ if (this.currentSpeaker && this.currentSpeaker !== speaker) {
37
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, { speaker: this.currentSpeaker })) as SpriteSpeakRecord | undefined;
38
+
39
+ if (sprite?.args?.options?.speak) await this.emit(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, { sprite, value: false });
40
+ }
41
+
42
+ this.currentSpeaker = speaker;
43
+ };
44
+ }
@@ -0,0 +1,38 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
4
+ import type { SpriteSpeakArgs, SpriteSpeakRecord, SpriteSpeakSetOptionPayload, SpriteSpeakSpeakerSpriteGetPayload } from "../utils/speak.js";
5
+
6
+ export class LayerSpriteSpeakStaff extends ModuleCore<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
7
+ name = "layer.sprite.speak.staff";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.SPRITE_GET, this.onSpriteGet);
11
+ this.on(this.EVENTS.LAYER_SPRITE_SPEAK.OPTION_SET, this.onOptionSet);
12
+ };
13
+
14
+ onSpriteGet = async ({ speaker = "" }: SpriteSpeakSpeakerSpriteGetPayload = {}) => {
15
+ for (let i = 0; i < 5; i++) {
16
+ const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: speaker })) as SpriteSpeakRecord | undefined;
17
+
18
+ if (sprite) {
19
+ await this.waitRerender();
20
+
21
+ return (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: speaker })) as SpriteSpeakRecord | undefined;
22
+ }
23
+
24
+ await this.waitRerender();
25
+ }
26
+ };
27
+
28
+ onOptionSet = async ({ sprite, value = false }: SpriteSpeakSetOptionPayload = {}) => {
29
+ if (!sprite) return;
30
+
31
+ const args = await this.emitClone<SpriteSpeakArgs>(sprite.args);
32
+
33
+ if (!args.options) args.options = {};
34
+ args.options.speak = value;
35
+
36
+ return this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, { ...sprite, args });
37
+ };
38
+ }
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ import "@vnejs/contracts.canvas.child.sprite.speak";
2
+
3
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
4
+ import type { PluginName as SpritePluginName, SubscribeEvents as SpriteSubscribeEvents } from "@vnejs/contracts.canvas.child.sprite";
5
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.canvas.child.sprite.speak";
6
+
7
+ export type SpriteSpeakPluginEvents = ModuleCoreEvents & Record<SpritePluginName, SpriteSubscribeEvents> & Record<PluginName, SubscribeEvents>;
8
+
9
+ export type SpriteSpeakPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
10
+
11
+ export type SpriteSpeakPluginSettings = ModuleCoreSettings;
12
+
13
+ export type SpriteSpeakPluginParams = ModuleCoreParams & Record<PluginName, Params>;
@@ -0,0 +1,40 @@
1
+ export type SpriteSpeakSourcePayload = {
2
+ source?: string;
3
+ silent?: boolean;
4
+ };
5
+
6
+ export type SpriteSpeakSpeakerPayload = {
7
+ speaker?: string;
8
+ };
9
+
10
+ export type SpriteSpeakArgs = Record<string, unknown> & {
11
+ parts?: Record<string, string>;
12
+ options?: {
13
+ speak?: boolean;
14
+ };
15
+ };
16
+
17
+ export type SpriteSpeakRecord = {
18
+ id: string;
19
+ variation?: string;
20
+ layer?: string;
21
+ mediaType?: string;
22
+ position?: string;
23
+ duration?: number;
24
+ args?: SpriteSpeakArgs;
25
+ };
26
+
27
+ export type SpriteSpeakPreloadPayload = {
28
+ variation?: string;
29
+ args?: SpriteSpeakArgs;
30
+ priority?: string;
31
+ };
32
+
33
+ export type SpriteSpeakSpeakerSpriteGetPayload = {
34
+ speaker?: string;
35
+ };
36
+
37
+ export type SpriteSpeakSetOptionPayload = {
38
+ sprite?: SpriteSpeakRecord;
39
+ value?: boolean;
40
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }