@vnejs/plugins.core.text 0.0.2 → 0.1.1

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,6 +1 @@
1
- export const DEFAULT_SPEAKER = { names: { default: [""] }, color: "#ffffff" };
2
- export const DEFAULT_SPEAKER_NAME = "default";
3
- export const LINE_REG = /^((?<speaker>[a-zA-z_0-9]+) )?["](?<text>.+)["]( (?<hash>.*))?$/;
4
- export const INTERFACE_VIEWS = { ADV: "adv", NVL: "nvl" };
5
- export const SIZES = { XS: "xs", S: "s", M: "m", L: "l", XL: "xl" };
6
1
  export const INTERACT_STATES = { EMPTY: "empty", RENDERING: "rendering", SHOWED: "showed" };
package/const/events.js CHANGED
@@ -7,4 +7,5 @@ export const SUBSCRIBE_EVENTS = {
7
7
  SPEAKER_REG: "vne:text:speaker_reg",
8
8
  VISIT: "vne:text:visit",
9
9
  MEET: "vne:text:meet",
10
+ CHANGED: "vne:text:changed",
10
11
  };
@@ -0,0 +1,10 @@
1
+ export const DEFAULT_CHAR_SHOW_SPEED = 1;
2
+
3
+ export const TOKEN_RENDER_DELAY = 16;
4
+
5
+ export const DEFAULT_SPEAKER = { names: { default: [""] }, color: "#ffffff", opacity: 1 };
6
+ export const DEFAULT_SPEAKER_NAME = "default";
7
+
8
+ export const SPEAKERS_INFO = {
9
+ [DEFAULT_SPEAKER_NAME]: DEFAULT_SPEAKER,
10
+ };
package/const/settings.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export const SETTINGS_KEYS = {
2
- SPEED: "vne:text:speed",
2
+ TOKEN_RENDER_SPEED: "vne:text:token_render_speed",
3
3
  };
package/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import * as constants from "./const/const";
2
+ import { SUBSCRIBE_EVENTS } from "./const/events";
3
+ import * as params from "./const/params";
4
+ import { SETTINGS_KEYS } from "./const/settings";
5
+
6
+ type ConstantsType = typeof constants;
7
+ type SubscribeEventsType = typeof SUBSCRIBE_EVENTS;
8
+ type ParamsType = typeof params;
9
+ type SettingsKeysType = typeof SETTINGS_KEYS;
10
+
11
+ const PLUGIN_NAME = "TEXT";
12
+
13
+ declare global {
14
+ interface CONST {
15
+ [PLUGIN_NAME]: ConstantsType;
16
+ }
17
+ interface EVENTS {
18
+ [PLUGIN_NAME]: SubscribeEventsType;
19
+ }
20
+ interface PARAMS {
21
+ [PLUGIN_NAME]: ParamsType;
22
+ }
23
+ interface SETTINGS {
24
+ [PLUGIN_NAME]: SettingsKeysType;
25
+ }
26
+ }
package/index.js CHANGED
@@ -2,6 +2,7 @@ import { regPlugin } from "@vnejs/shared";
2
2
 
3
3
  import * as constants from "./const/const";
4
4
  import { SUBSCRIBE_EVENTS } from "./const/events";
5
+ import * as params from "./const/params";
5
6
  import { SETTINGS_KEYS } from "./const/settings";
6
7
 
7
8
  import { TextCycle } from "./modules/cycle";
@@ -10,10 +11,4 @@ import { TextMeet } from "./modules/meet";
10
11
  import { TextSpeaker } from "./modules/speaker";
11
12
  import { Text } from "./modules/text";
12
13
 
13
- regPlugin("TEXT", { constants, events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS }, [
14
- TextCycle,
15
- TextInteract,
16
- TextMeet,
17
- TextSpeaker,
18
- Text,
19
- ]);
14
+ regPlugin("TEXT", { constants, events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS, params }, [TextCycle, TextInteract, TextMeet, TextSpeaker, Text]);
package/modules/cycle.js CHANGED
@@ -10,11 +10,14 @@ export class TextCycle extends Module {
10
10
  this.on(this.EVENTS.TEXT.CICLE, this.onCicle);
11
11
  this.on(this.EVENTS.TEXT.EMIT_END, this.onTextEmitEnd);
12
12
  };
