@vnejs/plugins.text 0.1.3 → 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/modules/speaker.js +0 -9
- package/modules/text.js +6 -2
- package/modules/utils.js +1 -1
- package/modules/wall.js +9 -10
- package/package.json +1 -1
package/modules/speaker.js
CHANGED
|
@@ -9,15 +9,6 @@ export class TextSpeaker extends Module {
|
|
|
9
9
|
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
10
10
|
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
11
11
|
};
|
|
12
|
-
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "text", handler: this.onLineTextHandler });
|
|
13
|
-
onLineTextHandler = async (line, args) => {
|
|
14
|
-
const { speaker: lineSpeaker } = line.match(this.CONST.TEXT.LINE_REG).groups;
|
|
15
|
-
|
|
16
|
-
const speaker = lineSpeaker || this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
17
|
-
const meet = this.globalState["text.meet"][speaker] ?? 0;
|
|
18
|
-
|
|
19
|
-
return this.emit(this.EVENTS.TEXT.SPEAKER, { speaker, meet, args });
|
|
20
|
-
};
|
|
21
12
|
|
|
22
13
|
onTextSpeaker = ({ speaker, meet, ...args }) => {
|
|
23
14
|
this.setState({ speaker, meet, args });
|
package/modules/text.js
CHANGED
|
@@ -22,10 +22,14 @@ export class Text extends Module {
|
|
|
22
22
|
return this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineHandler });
|
|
23
23
|
};
|
|
24
24
|
onLineHandler = async (line, args) => {
|
|
25
|
-
const { text } = line.match(this.CONST.TEXT.LINE_REG).groups;
|
|
25
|
+
const { text, speaker: lineSpeaker } = line.match(this.CONST.TEXT.LINE_REG).groups;
|
|
26
|
+
|
|
27
|
+
const speaker = lineSpeaker || this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
|
|
28
|
+
const meet = this.globalState["text.meet"][speaker] ?? 0;
|
|
26
29
|
|
|
27
30
|
await this.emit(this.EVENTS.TEXT.EMIT_BEFORE);
|
|
28
|
-
|
|
31
|
+
|
|
32
|
+
return Promise.all([this.emit(this.EVENTS.TEXT.SPEAKER, { speaker, meet, args }), this.emit(this.EVENTS.TEXT.EMIT, { text, ...args })]);
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
onTextEmit = async ({ text, ...args }) => {
|
package/modules/utils.js
CHANGED
package/modules/wall.js
CHANGED
|
@@ -6,7 +6,7 @@ export class TextWall extends Module {
|
|
|
6
6
|
name = "text.wall";
|
|
7
7
|
|
|
8
8
|
subscribe = () => {
|
|
9
|
-
this.on(this.EVENTS.TEXT.
|
|
9
|
+
this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
|
|
10
10
|
|
|
11
11
|
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
12
12
|
|
|
@@ -15,15 +15,15 @@ export class TextWall extends Module {
|
|
|
15
15
|
};
|
|
16
16
|
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineHandler });
|
|
17
17
|
onLineHandler = (line) => {
|
|
18
|
-
if (line === "clear") this.updateState({ wall: [] });
|
|
19
|
-
if (line === "start") this.updateState({ wall: [],
|
|
20
|
-
if (line === "end") this.updateState({ wall: [],
|
|
18
|
+
if (line === "clear") this.updateState({ wall: [], shouldSkip: false });
|
|
19
|
+
if (line === "start") this.updateState({ wall: [], isStarted: true, shouldSkip: true });
|
|
20
|
+
if (line === "end") this.updateState({ wall: [], isStarted: false, shouldSkip: true });
|
|
21
21
|
|
|
22
22
|
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
if (state
|
|
25
|
+
onTextEmitBefore = () => {
|
|
26
|
+
if (this.state.shouldSkip) return this.updateState({ shouldSkip: false });
|
|
27
27
|
|
|
28
28
|
const { text, tokens, uid, args } = this.globalState.text;
|
|
29
29
|
const { speaker, meet } = this.globalState["text.speaker"];
|
|
@@ -31,14 +31,13 @@ export class TextWall extends Module {
|
|
|
31
31
|
this.updateState({ wall: [...this.state.wall, { text, tokens, uid, args, speaker, meet }] });
|
|
32
32
|
};
|
|
33
33
|
onTextRecalc = async () => {
|
|
34
|
-
this.updateState({
|
|
35
|
-
wall: await Promise.all(this.state.wall.map(async (wallObj) => ({ ...wallObj, tokens: textToTokens(await this.getRealText(wallObj.text)) }))),
|
|
36
|
-
});
|
|
34
|
+
this.updateState({ wall: await Promise.all(this.state.wall.map(this.recalcWallObjToken)) });
|
|
37
35
|
|
|
38
36
|
return this.emit(this.EVENTS.TEXT.CHANGED, { ...this.globalState.text, wall: this.state.wall });
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
getRealText = (text) => this.emitOne(this.EVENTS.TEXT.REPLACE, { text, label: this.globalState.scenario.label, state: this.globalState });
|
|
40
|
+
recalcWallObjToken = async (wallObj) => ({ ...wallObj, tokens: textToTokens(await this.getRealText(wallObj.text)) });
|
|
42
41
|
|
|
43
|
-
getDefaultState = () => ({ wall: [],
|
|
42
|
+
getDefaultState = () => ({ wall: [], isStarted: false, shouldSkip: false });
|
|
44
43
|
}
|