@vnejs/compatibility.scenario.choose-with-scenario.qte 0.2.1 → 0.2.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/dist/index.d.ts CHANGED
@@ -8,10 +8,10 @@ declare module "@vnejs/contracts.scenario.choose" {
8
8
  qte?: string;
9
9
  }
10
10
  }
11
- export declare class CompatibilityChooseQte extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
11
+ export declare class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
12
12
  name: string;
13
13
  pendingResolve: ((success: boolean) => void) | null;
14
- init: () => Promise<unknown[]> | undefined;
14
+ init: () => Promise<import("@vnejs/shared").EmitResults<"vne:choose:option_replace_reg">> | undefined;
15
15
  subscribe: () => void;
16
16
  onQteResult: ({ success }?: QteResultPayload) => void;
17
17
  onOptionReplace: ChooseOptionReplaceHandler;
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import "@vnejs/contracts.scenario.choose";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
  import { regModule } from "@vnejs/shared";
4
- export class CompatibilityChooseQte extends ModuleCore {
4
+ const LOGS_ACTIONS = {
5
+ MISSING: "missing",
6
+ MISSING_FALLBACK: "missing_fallback",
7
+ };
8
+ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore {
5
9
  name = "compatibility.scenario.choose-with-scenario.qte";
6
10
  pendingResolve = null;
7
- init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, {
8
- handler: this.onOptionReplace,
9
- });
11
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, { handler: this.onOptionReplace });
10
12
  subscribe = () => {
11
13
  this.on(this.EVENTS.QTE.RESULT, this.onQteResult);
12
14
  };
@@ -24,7 +26,7 @@ export class CompatibilityChooseQte extends ModuleCore {
24
26
  return index;
25
27
  const item = this.PARAMS.QTE.ITEMS[qteId];
26
28
  if (!item) {
27
- this.emitLog({ action: "missing", id: qteId });
29
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING, id: qteId });
28
30
  return this.resolveFailIndex(index, options);
29
31
  }
30
32
  const success = await new Promise((resolve) => {
@@ -38,10 +40,10 @@ export class CompatibilityChooseQte extends ModuleCore {
38
40
  resolveFailIndex = (index, options) => {
39
41
  const fallbackIndex = options.findIndex((option) => option.keywords?.includes(this.CONST.QTE.LINE_KEYWORDS.QTE_FALLBACK));
40
42
  if (fallbackIndex < 0) {
41
- this.emitLog({ action: "missing_fallback", index });
43
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING_FALLBACK, index });
42
44
  return index;
43
45
  }
44
46
  return fallbackIndex;
45
47
  };
46
48
  }
47
- regModule(CompatibilityChooseQte);
49
+ regModule(CompatibilityScenarioChooseWithScenarioQte);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/compatibility.scenario.choose-with-scenario.qte",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -7,21 +7,23 @@ import type { QteEmitPayload, QteResultPayload } from "@vnejs/contracts.scenario
7
7
 
8
8
  import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
9
9
 
10
+ const LOGS_ACTIONS = {
11
+ MISSING: "missing",
12
+ MISSING_FALLBACK: "missing_fallback",
13
+ } as const;
14
+
10
15
  declare module "@vnejs/contracts.scenario.choose" {
11
16
  interface ChooseOption {
12
17
  qte?: string;
13
18
  }
14
19
  }
15
20
 
16
- export class CompatibilityChooseQte extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
21
+ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
17
22
  name = "compatibility.scenario.choose-with-scenario.qte";
18
23
 
19
24
  pendingResolve: ((success: boolean) => void) | null = null;
20
25
 
21
- init = () =>
22
- this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, {
23
- handler: this.onOptionReplace,
24
- } satisfies ChooseOptionReplaceRegPayload);
26
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, { handler: this.onOptionReplace } satisfies ChooseOptionReplaceRegPayload);
25
27
 
26
28
  subscribe = () => {
27
29
  this.on(this.EVENTS.QTE.RESULT, this.onQteResult);
@@ -44,7 +46,7 @@ export class CompatibilityChooseQte extends ModuleCore<PluginEvents, PluginConst
44
46
  const item = this.PARAMS.QTE.ITEMS[qteId];
45
47
 
46
48
  if (!item) {
47
- this.emitLog({ action: "missing", id: qteId });
49
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING, id: qteId });
48
50
  return this.resolveFailIndex(index, options);
49
51
  }
50
52
 
@@ -62,7 +64,7 @@ export class CompatibilityChooseQte extends ModuleCore<PluginEvents, PluginConst
62
64
  const fallbackIndex = options.findIndex((option) => option.keywords?.includes(this.CONST.QTE.LINE_KEYWORDS.QTE_FALLBACK));
63
65
 
64
66
  if (fallbackIndex < 0) {
65
- this.emitLog({ action: "missing_fallback", index });
67
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING_FALLBACK, index });
66
68
  return index;
67
69
  }
68
70
 