13
+
14
+ init = () => this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.TEXT.TOKEN_RENDER_SPEED, value: this.PARAMS.TEXT.DEFAULT_CHAR_SHOW_SPEED });
15
+
13
16
  onCicle = ({ text = "" } = {}) => this.startUpdateCycle(text);
14
17
  startUpdateCycle = async (oldOriginalText) => {
15
18
  let lastTs = new Date().getTime();
16
19
 
17
- const textSpeed = this.shared.settings[this.SETTINGS.TEXT.SPEED];
20
+ const delayForOneChar = this.PARAMS.TEXT.TOKEN_RENDER_DELAY / this.shared.settings[this.SETTINGS.TEXT.TOKEN_RENDER_SPEED];
18
21
  const updateCounterCur = ++updateCounter;
19
22
 
20
23
  while (updateCounterCur === updateCounter) {
@@ -25,9 +28,9 @@ export class TextCycle extends Module {
25
28
  }
26
29
  const ts = new Date().getTime();
27
30
  const diff = ts - lastTs;
28
- if (diff > textSpeed) {
29
- lastTs = ts - (diff % textSpeed);
30
- this.globalState.text.charsVisible += Math.floor(diff / textSpeed);
31
+ if (diff > delayForOneChar) {
32
+ lastTs = ts - (diff % delayForOneChar);
33
+ this.globalState.text.charsVisible += Math.floor(diff / delayForOneChar);
31
34
  } else {
32
35
  continue;
33
36
  }
@@ -38,7 +41,7 @@ export class TextCycle extends Module {
38
41
  await this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: false });
39
42
  } else {
40
43
  if (originalText === oldOriginalText) {
41
- await this.emit(this.EVENTS.INTERFACE.TEXT, { text, charsVisible });
44
+ await this.emit(this.EVENTS.TEXT.CHANGED, { text, charsVisible });
42
45
  } else updateCounter++;
43
46
  }
44
47
 
@@ -6,29 +6,29 @@ export class TextInteract extends Module {
6
6
  subscribe = () => {
7
7
  this.on(this.EVENTS.TEXT.INTERACT, this.onTextInteract);
8
8
 
9
- this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
10
9
  this.on(this.EVENTS.STATE.SET, this.onStateSet);
10
+ this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
11
+ };
12
+
13
+ interactHandlerRendering = () => this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: true });
14
+ interactHandlerShowed = async () => {
15
+ await this.emit(this.EVENTS.TEXT.INTERACT, { state: this.CONST.TEXT.INTERACT_STATES.EMPTY });
16
+
17
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
11
18
  };
19
+
20
+ interactArgRendering = { key: `${this.name}.rendering`, handler: this.interactHandlerRendering };
21
+ interactArgShowed = { key: `${this.name}.showed`, handler: this.interactHandlerShowed };
22
+
12
23
  onTextInteract = async ({ state = "" } = {}) => {
13
24
  this.state.state = state;
14
25
 
15
- state === this.CONST.TEXT.INTERACT_STATES.RENDERING
16
- ? await this.emit(this.EVENTS.INTERACT.PUSH, { key: `${this.name}.rendering`, handler: this.handlerRendering })
17
- : await this.emit(this.EVENTS.INTERACT.POP, { key: `${this.name}.rendering` });
18
-
19
- state === this.CONST.TEXT.INTERACT_STATES.SHOWED
20
- ? await this.emit(this.EVENTS.INTERACT.PUSH, { key: `${this.name}.showed`, handler: this.handlerShowed })
21
- : await this.emit(this.EVENTS.INTERACT.POP, { key: `${this.name}.showed` });
26
+ await this.emit(state === this.CONST.TEXT.INTERACT_STATES.RENDERING ? this.EVENTS.INTERACT.PUSH : this.EVENTS.INTERACT.POP, this.interactArgRendering);
27
+ await this.emit(state === this.CONST.TEXT.INTERACT_STATES.SHOWED ? this.EVENTS.INTERACT.PUSH : this.EVENTS.INTERACT.POP, this.interactArgShowed);
22
28
  };
23
29
 
24
30
  onStateSet = ({ [this.name]: state }) => this.emit(this.EVENTS.TEXT.INTERACT, state);
25
31
  onStateClear = () => this.emit(this.EVENTS.TEXT.INTERACT, this.getDefaultState());
26
32
 
27
- handlerShowed = async () => {
28
- await this.emit(this.EVENTS.TEXT.INTERACT, { state: this.CONST.TEXT.INTERACT_STATES.EMPTY });
29
- this.emitNext();
30
- };
31
- handlerRendering = () => this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: true });
32
-
33
33
  getDefaultState = () => ({ state: this.CONST.TEXT.INTERACT_STATES.EMPTY });
