@vnejs/plugins.text.wall 0.1.3 → 0.1.5
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/modules/wall.d.ts +2 -1
- package/dist/modules/wall.js +5 -2
- package/package.json +6 -3
- package/src/modules/wall.ts +7 -2
- package/src/tests/setup.ts +29 -0
- package/src/tests/wall.test.ts +36 -0
- package/tsconfig.json +1 -1
package/dist/modules/wall.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
|
6
6
|
import type { TextWallPluginConstants, TextWallPluginEvents, TextWallPluginParams, TextWallPluginSettings } from "../types.js";
|
|
7
7
|
export declare class TextWall extends ModuleCore<TextWallPluginEvents, TextWallPluginConstants, TextWallPluginSettings, TextWallPluginParams, ModuleGlobalStateTextWall> {
|
|
8
8
|
name: string;
|
|
9
|
+
isSetStateInProcess: boolean;
|
|
9
10
|
subscribe: () => void;
|
|
10
11
|
init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
|
|
11
12
|
emitWallChanged: () => Promise<unknown[]> | undefined;
|
|
12
13
|
onLineExec: ({ line }?: LineExecHandlerArg) => Promise<void>;
|
|
13
14
|
onTextEmitBefore: ({ isExtend }?: TextEmitBeforePayload) => Promise<void>;
|
|
14
15
|
onTextRecalc: () => Promise<unknown[] | undefined>;
|
|
15
|
-
onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<
|
|
16
|
+
onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<void>;
|
|
16
17
|
onStateClear: () => Promise<unknown[] | undefined>;
|
|
17
18
|
getRealText: (text: string, args: Record<string, unknown>) => Promise<string>;
|
|
18
19
|
recalcWallObjToken: (wallObj: WallElement) => Promise<{
|
package/dist/modules/wall.js
CHANGED
|
@@ -3,6 +3,7 @@ import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
|
|
|
3
3
|
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
4
4
|
export class TextWall extends ModuleCore {
|
|
5
5
|
name = "text.wall";
|
|
6
|
+
isSetStateInProcess = false;
|
|
6
7
|
subscribe = () => {
|
|
7
8
|
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
8
9
|
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
@@ -25,7 +26,7 @@ export class TextWall extends ModuleCore {
|
|
|
25
26
|
this.emitNext();
|
|
26
27
|
};
|
|
27
28
|
onTextEmitBefore = async ({ isExtend = false } = {}) => {
|
|
28
|
-
if (isExtend || !this.state.isStarted)
|
|
29
|
+
if (isExtend || !this.state.isStarted || this.isSetStateInProcess)
|
|
29
30
|
return;
|
|
30
31
|
if (this.state.shouldSkip)
|
|
31
32
|
return this.updateState({ shouldSkip: false });
|
|
@@ -45,8 +46,10 @@ export class TextWall extends ModuleCore {
|
|
|
45
46
|
return this.emitWallChanged();
|
|
46
47
|
};
|
|
47
48
|
onStateSet = async (payload) => {
|
|
49
|
+
this.isSetStateInProcess = true;
|
|
48
50
|
await this.onSetStateClone(payload);
|
|
49
|
-
|
|
51
|
+
await this.emitWallChanged();
|
|
52
|
+
this.isSetStateInProcess = false;
|
|
50
53
|
};
|
|
51
54
|
onStateClear = async () => {
|
|
52
55
|
this.setDefaultState();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.text.wall",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"tsconfig.json"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
22
|
"build": "npx @vnejs/monorepo package",
|
|
23
23
|
"publish:major:plugin": "npm run publish:major",
|
|
24
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
"@vnejs/shared": "~0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@vnejs/configs.ts-common": "~0.1.0"
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.1.0",
|
|
43
|
+
"@vnejs/configs.vitest": "~0.1.0",
|
|
44
|
+
"@vnejs/test-utils": "~0.1.0",
|
|
45
|
+
"@vnejs/contracts.text": "~0.1.0"
|
|
43
46
|
}
|
|
44
47
|
}
|
package/src/modules/wall.ts
CHANGED
|
@@ -18,6 +18,8 @@ export class TextWall extends ModuleCore<
|
|
|
18
18
|
> {
|
|
19
19
|
name = "text.wall";
|
|
20
20
|
|
|
21
|
+
isSetStateInProcess = false;
|
|
22
|
+
|
|
21
23
|
subscribe = () => {
|
|
22
24
|
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
23
25
|
|
|
@@ -46,7 +48,7 @@ export class TextWall extends ModuleCore<
|
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
onTextEmitBefore = async ({ isExtend = false }: TextEmitBeforePayload = {}) => {
|
|
49
|
-
if (isExtend || !this.state.isStarted) return;
|
|
51
|
+
if (isExtend || !this.state.isStarted || this.isSetStateInProcess) return;
|
|
50
52
|
if (this.state.shouldSkip) return this.updateState({ shouldSkip: false });
|
|
51
53
|
|
|
52
54
|
const { texts, tokens, uid } = this.globalState.text;
|
|
@@ -71,9 +73,12 @@ export class TextWall extends ModuleCore<
|
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
onStateSet = async (payload: ModuleGlobalStateRegistry) => {
|
|
76
|
+
this.isSetStateInProcess = true;
|
|
77
|
+
|
|
74
78
|
await this.onSetStateClone(payload);
|
|
79
|
+
await this.emitWallChanged();
|
|
75
80
|
|
|
76
|
-
|
|
81
|
+
this.isSetStateInProcess = false;
|
|
77
82
|
};
|
|
78
83
|
|
|
79
84
|
onStateClear = async () => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CONSTANTS as TEXT_CONST, PLUGIN_NAME as TEXT, SUBSCRIBE_EVENTS as TEXT_EVENTS } from "@vnejs/contracts.text";
|
|
2
|
+
import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.text.wall";
|
|
3
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
export const registerTextWallPluginVne = () => {
|
|
6
|
+
registerCoreVne();
|
|
7
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
8
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createTextWallTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
12
|
+
ModuleClass: T,
|
|
13
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
14
|
+
) => {
|
|
15
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
16
|
+
state: {
|
|
17
|
+
text: { uid: "1", texts: [{ text: "line", args: {} }], tokens: [], speaker: "hero" },
|
|
18
|
+
"text.speaker": { speakers: { hero: {} }, speaker: "hero" },
|
|
19
|
+
...(options.state ?? {}),
|
|
20
|
+
},
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SUBSCRIBE_EVENTS, PLUGIN_NAME };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
4
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
import { TextWall } from "../modules/wall.js";
|
|
7
|
+
import { createTextWallTestModule, registerTextWallPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("TextWall", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerTextWallPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("start command enables wall capture", async () => {
|
|
15
|
+
const { module, observer } = createTextWallTestModule(TextWall, { subscribe: false });
|
|
16
|
+
const changed = spyEvent(observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
17
|
+
const next = spyEvent(observer, SCENARIO_EVENTS.NEXT);
|
|
18
|
+
|
|
19
|
+
await (module as TextWall).onLineExec({ line: "start" });
|
|
20
|
+
|
|
21
|
+
expect((module as TextWall).state.isStarted).toBe(true);
|
|
22
|
+
expect(changed).toHaveBeenCalledOnce();
|
|
23
|
+
expect(next).toHaveBeenCalledOnce();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("clear command resets wall", async () => {
|
|
27
|
+
const { module, observer } = createTextWallTestModule(TextWall, { subscribe: false });
|
|
28
|
+
|
|
29
|
+
(module as TextWall).setState({ wall: [{ texts: [], tokens: [], uid: "1", speaker: "hero", speakerInfo: {} }], isStarted: true, shouldSkip: false });
|
|
30
|
+
|
|
31
|
+
await (module as TextWall).onLineExec({ line: "clear" });
|
|
32
|
+
|
|
33
|
+
expect((module as TextWall).state.wall).toEqual([]);
|
|
34
|
+
expect((module as TextWall).state.shouldSkip).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
package/tsconfig.json
CHANGED