@vnejs/plugins.text 0.1.1 → 0.1.3
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 +2 -0
- package/modules/cycle.js +2 -1
- package/modules/speaker.js +0 -2
- package/modules/text.js +5 -4
- package/modules/wall.js +44 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { TextMeet } from "./modules/meet";
|
|
|
11
11
|
import { TextReplace } from "./modules/replace";
|
|
12
12
|
import { TextSpeaker } from "./modules/speaker";
|
|
13
13
|
import { Text } from "./modules/text";
|
|
14
|
+
import { TextWall } from "./modules/wall";
|
|
14
15
|
|
|
15
16
|
regPlugin("TEXT", { constants, events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS, params }, [
|
|
16
17
|
TextCycle,
|
|
@@ -19,4 +20,5 @@ regPlugin("TEXT", { constants, events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS
|
|
|
19
20
|
TextReplace,
|
|
20
21
|
TextSpeaker,
|
|
21
22
|
Text,
|
|
23
|
+
TextWall,
|
|
22
24
|
]);
|
package/modules/cycle.js
CHANGED
|
@@ -31,11 +31,12 @@ export class TextCycle extends Module {
|
|
|
31
31
|
this.globalState.text.tokensVisible += Math.floor(diff / delayForOneChar);
|
|
32
32
|
|
|
33
33
|
const { tokens: currentTokens, tokensVisible = 0, uid = "" } = this.globalState.text;
|
|
34
|
+
const { wall = [] } = this.globalState["text.wall"];
|
|
34
35
|
|
|
35
36
|
if (currentTokens !== tokens) return;
|
|
36
37
|
if (tokensVisible > tokens.length) return this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: false });
|
|
37
38
|
|
|
38
|
-
await this.emit(this.EVENTS.TEXT.CHANGED, { tokens, tokensVisible, uid });
|
|
39
|
+
await this.emit(this.EVENTS.TEXT.CHANGED, { tokens, tokensVisible, uid, wall });
|
|
39
40
|
|
|
40
41
|
return this.setUpdateTextRaf(tokens, ts - (diff % delayForOneChar));
|
|
41
42
|
};
|
package/modules/speaker.js
CHANGED
package/modules/text.js
CHANGED
|
@@ -16,10 +16,10 @@ export class Text extends Module {
|
|
|
16
16
|
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
17
17
|
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
18
18
|
};
|
|
19
|
-
init =
|
|
20
|
-
await this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineHandler });
|
|
21
|
-
|
|
19
|
+
init = () => {
|
|
22
20
|
this.shared.textNoAnimationSources = [];
|
|
21
|
+
|
|
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
25
|
const { text } = line.match(this.CONST.TEXT.LINE_REG).groups;
|
|
@@ -27,6 +27,7 @@ export class Text extends Module {
|
|
|
27
27
|
await this.emit(this.EVENTS.TEXT.EMIT_BEFORE);
|
|
28
28
|
await this.emit(this.EVENTS.TEXT.EMIT, { text, ...args });
|
|
29
29
|
};
|
|
30
|
+
|
|
30
31
|
onTextEmit = async ({ text, ...args }) => {
|
|
31
32
|
const [uid, tokens] = [await this.emitOne(this.EVENTS.VENDORS.UID), textToTokens(await this.getRealText(text))];
|
|
32
33
|
const tokensVisible = this.shared.textNoAnimationSources.length ? BIG_VALUE : 0;
|
|
@@ -64,7 +65,7 @@ export class Text extends Module {
|
|
|
64
65
|
setNewState = (state) => this.emit(this.EVENTS.TEXT.EMIT, { text: state.text, ...state.args });
|
|
65
66
|
getRealText = (text) => this.emitOne(this.EVENTS.TEXT.REPLACE, { text, label: this.globalState.scenario.label, state: this.globalState });
|
|
66
67
|
emitAnimationEnd = () => this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: true });
|
|
67
|
-
emitTextChanged = () => this.emit(this.EVENTS.TEXT.CHANGED, this.state);
|
|
68
|
+
emitTextChanged = () => this.emit(this.EVENTS.TEXT.CHANGED, { ...this.state, wall: this.globalState["text.wall"].wall });
|
|
68
69
|
|
|
69
70
|
getDefaultState = () => ({ text: "", tokensVisible: 0, uid: "", tokens: [], args: {} });
|
|
70
71
|
}
|
package/modules/wall.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import { textToTokens } from "./utils";
|
|
4
|
+
|
|
5
|
+
export class TextWall extends Module {
|
|
6
|
+
name = "text.wall";
|
|
7
|
+
|
|
8
|
+
subscribe = () => {
|
|
9
|
+
this.on(this.EVENTS.TEXT.INTERACT, this.onTextInteract);
|
|
10
|
+
|
|
11
|
+
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
12
|
+
|
|
13
|
+
this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
|
|
14
|
+
this.on(this.EVENTS.STATE.SET, this.setStateFromGlobalState);
|
|
15
|
+
};
|
|
16
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineHandler });
|
|
17
|
+
onLineHandler = (line) => {
|
|
18
|
+
if (line === "clear") this.updateState({ wall: [] });
|
|
19
|
+
if (line === "start") this.updateState({ wall: [], isWallStarted: true });
|
|
20
|
+
if (line === "end") this.updateState({ wall: [], isWallStarted: false });
|
|
21
|
+
|
|
22
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
onTextInteract = ({ state } = {}) => {
|
|
26
|
+
if (state !== this.CONST.TEXT.INTERACT_STATES.NEXT || !this.state.isWallStarted) return;
|
|
27
|
+
|
|
28
|
+
const { text, tokens, uid, args } = this.globalState.text;
|
|
29
|
+
const { speaker, meet } = this.globalState["text.speaker"];
|
|
30
|
+
|
|
31
|
+
this.updateState({ wall: [...this.state.wall, { text, tokens, uid, args, speaker, meet }] });
|
|
32
|
+
};
|
|
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
|
+
});
|
|
37
|
+
|
|
38
|
+
return this.emit(this.EVENTS.TEXT.CHANGED, { ...this.globalState.text, wall: this.state.wall });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
getRealText = (text) => this.emitOne(this.EVENTS.TEXT.REPLACE, { text, label: this.globalState.scenario.label, state: this.globalState });
|
|
42
|
+
|
|
43
|
+
getDefaultState = () => ({ wall: [], isWallStarted: false });
|
|
44
|
+
}
|