34
34
  }
package/modules/meet.js CHANGED
@@ -3,29 +3,28 @@ import { Module } from "@vnejs/module";
3
3
  const MEET_REG = /^(?<char>[a-zA-Z0-9_\-]+)( (?<value>-?\d+))?$/;
4
4
 
5
5
  export class TextMeet extends Module {
6
- name = "meet";
6
+ name = "text.meet";
7
7
 
8
8
  subscribe = () => {
9
9
  this.on(this.EVENTS.TEXT.MEET, this.onMeet);
10
10
 
11
- this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
12
11
  this.on(this.EVENTS.STATE.SET, this.setStateFromGlobalState);
12
+ this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
13
13
  };
14
14
 
15
- init = () => this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.execHandler });
15
+ init = () => this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: "meet", handler: this.execHandler });
16
16
 
17
17
  execHandler = async (line, args) => {
18
18
  const { char, value } = line.match(MEET_REG).groups;
19
19
 
20
20
  await this.emit(this.EVENTS.TEXT.MEET, { char, value, ...args });
21
- this.emitNext();
21
+
22
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
22
23
  };
23
24
 
24
25
  onMeet = ({ char, value = 1 }) => {
25
- const realValue = Number(value);
26
- this.log({ char, value });
27
- this.state[char] = this.state[char] ? this.state[char] + realValue : realValue;
28
- };
26
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { char, value } });
29
27
 
30
- getDefaultState = () => ({});
28
+ this.state[char] = this.state[char] ? this.state[char] + Number(value) : Number(value);
29
+ };
31
30
  }
@@ -1,28 +1,16 @@
1
1
  import { Module } from "@vnejs/module";
2
2
 
3
- window.VNESpeakers = {};
4
-
5
3
  export class TextSpeaker extends Module {
6
4
  name = "text.speaker";
7
5
 
8
6
  subscribe = () => {
9
7
  this.on(this.EVENTS.TEXT.SPEAKER_REG, this.onSpeakerReg);
10
8
  };
11
- init = async () => {
12
- const defaultSpeakerName = this.CONST.TEXT.DEFAULT_SPEAKER_NAME;
13
- const defaultSpeaker = this.CONST.TEXT.DEFAULT_SPEAKER;
14
- window.VNESpeakers = { [defaultSpeakerName]: defaultSpeaker, ...window.VNESpeakers };
15
-
16
- this.shared.speakers = {};
17
-
18
- await Promise.all(Object.entries(window.VNESpeakers).map(this.mapSpeakers));
19
- };
9
+ init = () => Promise.all(Object.entries(this.PARAMS.TEXT.SPEAKERS_INFO).map(this.mapSpeakers));
20
10
 
21
11
  mapSpeakers = ([name, speaker]) => this.emit(this.EVENTS.TEXT.SPEAKER_REG, { name, speaker });
22
12
 
23
13
  onSpeakerReg = ({ name, speaker } = {}) => {
24
- this.log({ action: "reg", name, speaker });
25
-
26
- this.shared.speakers[name] = speaker;
14
+ this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "reg", name, speaker } });
27
15
  };
28
16
  }
package/modules/text.js CHANGED
@@ -4,6 +4,8 @@ import { prepareText } from "./utils";
4
4
 
5
5
  const BIG_VALUE = 99999999;
6
6
 
7
+ const LINE_REG = /^((?<speaker>[a-zA-z_0-9]+) )?["](?<text>.+)["]( (?<hash>.*))?$/;
8
+
7
9
  export class Text extends Module {
8
10
  name = "text";
9
11
 
@@ -18,29 +20,31 @@ export class Text extends Module {
18
20
  };
19
21
  init = async () => {
20
22
  await this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.onLineHandler });
21
- await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.TEXT.SPEED, value: 15 });
22
23
 
23
24
  this.shared.textNoAnimationSources = [];
24
25
  };
25
26
  onLineHandler = async (line, args) => {
26
- const { speaker, text, hash } = line.match(this.CONST.TEXT.LINE_REG).groups;
27
+ const { speaker, text, hash } = line.match(LINE_REG).groups;
27
28
 
28
29
  await this.emit(this.EVENTS.INTERFACE.SHOW);
29
30
  await this.emit(this.EVENTS.TEXT.EMIT, { speaker, text, hash, ...args });
30
31
  };
