@vnejs/plugins.text 0.1.8 → 0.1.9

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/const/const.js CHANGED
@@ -1,3 +1 @@
1
1
  export const INTERACT_STATES = { EMPTY: "empty", RENDERING: "rendering", SHOWED: "showed", NEXT: "next" };
2
-
3
- export const LINE_REG = /^((?<speaker>[a-zA-z_0-9]+) )?["](?<text>.+)["]$/;
package/modules/meet.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Module } from "@vnejs/module";
2
-
3
- const MEET_REG = /^(?<char>[a-zA-Z0-9_\-]+)( (?<value>-?\d+))?$/;
2
+ import { tokenizeExecLine } from "@vnejs/helpers";
4
3
 
5
4
  export class TextMeet extends Module {
6
5
  name = "text.meet";
@@ -15,14 +14,14 @@ export class TextMeet extends Module {
15
14
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "meet", handler: this.onLineExec });
16
15
 
17
16
  onLineExec = async ({ line = "", args = {} } = {}) => {
18
- const { char, value } = line.match(MEET_REG).groups;
17
+ const [char = "", value = 1] = tokenizeExecLine(line);
19
18
 
20
19
  await this.emit(this.EVENTS.TEXT.MEET, { char, value, ...args });
21
20
 
22
21
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
23
22
  };
24
23
 
25
- onMeet = ({ char, value = 1 } = {}) => {
24
+ onMeet = ({ char = "", value = 1 } = {}) => {
26
25
  this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { char, value } });
27
26
 
28
27
  this.state[char] = this.state[char] ? this.state[char] + Number(value) : Number(value);
package/modules/text.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Module } from "@vnejs/module";
2
2
 
3
- import { textToTokens } from "./utils";
3
+ import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
4
4
 
5
5
  const BIG_VALUE = 99999999;
6
6
 
@@ -22,9 +22,15 @@ export class Text extends Module {
22
22
  return this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.SCENARIO.OTHER_MODULE, handler: this.onLineExec });
23
23
  };
24
24
  onLineExec = async ({ line = "", args = {} } = {}) => {
25
- const { text, speaker: lineSpeaker } = line.match(this.CONST.TEXT.LINE_REG).groups;
25
+ const tokens = tokenizeExecLine(line);
26
+
27
+ let [text, speaker] = [tokens[0], this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME];
28
+
29
+ if (tokens.length === 2) {
30
+ speaker = tokens[0];
31
+ text = tokens[1];
32
+ }
26
33
 
27
- const speaker = lineSpeaker || this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
28
34
  const meet = this.globalState["text.meet"][speaker] ?? 0;
29
35
 
30
36
  await this.emit(this.EVENTS.TEXT.EMIT_BEFORE);
@@ -33,7 +39,7 @@ export class Text extends Module {
33
39
  };
34
40
 
35
41
  onTextEmit = async ({ text, ...args } = {}) => {
36
- const [uid, tokens] = [await this.emitOne(this.EVENTS.VENDORS.UID), textToTokens(await this.getRealText(text))];
42
+ const [uid, tokens] = [await this.emitOne(this.EVENTS.VENDORS.UID), tokenizeText(await this.getRealText(text))];
37
43
  const tokensVisible = this.shared.textNoAnimationSources.length ? BIG_VALUE : 0;
38
44
 
39
45
  this.updateState({ text, tokensVisible, uid, tokens, args });
@@ -57,7 +63,7 @@ export class Text extends Module {
57
63
  this.shared.isTextAnimationInProcess = false;
58
64
  };
59
65
  onTextRecalc = async () => {
60
- const [uid, tokens] = [await this.emitOne(this.EVENTS.VENDORS.UID), textToTokens(await this.getRealText(this.state.text))];
66
+ const [uid, tokens] = [await this.emitOne(this.EVENTS.VENDORS.UID), tokenizeText(await this.getRealText(this.state.text))];
61
67
 
62
68
  this.updateState({ tokens, tokensVisible: tokens.length, uid });
63
69
 
package/modules/wall.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Module } from "@vnejs/module";
2
2
 
3
- import { textToTokens } from "./utils";
3
+ import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
4
4
 
5
5
  export class TextWall extends Module {
6
6
  name = "text.wall";
@@ -15,9 +15,11 @@ export class TextWall extends Module {
15
15
  };
16
16
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
17
17
  onLineExec = ({ line = "" } = {}) => {
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 });
18
+ const [action = ""] = tokenizeExecLine(line);
19
+
20
+ if (action === "clear") this.updateState({ wall: [], shouldSkip: false });
21
+ if (action === "start") this.updateState({ wall: [], isStarted: true, shouldSkip: true });
22
+ if (action === "end") this.updateState({ wall: [], isStarted: false, shouldSkip: true });
21
23
 
22
24
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
23
25
  };
@@ -45,7 +47,7 @@ export class TextWall extends Module {
45
47
  onStateSet = async ({ [this.name]: state } = {}) => this.setState(await this.emitOne(this.EVENTS.VENDORS.CLONE, state));
46
48
 
47
49
  getRealText = (text) => this.emitOne(this.EVENTS.TEXT.REPLACE, { text, label: this.globalState.scenario.label, state: this.globalState });
48
- recalcWallObjToken = async (wallObj) => ({ ...wallObj, tokens: textToTokens(await this.getRealText(wallObj.text)) });
50
+ recalcWallObjToken = async (wallObj) => ({ ...wallObj, tokens: tokenizeText(await this.getRealText(wallObj.text)) });
49
51
 
50
52
  getDefaultState = () => ({ wall: [], isStarted: false, shouldSkip: false });
51
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.text",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "scripts": {
package/modules/utils.js DELETED
@@ -1,37 +0,0 @@
1
- export const textToTokens = (str) => {
2
- const marks = {};
3
- const tokens = [];
4
-
5
- for (let i = 0; i < str.length; ) {
6
- const curChar = str[i];
7
-
8
- if (curChar === "{") {
9
- let j = 0;
10
- while (true) {
11
- j++;
12
- if (str[i + j] === "}") {
13
- if (str[i + 1] === "/") {
14
- let mark = str.slice(i + 2, i + j);
15
- if (mark.includes(":")) {
16
- mark = mark.split(":")[0];
17
- }
18
- delete marks[mark];
19
- } else {
20
- let [mark, value] = [str.slice(i + 1, i + j), true];
21
- if (mark.includes(":")) {
22
- [mark, value] = mark.split(":");
23
- }
24
- marks[mark] = value;
25
- }
26
- break;
27
- }
28
- }
29
- i += j + 1;
30
- } else {
31
- i++;
32
- tokens.push({ token: curChar, marks: { ...marks } });
33
- }
34
- }
35
-
36
- return tokens;
37
- };