@vnejs/plugins.views.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.js +3 -3
- package/dist/modules/controller.d.ts +4 -4
- package/dist/modules/controller.js +4 -4
- package/dist/modules/view.d.ts +4 -5
- package/dist/modules/view.js +4 -5
- package/dist/view/index.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/modules/controller.ts +4 -4
- package/src/modules/view.ts +6 -5
- package/src/tests/controller.test.ts +23 -23
- package/src/view/index.tsx +1 -8
package/dist/index.js
CHANGED
|
@@ -2,6 +2,6 @@ import "@vnejs/contracts.scenario.qte";
|
|
|
2
2
|
import "@vnejs/contracts.views.scenario.qte";
|
|
3
3
|
import { regPlugin } from "@vnejs/shared";
|
|
4
4
|
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.qte";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
5
|
+
import { QteViewController } from "./modules/controller.js";
|
|
6
|
+
import { QteViewView } from "./modules/view.js";
|
|
7
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewView]);
|
|
@@ -2,14 +2,14 @@ import { ModuleController } from "@vnejs/module.components";
|
|
|
2
2
|
import type { ViewActionPayload } from "@vnejs/module.components";
|
|
3
3
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
4
4
|
import type { QtePluginControllerState, QteVisibilityPayload } from "../utils/qte.js";
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
8
|
+
CONTROLS: {
|
|
9
9
|
abstract_accept: () => undefined;
|
|
10
10
|
abstract_interact: () => undefined;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
CONTROLS_INDEX: number;
|
|
13
13
|
activeStartedAt: number | null;
|
|
14
14
|
isResolved: boolean;
|
|
15
15
|
resultTimeout: ReturnType<typeof setTimeout> | null;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
import { getFailAtProgress, getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
3
|
-
export class
|
|
3
|
+
export class QteViewController extends ModuleController {
|
|
4
4
|
name = "qte_view.controller";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
6
|
+
CONTROLS = {
|
|
7
7
|
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.onAction(),
|
|
8
8
|
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.onAction(),
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
11
11
|
activeStartedAt = null;
|
|
12
12
|
isResolved = false;
|
|
13
13
|
resultTimeout = null;
|
package/dist/modules/view.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
3
3
|
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
5
5
|
name: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
9
|
renderFunc: import("@vnejs/module.components").ViewRenderFunc<QtePluginControllerState>;
|
|
10
|
-
updateHandler: (state?: QtePluginControllerState | undefined) => Promise<void>;
|
|
11
10
|
}
|
package/dist/modules/view.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
import { render } from "../view/index.js";
|
|
3
|
-
export class
|
|
3
|
+
export class QteViewView extends ModuleView {
|
|
4
4
|
name = "qte_view.view";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
6
|
+
LOC_LABEL = this.PARAMS.QTE_VIEW.LOC_LABEL;
|
|
7
|
+
TRANSITION = this.PARAMS.QTE_VIEW.TRANSITION;
|
|
8
8
|
renderFunc = render;
|
|
9
|
-
updateHandler = this.onUpdateStoreComponent;
|
|
10
9
|
}
|
package/dist/view/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const describeArc = (sectorStart, sectorWidth) => {
|
|
|
16
16
|
return ["M", start.x, start.y, "A", RADIUS, RADIUS, 0, largeArcFlag, 0, end.x, end.y].join(" ");
|
|
17
17
|
};
|
|
18
18
|
const Qte = ({ store, onMount, emit, EVENTS, PARAMS }) => {
|
|
19
|
-
const { isShow = false, isForce = false, phase = "", result = "", item = null, locs = {}
|
|
19
|
+
const { isShow = false, isForce = false, phase = "", result = "", item = null, locs = {} } = useStoreState(store, onMount);
|
|
20
20
|
const isRealForce = useIsForceHook(isForce);
|
|
21
21
|
const propsView = PARAMS.QTE_VIEW.VIEW_PROPS;
|
|
22
22
|
const transition = isRealForce ? 0 : PARAMS.QTE_VIEW.TRANSITION;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import "@vnejs/contracts.views.scenario.qte";
|
|
|
4
4
|
import { regPlugin } from "@vnejs/shared";
|
|
5
5
|
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.scenario.qte";
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { QteViewController } from "./modules/controller.js";
|
|
8
|
+
import { QteViewView } from "./modules/view.js";
|
|
9
9
|
|
|
10
|
-
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
10
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewView]);
|
|
@@ -6,16 +6,16 @@ import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSet
|
|
|
6
6
|
import type { QtePluginControllerState, QteVisibilityPayload } from "../utils/qte.js";
|
|
7
7
|
import { getFailAtProgress, getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
8
8
|
|
|
9
|
-
export class
|
|
9
|
+
export class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
10
10
|
name = "qte_view.controller";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
CONTROLS = {
|
|
15
15
|
[this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.onAction(),
|
|
16
16
|
[this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.onAction(),
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
19
19
|
|
|
20
20
|
activeStartedAt: number | null = null;
|
|
21
21
|
isResolved = false;
|
package/src/modules/view.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { render } from "../view/index.js";
|
|
|
4
4
|
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
5
5
|
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
6
6
|
|
|
7
|
-
export class
|
|
7
|
+
export class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
8
8
|
name = "qte_view.view";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
11
|
+
|
|
12
|
+
LOC_LABEL = this.PARAMS.QTE_VIEW.LOC_LABEL;
|
|
13
|
+
|
|
14
|
+
TRANSITION = this.PARAMS.QTE_VIEW.TRANSITION;
|
|
13
15
|
|
|
14
16
|
renderFunc = render;
|
|
15
|
-
updateHandler = this.onUpdateStoreComponent;
|
|
16
17
|
}
|
|
@@ -2,17 +2,17 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import { spyEvent } from "@vnejs/test-utils";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { QteViewController } from "../modules/controller.js";
|
|
6
6
|
import { createQteViewTestModule, registerQteViewPluginVne, QTE_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
7
7
|
|
|
8
|
-
describe("
|
|
8
|
+
describe("QteViewController", () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
registerQteViewPluginVne();
|
|
11
11
|
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "performance"] });
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("OPENED bridge emits SHOW with payload", async () => {
|
|
15
|
-
const { observer } = createQteViewTestModule(
|
|
15
|
+
const { observer } = createQteViewTestModule(QteViewController);
|
|
16
16
|
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
17
17
|
const payload = { id: "door_lock", item: { start: 70, size: 20, duration: 1500 } };
|
|
18
18
|
|
|
@@ -22,66 +22,66 @@ describe("QteController", () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it("SHOW starts in initial, then intro, then active", async () => {
|
|
25
|
-
const { module, observer } = createQteViewTestModule(
|
|
25
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
26
26
|
const item = { start: 70, size: 20, duration: 1500 };
|
|
27
|
-
const { INITIAL, TRANSITION } = (module as
|
|
27
|
+
const { INITIAL, TRANSITION } = (module as QteViewController).PARAMS.QTE_VIEW;
|
|
28
28
|
|
|
29
29
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
30
30
|
|
|
31
|
-
expect((module as
|
|
32
|
-
expect((module as
|
|
33
|
-
expect((module as
|
|
31
|
+
expect((module as QteViewController).state.id).toBe("door_lock");
|
|
32
|
+
expect((module as QteViewController).state.item).toEqual(item);
|
|
33
|
+
expect((module as QteViewController).state.phase).toBe("initial");
|
|
34
34
|
|
|
35
35
|
await vi.advanceTimersByTimeAsync(INITIAL);
|
|
36
|
-
expect((module as
|
|
36
|
+
expect((module as QteViewController).state.phase).toBe("intro");
|
|
37
37
|
|
|
38
38
|
await vi.advanceTimersByTimeAsync(TRANSITION - INITIAL);
|
|
39
|
-
expect((module as
|
|
40
|
-
expect((module as
|
|
39
|
+
expect((module as QteViewController).state.phase).toBe("active");
|
|
40
|
+
expect((module as QteViewController).activeStartedAt).not.toBeNull();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it("ACTION resolves success inside zone by elapsed time", async () => {
|
|
44
|
-
const { module, observer } = createQteViewTestModule(
|
|
44
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
45
45
|
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
46
46
|
const item = { start: 40, size: 20, duration: 1000 };
|
|
47
47
|
|
|
48
48
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
49
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
49
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
50
50
|
await vi.advanceTimersByTimeAsync(500);
|
|
51
51
|
|
|
52
52
|
await observer.emit(SUBSCRIBE_EVENTS.ACTION);
|
|
53
53
|
|
|
54
|
-
expect((module as
|
|
54
|
+
expect((module as QteViewController).state.result).toBe("success");
|
|
55
55
|
|
|
56
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
56
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
57
57
|
|
|
58
58
|
expect(result).toHaveBeenCalledExactlyOnceWith({ success: true });
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("ACTION resolves fail outside zone", async () => {
|
|
62
|
-
const { module, observer } = createQteViewTestModule(
|
|
62
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
63
63
|
const item = { start: 70, size: 20, duration: 1000 };
|
|
64
64
|
|
|
65
65
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
66
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
66
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
67
67
|
await vi.advanceTimersByTimeAsync(100);
|
|
68
68
|
|
|
69
|
-
(module as
|
|
69
|
+
(module as QteViewController).CONTROLS[(module as QteViewController).CONST.CONTROLS.BUTTONS.ACCEPT]();
|
|
70
70
|
|
|
71
|
-
expect((module as
|
|
71
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
it("auto-fails when pointer leaves the zone", async () => {
|
|
75
|
-
const { module, observer } = createQteViewTestModule(
|
|
75
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
76
76
|
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
77
77
|
const item = { start: 50, size: 10, duration: 1000 };
|
|
78
78
|
|
|
79
79
|
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
80
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
80
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
81
81
|
await vi.advanceTimersByTimeAsync(600);
|
|
82
|
-
await vi.advanceTimersByTimeAsync((module as
|
|
82
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
83
83
|
|
|
84
|
-
expect((module as
|
|
84
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
85
85
|
expect(result).toHaveBeenCalledExactlyOnceWith({ success: false });
|
|
86
86
|
});
|
|
87
87
|
});
|
package/src/view/index.tsx
CHANGED
|
@@ -28,14 +28,7 @@ const describeArc = (sectorStart: number, sectorWidth: number) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const Qte = ({ store, onMount, emit, EVENTS, PARAMS }: QteComponentProps) => {
|
|
31
|
-
const {
|
|
32
|
-
isShow = false,
|
|
33
|
-
isForce = false,
|
|
34
|
-
phase = "",
|
|
35
|
-
result = "",
|
|
36
|
-
item = null,
|
|
37
|
-
locs = {},
|
|
38
|
-
} = useStoreState<QtePluginControllerState>(store, onMount);
|
|
31
|
+
const { isShow = false, isForce = false, phase = "", result = "", item = null, locs = {} } = useStoreState<QtePluginControllerState>(store, onMount);
|
|
39
32
|
|
|
40
33
|
const isRealForce = useIsForceHook(isForce);
|
|
41
34
|
const propsView = PARAMS.QTE_VIEW.VIEW_PROPS;
|