31
- onTextEmit = async ({ text: originalText, speaker = this.CONST.TEXT.DEFAULT_SPEAKER_NAME, ...otherArgs }) => {
32
- const [meet, textSpeed] = [this.globalState.meet[speaker], this.shared.settings[this.SETTINGS.TEXT.SPEED]];
33
- const [uid, text] = [
34
- await this.emitOne(this.EVENTS.VENDORS.UID),
35
- prepareText(await this.getRealText(originalText)),
36
- ];
37
- const charsVisible = textSpeed && !this.shared.textNoAnimationSources.length ? 0 : BIG_VALUE;
38
-
39
- this.updateState({ originalText, charsVisible, text: { ...otherArgs, uid, text, speaker, meet } });
32
+ onTextEmit = async ({ text: originalText, speaker = this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME, ...otherArgs }) => {
33
+ this.updateState({
34
+ originalText,
35
+ charsVisible: !this.shared.textNoAnimationSources.length ? 0 : BIG_VALUE,
36
+ text: {
37
+ ...otherArgs,
38
+ uid: await this.emitOne(this.EVENTS.VENDORS.UID),
39
+ text: prepareText(await this.getRealText(originalText)),
40
+ speaker,
41
+ meet: this.globalState["text.meet"][speaker],
42
+ },
43
+ });
40
44
 
41
45
  await this.setInterfaceText();
42
46
 
43
- if (!textSpeed || this.shared.textNoAnimationSources.length) return setImmediate(this.emitAnimationEnd);
47
+ if (this.shared.textNoAnimationSources.length) return setImmediate(this.emitAnimationEnd);
44
48
 
45
49
  this.shared.isTextAnimationInProcess = true;
46
50
 
@@ -65,14 +69,14 @@ export class Text extends Module {
65
69
 
66
70
  return this.changeTextLang();
67
71
  };
68
- setInterfaceText = () => this.emit(this.EVENTS.INTERFACE.TEXT, this.state);
72
+ setInterfaceText = () => this.emit(this.EVENTS.TEXT.CHANGED, this.state);
69
73
  changeTextLang = async () => {
70
74
  this.state.text = { ...this.state.text, text: prepareText(await this.getRealText(this.state.originalText)) };
71
75
  return this.setInterfaceText();
72
76
  };
73
- getRealText = (text) => this.getLocTextByKey(this.globalState.scenario.label, text);
77
+ getRealText = (text) => this.emitOne(this.EVENTS.LOCS.GET_TEXT, { key: text, label: this.globalState.scenario.label });
74
78
  emitAnimationEnd = () => this.emit(this.EVENTS.TEXT.EMIT_END, { isForced: true });
75
79
 
76
80
  getDefaultState = () => ({ originalText: "", charsVisible: 0, text: this.getDefaultText() });
77
- getDefaultText = () => ({ text: [], speaker: this.CONST.TEXT.DEFAULT_SPEAKER_NAME, meet: 0 });
81
+ getDefaultText = () => ({ text: [], speaker: this.PARAMS.TEXT.DEFAULT_SPEAKER_NAME, meet: 0 });
78
82
  }
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.core.text",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
- "types": "module.d.ts",
5
+ "types": "index.d.ts",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
+ "publish:major:plugin": "npm run publish:major",
9
+ "publish:minor:plugin": "npm run publish:minor",
10
+ "publish:patch:plugin": "npm run publish:patch",
8
11
  "publish:major": "npm version major && npm publish --access public",
9
12
  "publish:minor": "npm version minor && npm publish --access public",
10
13
  "publish:patch": "npm version patch && npm publish --access public"
11
14
  },
12
15
  "author": "",
13
16
  "license": "ISC",
14
- "description": "",
15
- "peerDependencies": {
16
- "@vnejs/shared": "*",
17
- "@vnejs/module": "*"
18
- }
17
+ "description": ""
19
18
  }
package/module.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { SUBSCRIBE_EVENTS } from "./const/events";
2
- import { SETTINGS_KEYS } from "./const/settings";
3
-
4
- declare module "@vnejs/shared" {
5
- interface VNE_EVENTS {
6
- TEXT: typeof SUBSCRIBE_EVENTS;
7
- }
8
- interface VNE_SETTINGS {
9
- TEXT: typeof SETTINGS_KEYS;
10
- }
11
- }