@vnejs/plugins.canvas.sprite.speak 0.1.1 → 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/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/speak.d.ts +14 -0
- package/dist/modules/speak.js +48 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/utils/speak.d.ts +23 -0
- package/dist/utils/speak.js +1 -0
- package/package.json +34 -6
- package/src/index.ts +6 -0
- package/src/modules/speak.ts +68 -0
- package/src/types.ts +17 -0
- package/src/utils/speak.ts +26 -0
- package/tsconfig.json +9 -0
- package/index.js +0 -5
- package/modules/speak.js +0 -53
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
|
|
3
|
+
import type { SpriteSpeakPreloadPayload, SpriteSpeakRecord, TextEmitPayload } from "../utils/speak.js";
|
|
4
|
+
export declare class LayerSpriteSpeak extends Module<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
inProcessSpeaker: string | null;
|
|
7
|
+
subscribe: () => void;
|
|
8
|
+
onText: ({ speaker }?: TextEmitPayload) => void;
|
|
9
|
+
onTextCicle: () => Promise<void | undefined>;
|
|
10
|
+
onTextEndAnimation: () => Promise<false | void>;
|
|
11
|
+
onSpritePreload: ({ variation, args, priority }?: SpriteSpeakPreloadPayload) => false | Promise<[unknown[] | undefined, unknown[] | undefined]>;
|
|
12
|
+
setSpeakOption: (sprite: SpriteSpeakRecord, value: boolean) => Promise<void>;
|
|
13
|
+
getSpeakerSprite: () => Promise<SpriteSpeakRecord | undefined>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class LayerSpriteSpeak extends Module {
|
|
3
|
+
name = "layer.sprite.speak";
|
|
4
|
+
inProcessSpeaker = null;
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.TEXT.EMIT, this.onText);
|
|
7
|
+
this.on(this.EVENTS.TEXT.CICLE, this.onTextCicle);
|
|
8
|
+
this.on(this.EVENTS.TEXT.EMIT_END, this.onTextEndAnimation);
|
|
9
|
+
this.on(this.EVENTS.LAYER_SPRITE.PRELOAD, this.onSpritePreload);
|
|
10
|
+
};
|
|
11
|
+
onText = ({ speaker = "" } = {}) => {
|
|
12
|
+
if (speaker && !this.shared.textNoAnimationSources.length)
|
|
13
|
+
this.inProcessSpeaker = speaker;
|
|
14
|
+
};
|
|
15
|
+
onTextCicle = async () => {
|
|
16
|
+
const sprite = await this.getSpeakerSprite();
|
|
17
|
+
return sprite && this.setSpeakOption(sprite, true);
|
|
18
|
+
};
|
|
19
|
+
onTextEndAnimation = async () => {
|
|
20
|
+
if (!this.inProcessSpeaker || this.shared.textNoAnimationSources.length)
|
|
21
|
+
return;
|
|
22
|
+
const sprite = await this.getSpeakerSprite();
|
|
23
|
+
this.inProcessSpeaker = null;
|
|
24
|
+
return sprite?.args?.options?.speak && this.setSpeakOption(sprite, false);
|
|
25
|
+
};
|
|
26
|
+
onSpritePreload = ({ variation = "", args = {}, priority } = {}) => !args.options &&
|
|
27
|
+
Promise.all([
|
|
28
|
+
this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: true } } }),
|
|
29
|
+
this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: false } } }),
|
|
30
|
+
]);
|
|
31
|
+
setSpeakOption = async (sprite, value) => {
|
|
32
|
+
const args = (await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite.args));
|
|
33
|
+
if (!args.options)
|
|
34
|
+
args.options = {};
|
|
35
|
+
args.options.speak = value;
|
|
36
|
+
await this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, { ...sprite, args });
|
|
37
|
+
};
|
|
38
|
+
getSpeakerSprite = async () => {
|
|
39
|
+
for (let i = 0; i < 5; i++) {
|
|
40
|
+
const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker }));
|
|
41
|
+
if (sprite) {
|
|
42
|
+
await this.waitRerender();
|
|
43
|
+
return this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker });
|
|
44
|
+
}
|
|
45
|
+
await this.waitRerender();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "@vnejs/plugins.text.contract";
|
|
2
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
3
|
+
import type { PluginName as SpritePluginName, SubscribeEvents as SpriteSubscribeEvents } from "@vnejs/plugins.canvas.sprite.contract";
|
|
4
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/plugins.text.contract";
|
|
5
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
|
|
6
|
+
export type SpriteSpeakPluginEvents = VnePluginEventsMapRegistry & Record<SpritePluginName, SpriteSubscribeEvents> & Record<TextPluginName, TextSubscribeEvents> & Record<VendorsPluginName, VendorsSubscribeEvents>;
|
|
7
|
+
export type SpriteSpeakPluginConstants = VnePluginConstantsMapRegistry;
|
|
8
|
+
export type SpriteSpeakPluginSettings = VnePluginSettingsMapRegistry;
|
|
9
|
+
export type SpriteSpeakPluginParams = VnePluginParamsMapRegistry;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vnejs/plugins.text.contract";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type TextEmitPayload = {
|
|
2
|
+
speaker?: string;
|
|
3
|
+
};
|
|
4
|
+
export type SpriteSpeakArgs = Record<string, unknown> & {
|
|
5
|
+
parts?: Record<string, string>;
|
|
6
|
+
options?: {
|
|
7
|
+
speak?: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type SpriteSpeakRecord = {
|
|
11
|
+
id: string;
|
|
12
|
+
variation?: string;
|
|
13
|
+
layer?: string;
|
|
14
|
+
mediaType?: string;
|
|
15
|
+
position?: string;
|
|
16
|
+
duration?: number;
|
|
17
|
+
args?: SpriteSpeakArgs;
|
|
18
|
+
};
|
|
19
|
+
export type SpriteSpeakPreloadPayload = {
|
|
20
|
+
variation?: string;
|
|
21
|
+
args?: SpriteSpeakArgs;
|
|
22
|
+
priority?: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.canvas.sprite.speak",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.4",
|
|
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
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"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"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.canvas.sprite.speak.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/plugins.canvas.sprite.contract": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.vendors.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/plugins.text.contract": "~0.0.1",
|
|
40
|
+
"@vnejs/shared": "~0.0.9"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
44
|
+
}
|
|
17
45
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import type { SpriteSpeakPluginConstants, SpriteSpeakPluginEvents, SpriteSpeakPluginParams, SpriteSpeakPluginSettings } from "../types.js";
|
|
4
|
+
import type { SpriteSpeakArgs, SpriteSpeakPreloadPayload, SpriteSpeakRecord, TextEmitPayload } from "../utils/speak.js";
|
|
5
|
+
|
|
6
|
+
export class LayerSpriteSpeak extends Module<SpriteSpeakPluginEvents, SpriteSpeakPluginConstants, SpriteSpeakPluginSettings, SpriteSpeakPluginParams> {
|
|
7
|
+
name = "layer.sprite.speak";
|
|
8
|
+
|
|
9
|
+
inProcessSpeaker: string | null = null;
|
|
10
|
+
|
|
11
|
+
subscribe = () => {
|
|
12
|
+
this.on(this.EVENTS.TEXT.EMIT, this.onText);
|
|
13
|
+
this.on(this.EVENTS.TEXT.CICLE, this.onTextCicle);
|
|
14
|
+
this.on(this.EVENTS.TEXT.EMIT_END, this.onTextEndAnimation);
|
|
15
|
+
|
|
16
|
+
this.on(this.EVENTS.LAYER_SPRITE.PRELOAD, this.onSpritePreload);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
onText = ({ speaker = "" }: TextEmitPayload = {}) => {
|
|
20
|
+
if (speaker && !this.shared.textNoAnimationSources.length) this.inProcessSpeaker = speaker;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
onTextCicle = async () => {
|
|
24
|
+
const sprite = await this.getSpeakerSprite();
|
|
25
|
+
|
|
26
|
+
return sprite && this.setSpeakOption(sprite, true);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
onTextEndAnimation = async () => {
|
|
30
|
+
if (!this.inProcessSpeaker || this.shared.textNoAnimationSources.length) return;
|
|
31
|
+
|
|
32
|
+
const sprite = await this.getSpeakerSprite();
|
|
33
|
+
|
|
34
|
+
this.inProcessSpeaker = null;
|
|
35
|
+
|
|
36
|
+
return sprite?.args?.options?.speak && this.setSpeakOption(sprite, false);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
onSpritePreload = ({ variation = "", args = {}, priority }: SpriteSpeakPreloadPayload = {}) =>
|
|
40
|
+
!args.options &&
|
|
41
|
+
Promise.all([
|
|
42
|
+
this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: true } } }),
|
|
43
|
+
this.emit(this.EVENTS.LAYER_SPRITE.PRELOAD, { variation, priority, args: { ...args, options: { speak: false } } }),
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
setSpeakOption = async (sprite: SpriteSpeakRecord, value: boolean) => {
|
|
47
|
+
const args = (await this.emitOne(this.EVENTS.VENDORS.CLONE, sprite.args)) as SpriteSpeakArgs;
|
|
48
|
+
|
|
49
|
+
if (!args.options) args.options = {};
|
|
50
|
+
args.options.speak = value;
|
|
51
|
+
|
|
52
|
+
await this.emit(this.EVENTS.LAYER_SPRITE.CHANGE, { ...sprite, args });
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
getSpeakerSprite = async () => {
|
|
56
|
+
for (let i = 0; i < 5; i++) {
|
|
57
|
+
const sprite = (await this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker! })) as SpriteSpeakRecord | undefined;
|
|
58
|
+
|
|
59
|
+
if (sprite) {
|
|
60
|
+
await this.waitRerender();
|
|
61
|
+
|
|
62
|
+
return this.emitOne(this.EVENTS.LAYER_SPRITE.STATE_GET, { id: this.inProcessSpeaker! }) as Promise<SpriteSpeakRecord | undefined>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await this.waitRerender();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "@vnejs/plugins.text.contract";
|
|
2
|
+
|
|
3
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
4
|
+
import type { PluginName as SpritePluginName, SubscribeEvents as SpriteSubscribeEvents } from "@vnejs/plugins.canvas.sprite.contract";
|
|
5
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/plugins.text.contract";
|
|
6
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
|
|
7
|
+
|
|
8
|
+
export type SpriteSpeakPluginEvents = VnePluginEventsMapRegistry &
|
|
9
|
+
Record<SpritePluginName, SpriteSubscribeEvents> &
|
|
10
|
+
Record<TextPluginName, TextSubscribeEvents> &
|
|
11
|
+
Record<VendorsPluginName, VendorsSubscribeEvents>;
|
|
12
|
+
|
|
13
|
+
export type SpriteSpeakPluginConstants = VnePluginConstantsMapRegistry;
|
|
14
|
+
|
|
15
|
+
export type SpriteSpeakPluginSettings = VnePluginSettingsMapRegistry;
|
|
16
|
+
|
|
17
|
+
export type SpriteSpeakPluginParams = VnePluginParamsMapRegistry;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type TextEmitPayload = {
|
|
2
|
+
speaker?: string;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export type SpriteSpeakArgs = Record<string, unknown> & {
|
|
6
|
+
parts?: Record<string, string>;
|
|
7
|
+
options?: {
|
|
8
|
+
speak?: boolean;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type SpriteSpeakRecord = {
|
|
13
|
+
id: string;
|
|
14
|
+
variation?: string;
|
|
15
|
+
layer?: string;
|
|
16
|
+
mediaType?: string;
|
|
17
|
+
position?: string;
|
|
18
|
+
duration?: number;
|
|
19
|
+
args?: SpriteSpeakArgs;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type SpriteSpeakPreloadPayload = {
|
|
23
|
+
variation?: string;
|
|
24
|
+
args?: SpriteSpeakArgs;
|
|
25
|
+
priority?: string;
|
|
26
|
+
};
|
package/tsconfig.json
ADDED
package/index.js
DELETED
package/modules/speak.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
}
|