@@ -70,4 +72,4 @@ export class CompatibilityChooseQte extends ModuleCore<PluginEvents, PluginConst
70
72
  };
71
73
  }
72
74
 
73
- regModule(CompatibilityChooseQte);
75
+ regModule(CompatibilityScenarioChooseWithScenarioQte);
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it } from "vitest";
3
3
  import { spyEvent } from "@vnejs/test-utils";
4
4
  import type { ChooseOption, ChooseOptionReplaceHandler } from "@vnejs/contracts.scenario.choose";
5
5
 
6
- import { CompatibilityChooseQte } from "../index.js";
6
+ import { CompatibilityScenarioChooseWithScenarioQte } from "../index.js";
7
7
  import { CHOOSE_EVENTS, createCompatibilityTestModule, QTE_EVENTS, QTE_LINE_KEYWORDS, QTE_PARAMS, registerCompatibilityVne } from "./setup.js";
8
8
 
9
9
  const OPTIONS: ChooseOption[] = [
@@ -13,28 +13,28 @@ const OPTIONS: ChooseOption[] = [
13
13
 
14
14
  const ITEM = { start: 50, size: 40, duration: 2500 };
15
15
 
16
- describe("CompatibilityChooseQte", () => {
16
+ describe("CompatibilityScenarioChooseWithScenarioQte", () => {
17
17
  beforeEach(() => {
18
18
  registerCompatibilityVne();
19
19
  Object.assign(QTE_PARAMS.ITEMS, { easy: ITEM });
20
20
  });
21
21
 
22
22
  it("init registers OPTION_REPLACE handler", async () => {
23
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte, { subscribe: false });
23
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte, { subscribe: false });
24
24
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
25
25
 
26
- await (module as CompatibilityChooseQte).init();
26
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
27
27
 
28
28
  expect(replaceReg).toHaveBeenCalledOnce();
29
29
  expect(replaceReg.mock.calls[0]?.[0]?.handler).toBeTypeOf("function");
30
30
  });
31
31
 
32
32
  it("returns same index when option has no qte", async () => {
33
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte, { subscribe: false });
33
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte, { subscribe: false });
34
34
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
35
35
  const emit = spyEvent(observer, QTE_EVENTS.EMIT);
36
36
 
37
- await (module as CompatibilityChooseQte).init();
37
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
38
38
 
39
39
  const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionReplaceHandler;
40
40
  const result = await handler({ index: 1, options: OPTIONS });
@@ -44,11 +44,11 @@ describe("CompatibilityChooseQte", () => {
44
44
  });
45
45
 
46
46
  it("success keeps selected index", async () => {
47
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte);
47
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte);
48
48
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
49
49
  const emit = spyEvent(observer, QTE_EVENTS.EMIT);
50
50
 
51
- await (module as CompatibilityChooseQte).init();
51
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
52
52
 
53
53
  const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionReplaceHandler;
54
54
  const pending = handler({ index: 0, options: OPTIONS });
@@ -62,10 +62,10 @@ describe("CompatibilityChooseQte", () => {
62
62
  });
63
63
 
64
64
  it("fail remaps to qte-fallback option", async () => {
65
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte);
65
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte);
66
66
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
67
67
 
68
- await (module as CompatibilityChooseQte).init();
68
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
69
69
 
70
70
  const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionReplaceHandler;
71
71
  const pending = handler({ index: 0, options: OPTIONS });
@@ -77,11 +77,11 @@ describe("CompatibilityChooseQte", () => {
77
77
  });
78
78
 
79
79
  it("fail without fallback keeps selected index", async () => {
80
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte);
80
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte);
81
81
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
82
82
  const options: ChooseOption[] = [{ index: 10, text: "With QTE", qte: "easy" }];
83
83
 
84
- await (module as CompatibilityChooseQte).init();
84
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
85
85
 
86
86
  const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionReplaceHandler;
87
87
  const pending = handler({ index: 0, options });
@@ -93,7 +93,7 @@ describe("CompatibilityChooseQte", () => {
93
93
  });
94
94
 
95
95
  it("missing item fails without opening QTE emit of item", async () => {
96
- const { module, observer } = createCompatibilityTestModule(CompatibilityChooseQte, { subscribe: false });
96
+ const { module, observer } = createCompatibilityTestModule(CompatibilityScenarioChooseWithScenarioQte, { subscribe: false });
97
97
  const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_REPLACE_REG);
98
98
  const emit = spyEvent(observer, QTE_EVENTS.EMIT);
99
99
  const options: ChooseOption[] = [
@@ -101,7 +101,7 @@ describe("CompatibilityChooseQte", () => {
101
101
  { index: 20, text: "Fallback", keywords: [QTE_LINE_KEYWORDS.QTE_FALLBACK] },
102
102
  ];
103
103
 
104
- await (module as CompatibilityChooseQte).init();
104
+ await (module as CompatibilityScenarioChooseWithScenarioQte).init();
105
105
 
106
106
  const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionReplaceHandler;
107
107
  const result = await handler({ index: 0, options });