@vnejs/plugins.controllers.scenario.qte 0.0.0-stage → 0.2.16
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 +2 -0
- package/dist/index.js +8 -0
- package/dist/modules/controller.accept.d.ts +10 -0
- package/dist/modules/controller.accept.js +9 -0
- package/dist/modules/controller.d.ts +34 -0
- package/dist/modules/controller.js +111 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.js +1 -0
- package/dist/utils/qte.d.ts +15 -0
- package/dist/utils/qte.js +10 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +54 -0
- package/dist/view/index.styles.d.ts +2 -0
- package/dist/view/index.styles.js +137 -0
- package/package.json +58 -4
- package/src/index.ts +12 -0
- package/src/modules/controller.accept.ts +15 -0
- package/src/modules/controller.ts +134 -0
- package/src/modules/view.ts +19 -0
- package/src/tests/accept.test.ts +54 -0
- package/src/tests/controller.test.ts +89 -0
- package/src/tests/qte.test.ts +22 -0
- package/src/tests/setup.ts +37 -0
- package/src/types.ts +19 -0
- package/src/utils/qte.ts +29 -0
- package/src/view/index.styles.ts +141 -0
- package/src/view/index.tsx +131 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@vnejs/contracts.scenario.qte";
|
|
2
|
+
import "@vnejs/contracts.controllers.scenario.qte";
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.qte";
|
|
5
|
+
import { QteViewControllerAccept } from "./modules/controller.accept.js";
|
|
6
|
+
import { QteViewController } from "./modules/controller.js";
|
|
7
|
+
import { QteViewView } from "./modules/view.js";
|
|
8
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewControllerAccept, QteViewView]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
3
|
+
export declare class QteViewControllerAccept extends ModuleControllerAccept<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_SHOW: "vne:qte_view:show";
|
|
6
|
+
EVENT_HIDE: "vne:qte_view:hide";
|
|
7
|
+
EVENT_ACCEPT: "vne:qte_view:action";
|
|
8
|
+
CONTROLS_ZINDEX: number;
|
|
9
|
+
onAccept: () => undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
export class QteViewControllerAccept extends ModuleControllerAccept {
|
|
3
|
+
name = "qte_view.controller.accept";
|
|
4
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
5
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
6
|
+
EVENT_ACCEPT = this.EVENTS.QTE_VIEW.ACTION;
|
|
7
|
+
CONTROLS_ZINDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
8
|
+
onAccept = () => undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { ViewActionPayload } from "@vnejs/module.components";
|
|
3
|
+
import type { QteVisibilityPayload } from "@vnejs/contracts.controllers.scenario.qte";
|
|
4
|
+
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
5
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
6
|
+
export declare class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
7
|
+
name: string;
|
|
8
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
9
|
+
EVENT_UPDATE_STATE: "vne:qte_view:update_state";
|
|
10
|
+
EVENT_UPDATE_FAST: "vne:qte_view:update_fast";
|
|
11
|
+
EVENT_UPDATE_FORCE: "vne:qte_view:update_force";
|
|
12
|
+
EVENT_SHOW: "vne:qte_view:show";
|
|
13
|
+
EVENT_HIDE: "vne:qte_view:hide";
|
|
14
|
+
CONTROLS: {};
|
|
15
|
+
CONTROLS_INDEX: number;
|
|
16
|
+
activeStartedAt: number | null;
|
|
17
|
+
isResolved: boolean;
|
|
18
|
+
resultTimeout: ReturnType<typeof setTimeout> | null;
|
|
19
|
+
phaseTimeout: ReturnType<typeof setTimeout> | null;
|
|
20
|
+
failTimeout: ReturnType<typeof setTimeout> | null;
|
|
21
|
+
subscribe: () => void;
|
|
22
|
+
onAction: () => void;
|
|
23
|
+
onQteOpened: (payload?: QteVisibilityPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:qte_view:show">> | undefined;
|
|
24
|
+
onQteClosed: (payload?: QteVisibilityPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:qte_view:hide">> | undefined;
|
|
25
|
+
getDefaultState: () => QtePluginControllerState;
|
|
26
|
+
onShowBefore: ({ id, item }?: ViewActionPayload) => Promise<void>;
|
|
27
|
+
schedulePhases: () => void;
|
|
28
|
+
startActive: () => void;
|
|
29
|
+
scheduleFailTimeout: () => void;
|
|
30
|
+
onHideAfter: () => void;
|
|
31
|
+
resolveRound: (success: boolean) => void;
|
|
32
|
+
clearFailTimeout: () => void;
|
|
33
|
+
clearTimers: () => void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import { getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
3
|
+
export class QteViewController extends ModuleController {
|
|
4
|
+
name = "qte_view.controller";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
6
|
+
EVENT_UPDATE_STATE = this.EVENTS.QTE_VIEW.UPDATE_STATE;
|
|
7
|
+
EVENT_UPDATE_FAST = this.EVENTS.QTE_VIEW.UPDATE_FAST;
|
|
8
|
+
EVENT_UPDATE_FORCE = this.EVENTS.QTE_VIEW.UPDATE_FORCE;
|
|
9
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
10
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
11
|
+
CONTROLS = {};
|
|
12
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
13
|
+
activeStartedAt = null;
|
|
14
|
+
isResolved = false;
|
|
15
|
+
resultTimeout = null;
|
|
16
|
+
phaseTimeout = null;
|
|
17
|
+
failTimeout = null;
|
|
18
|
+
subscribe = () => {
|
|
19
|
+
super.subscribe();
|
|
20
|
+
this.on(this.EVENTS.QTE_VIEW.ACTION, this.onAction);
|
|
21
|
+
this.on(this.EVENTS.QTE.OPENED, this.onQteOpened);
|
|
22
|
+
this.on(this.EVENTS.QTE.CLOSED, this.onQteClosed);
|
|
23
|
+
};
|
|
24
|
+
onAction = () => {
|
|
25
|
+
if (this.state.phase !== "active" || this.isResolved || !this.state.item || this.activeStartedAt === null)
|
|
26
|
+
return;
|
|
27
|
+
const { start, size, duration } = this.state.item;
|
|
28
|
+
const progress = getProgressFromElapsed(performance.now() - this.activeStartedAt, duration);
|
|
29
|
+
const success = isProgressInsideZone(progress, start, size);
|
|
30
|
+
this.resolveRound(success);
|
|
31
|
+
};
|
|
32
|
+
onQteOpened = (payload = {}) => this.emit(this.EVENTS.QTE_VIEW.SHOW, payload);
|
|
33
|
+
onQteClosed = (payload = {}) => this.emit(this.EVENTS.QTE_VIEW.HIDE, payload);
|
|
34
|
+
getDefaultState = () => ({
|
|
35
|
+
isShow: false,
|
|
36
|
+
isForce: false,
|
|
37
|
+
id: "",
|
|
38
|
+
item: null,
|
|
39
|
+
phase: "idle",
|
|
40
|
+
result: "idle",
|
|
41
|
+
pointerProgress: 0,
|
|
42
|
+
});
|
|
43
|
+
onShowBefore = async ({ id = "", item = null } = {}) => {
|
|
44
|
+
this.clearTimers();
|
|
45
|
+
this.isResolved = false;
|
|
46
|
+
this.activeStartedAt = null;
|
|
47
|
+
this.updateState({
|
|
48
|
+
id: String(id),
|
|
49
|
+
item: item ?? null,
|
|
50
|
+
phase: "initial",
|
|
51
|
+
result: "idle",
|
|
52
|
+
pointerProgress: 0,
|
|
53
|
+
});
|
|
54
|
+
this.schedulePhases();
|
|
55
|
+
};
|
|
56
|
+
schedulePhases = () => {
|
|
57
|
+
const { TRANSITION } = this.PARAMS.QTE_VIEW;
|
|
58
|
+
this.phaseTimeout = setTimeout(() => {
|
|
59
|
+
if (this.isResolved)
|
|
60
|
+
return;
|
|
61
|
+
this.startActive();
|
|
62
|
+
}, TRANSITION);
|
|
63
|
+
};
|
|
64
|
+
startActive = () => {
|
|
65
|
+
if (!this.state.item)
|
|
66
|
+
return;
|
|
67
|
+
this.activeStartedAt = performance.now();
|
|
68
|
+
this.updateStateAndViewFast({ phase: "active" });
|
|
69
|
+
this.scheduleFailTimeout();
|
|
70
|
+
};
|
|
71
|
+
scheduleFailTimeout = () => {
|
|
72
|
+
if (!this.state.item)
|
|
73
|
+
return;
|
|
74
|
+
const { duration } = this.state.item;
|
|
75
|
+
this.failTimeout = setTimeout(() => this.resolveRound(false), Math.max(duration, 1));
|
|
76
|
+
};
|
|
77
|
+
onHideAfter = () => {
|
|
78
|
+
this.clearTimers();
|
|
79
|
+
};
|
|
80
|
+
resolveRound = (success) => {
|
|
81
|
+
if (this.isResolved)
|
|
82
|
+
return;
|
|
83
|
+
this.isResolved = true;
|
|
84
|
+
this.clearFailTimeout();
|
|
85
|
+
const duration = this.state.item?.duration ?? 0;
|
|
86
|
+
const pointerProgress = this.activeStartedAt === null ? 0 : getProgressFromElapsed(performance.now() - this.activeStartedAt, duration);
|
|
87
|
+
this.updateStateAndViewFast({
|
|
88
|
+
phase: "resolved",
|
|
89
|
+
result: success ? "success" : "fail",
|
|
90
|
+
pointerProgress,
|
|
91
|
+
});
|
|
92
|
+
this.resultTimeout = setTimeout(() => {
|
|
93
|
+
void this.emit(this.EVENTS.QTE.RESULT, { success });
|
|
94
|
+
}, this.PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
95
|
+
};
|
|
96
|
+
clearFailTimeout = () => {
|
|
97
|
+
if (this.failTimeout)
|
|
98
|
+
clearTimeout(this.failTimeout);
|
|
99
|
+
this.failTimeout = null;
|
|
100
|
+
};
|
|
101
|
+
clearTimers = () => {
|
|
102
|
+
this.clearFailTimeout();
|
|
103
|
+
if (this.phaseTimeout)
|
|
104
|
+
clearTimeout(this.phaseTimeout);
|
|
105
|
+
if (this.resultTimeout)
|
|
106
|
+
clearTimeout(this.resultTimeout);
|
|
107
|
+
this.phaseTimeout = null;
|
|
108
|
+
this.resultTimeout = null;
|
|
109
|
+
this.activeStartedAt = null;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
3
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
4
|
+
export declare class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:qte_view:update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<QtePluginControllerState>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class QteViewView extends ModuleView {
|
|
4
|
+
name = "qte_view.view";
|
|
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
|
+
renderFunc = render;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { PluginName, SubscribeEvents, Params } from "@vnejs/contracts.controllers.scenario.qte";
|
|
3
|
+
import type { PluginName as ControlsPluginName, Constants as ControlsConstants } from "@vnejs/contracts.controls";
|
|
4
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
|
|
5
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/contracts.core.vendors";
|
|
6
|
+
import type { PluginName as QtePluginName, SubscribeEvents as QteSubscribeEvents, Params as QteParams } from "@vnejs/contracts.scenario.qte";
|
|
7
|
+
export type QtePluginEvents = ModuleComponentsEvents & Record<QtePluginName, QteSubscribeEvents> & Record<PluginName, SubscribeEvents> & Record<VendorsPluginName, VendorsSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents>;
|
|
8
|
+
export type QtePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
9
|
+
export type QtePluginSettings = ModuleComponentsSettings;
|
|
10
|
+
export type QtePluginParams = ModuleComponentsParams & Record<QtePluginName, QteParams> & Record<PluginName, Params>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ModuleControllerState } from "@vnejs/module.components";
|
|
2
|
+
import type { QteItem } from "@vnejs/contracts.controllers.scenario.qte";
|
|
3
|
+
export type QtePhase = "idle" | "initial" | "active" | "resolved";
|
|
4
|
+
export type QteResult = "idle" | "success" | "fail";
|
|
5
|
+
export type QtePluginControllerState = ModuleControllerState & {
|
|
6
|
+
id: string;
|
|
7
|
+
item: QteItem | null;
|
|
8
|
+
phase: QtePhase;
|
|
9
|
+
result: QteResult;
|
|
10
|
+
pointerProgress: number;
|
|
11
|
+
locs?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export declare const getProgressFromElapsed: (elapsedMs: number, duration: number) => number;
|
|
14
|
+
export declare const isProgressInsideZone: (progress: number, start: number, size: number) => boolean;
|
|
15
|
+
export declare const getFailAtProgress: () => number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const getProgressFromElapsed = (elapsedMs, duration) => {
|
|
2
|
+
if (duration <= 0)
|
|
3
|
+
return 100;
|
|
4
|
+
return Math.min(Math.max((elapsedMs / duration) * 100, 0), 100);
|
|
5
|
+
};
|
|
6
|
+
export const isProgressInsideZone = (progress, start, size) => {
|
|
7
|
+
const zoneEnd = Math.min(start + size, 100);
|
|
8
|
+
return progress >= start && progress <= zoneEnd;
|
|
9
|
+
};
|
|
10
|
+
export const getFailAtProgress = () => 100;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PositionBox, Screen, createRenderFunc, useEffect, useIsForceHook, useState, useStoreState } from "@vnejs/uis.react";
|
|
3
|
+
import { POINTER_RETREAT_SPEED_FACTOR, b } from "./index.styles.js";
|
|
4
|
+
const Qte = ({ store, onMount, emit, EVENTS, PARAMS }) => {
|
|
5
|
+
const { isShow = false, isForce = false, phase = "", result = "", item = null, locs = {}, pointerProgress = 0, } = useStoreState(store, onMount);
|
|
6
|
+
const isRealForce = useIsForceHook(isForce);
|
|
7
|
+
const propsView = PARAMS.QTE_VIEW.VIEW_PROPS;
|
|
8
|
+
const transition = isRealForce ? 0 : PARAMS.QTE_VIEW.TRANSITION;
|
|
9
|
+
const duration = item?.duration ?? 0;
|
|
10
|
+
const start = item?.start ?? 0;
|
|
11
|
+
const size = item?.size ?? 0;
|
|
12
|
+
const sectorWidth = Math.min(size, Math.max(100 - start, 0));
|
|
13
|
+
const isPointerRetreat = phase === "resolved" && result === "fail";
|
|
14
|
+
const isFailResult = isPointerRetreat;
|
|
15
|
+
const isPointerMoving = phase === "active" || (phase === "resolved" && result === "success");
|
|
16
|
+
const isPointerSuccess = result === "success";
|
|
17
|
+
const resultDelayMs = isRealForce ? 0 : PARAMS.QTE_VIEW.RESULT_DELAY;
|
|
18
|
+
const [isRetreatActive, setRetreatActive] = useState(false);
|
|
19
|
+
const [isFailFadeActive, setFailFadeActive] = useState(false);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!isPointerRetreat) {
|
|
22
|
+
setRetreatActive(false);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const frame = requestAnimationFrame(() => setRetreatActive(true));
|
|
26
|
+
return () => cancelAnimationFrame(frame);
|
|
27
|
+
}, [isPointerRetreat, pointerProgress]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!isFailResult) {
|
|
30
|
+
setFailFadeActive(false);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const frame = requestAnimationFrame(() => setFailFadeActive(true));
|
|
34
|
+
return () => cancelAnimationFrame(frame);
|
|
35
|
+
}, [isFailResult]);
|
|
36
|
+
const sectorStyle = { left: `${start}%`, width: `${sectorWidth}%` };
|
|
37
|
+
const retreatDurationMs = (pointerProgress / 100) * duration * POINTER_RETREAT_SPEED_FACTOR;
|
|
38
|
+
const pointerMoveStyle = {
|
|
39
|
+
["--qte-duration"]: `${duration}ms`,
|
|
40
|
+
["--qte-pointer-progress"]: String(pointerProgress),
|
|
41
|
+
["--qte-retreat-duration"]: `${retreatDurationMs}ms`,
|
|
42
|
+
["--qte-result-delay"]: `${resultDelayMs}ms`,
|
|
43
|
+
};
|
|
44
|
+
return (_jsx(Screen, { ...propsView.screen, isDisableAutoread: true, isIgnoreOnScreenshot: true, isShow: isShow, isForce: isRealForce, transition: transition, children: _jsx(PositionBox, { ...propsView.position, children: _jsx("div", { className: b("shell", { phase }), children: _jsxs("div", { className: b("block"), children: [_jsxs("div", { className: b("status"), "aria-live": "polite", children: [_jsx("span", { className: b("statusLine", { shown: result === "success" }), children: locs.success ?? "" }), _jsx("span", { className: b("statusLine", { shown: result === "fail" }), children: locs.fail ?? "" })] }), _jsxs("div", { className: b("rail"), onClick: () => void emit(EVENTS.QTE_VIEW.ACTION), "vne-cursor-type": "pointer", "vne-cursor-target-possible": "", children: [_jsx("div", { className: b("track") }), _jsx("div", { className: b("sector"), style: sectorStyle }), _jsx("div", { className: b("pointerMove", {
|
|
45
|
+
moving: isPointerMoving,
|
|
46
|
+
retreat: isPointerRetreat,
|
|
47
|
+
retreatActive: isPointerRetreat && isRetreatActive,
|
|
48
|
+
}), style: pointerMoveStyle, children: _jsx("div", { className: b("pointer", {
|
|
49
|
+
success: isPointerSuccess,
|
|
50
|
+
failFade: isFailResult,
|
|
51
|
+
failFadeActive: isFailResult && isFailFadeActive,
|
|
52
|
+
}) }) })] })] }) }) }) }));
|
|
53
|
+
};
|
|
54
|
+
export const render = createRenderFunc(Qte);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { cn, getVneLength, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
export const b = cn("Qte");
|
|
3
|
+
const RAIL_WIDTH = 3840;
|
|
4
|
+
const RAIL_HEIGHT = 36;
|
|
5
|
+
const POINTER_SIZE = 96;
|
|
6
|
+
/** Доля времени анимации до 100% ширины; остальное — выезд маркера за край (110%). */
|
|
7
|
+
const POINTER_ACTIVE_KEYFRAME_PERCENT = (100 / 110) * 100;
|
|
8
|
+
const POINTER_ANIMATION_DURATION_FACTOR = 1.1;
|
|
9
|
+
export const POINTER_RETREAT_SPEED_FACTOR = 2;
|
|
10
|
+
const POINTER_GLOW_TRANSITION_MS = 400;
|
|
11
|
+
const CSS = `
|
|
12
|
+
@keyframes qte-pointer-move {
|
|
13
|
+
0% {
|
|
14
|
+
left: 0%;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
${POINTER_ACTIVE_KEYFRAME_PERCENT}% {
|
|
18
|
+
left: 100%;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
100% {
|
|
22
|
+
left: 110%;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
${sel(b("shell", { phase: "initial" }))},
|
|
27
|
+
${sel(b("shell", { phase: "resolved" }))} {
|
|
28
|
+
pointer-events: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
${sel(b("block"))} {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
align-items: center;
|
|
35
|
+
width: ${getVneLength(RAIL_WIDTH)};
|
|
36
|
+
gap: ${getVneLength(48)};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
${sel(b("status"))} {
|
|
40
|
+
display: grid;
|
|
41
|
+
place-items: center;
|
|
42
|
+
width: ${getVneLength(528)};
|
|
43
|
+
text-align: center;
|
|
44
|
+
pointer-events: none;
|
|
45
|
+
color: #ffffff;
|
|
46
|
+
font-size: ${getVneLength(72)};
|
|
47
|
+
font-weight: 900;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
${sel(b("statusLine"))} {
|
|
51
|
+
grid-area: 1 / 1;
|
|
52
|
+
opacity: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
${sel(b("statusLine", { shown: true }))} {
|
|
56
|
+
opacity: 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
${sel(b("rail"))} {
|
|
60
|
+
position: relative;
|
|
61
|
+
width: ${getVneLength(RAIL_WIDTH)};
|
|
62
|
+
height: ${getVneLength(RAIL_HEIGHT)};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
${sel(b("track"))} {
|
|
66
|
+
position: absolute;
|
|
67
|
+
inset: 0;
|
|
68
|
+
background: var(--vne-color-disabled, rgba(255, 255, 255, 30%));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
${sel(b("sector"))} {
|
|
72
|
+
position: absolute;
|
|
73
|
+
top: 0;
|
|
74
|
+
bottom: 0;
|
|
75
|
+
border-radius: ${getVneLength(18)};
|
|
76
|
+
background: var(--vne-color-main, rgba(255, 255, 255, 100%));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
${sel(b("pointerMove"))} {
|
|
80
|
+
position: absolute;
|
|
81
|
+
top: 50%;
|
|
82
|
+
left: 0;
|
|
83
|
+
pointer-events: none;
|
|
84
|
+
transform: translate(-50%, -50%);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
${sel(b("pointerMove", { moving: true }))} {
|
|
88
|
+
animation-name: qte-pointer-move;
|
|
89
|
+
animation-duration: calc(var(--qte-duration, 1800ms) * ${POINTER_ANIMATION_DURATION_FACTOR});
|
|
90
|
+
animation-timing-function: linear;
|
|
91
|
+
animation-fill-mode: forwards;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
${sel(b("pointerMove", { retreat: true }))} {
|
|
95
|
+
animation: none;
|
|
96
|
+
left: calc(var(--qte-pointer-progress, 0) * 1%);
|
|
97
|
+
transition-property: left;
|
|
98
|
+
transition-timing-function: linear;
|
|
99
|
+
transition-duration: var(--qte-retreat-duration, 0ms);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
${sel(b("pointerMove", { retreat: true, retreatActive: true }))} {
|
|
103
|
+
left: 0%;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
${sel(b("pointer"))} {
|
|
107
|
+
width: ${getVneLength(POINTER_SIZE)};
|
|
108
|
+
height: ${getVneLength(POINTER_SIZE)};
|
|
109
|
+
border-radius: 50%;
|
|
110
|
+
opacity: 1;
|
|
111
|
+
background: #ffffff;
|
|
112
|
+
filter: drop-shadow(0 0 ${getVneLength(12)} rgba(0, 0, 0, 0.3));
|
|
113
|
+
box-shadow: 0 0 0 0 transparent;
|
|
114
|
+
transition:
|
|
115
|
+
box-shadow ${POINTER_GLOW_TRANSITION_MS}ms ease,
|
|
116
|
+
filter ${POINTER_GLOW_TRANSITION_MS}ms ease;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
${sel(b("pointer", { failFade: true }))} {
|
|
120
|
+
opacity: 1;
|
|
121
|
+
transition:
|
|
122
|
+
opacity var(--qte-result-delay, 500ms) linear,
|
|
123
|
+
box-shadow ${POINTER_GLOW_TRANSITION_MS}ms ease,
|
|
124
|
+
filter ${POINTER_GLOW_TRANSITION_MS}ms ease;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
${sel(b("pointer", { failFade: true, failFadeActive: true }))} {
|
|
128
|
+
opacity: 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
${sel(b("pointer", { success: true }))} {
|
|
132
|
+
box-shadow:
|
|
133
|
+
0 0 ${getVneLength(28)} var(--vne-color-main, rgba(255, 255, 255, 100%)),
|
|
134
|
+
0 0 ${getVneLength(56)} var(--vne-color-main, rgba(255, 255, 255, 100%));
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
injectStyles(CSS);
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.scenario.qte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.16",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/contracts.scenario.qte": "~0.2.0",
|
|
34
|
+
"@vnejs/contracts.controllers.scenario.qte": "~0.2.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.core": "~0.2.0",
|
|
40
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
41
|
+
"@vnejs/registry": "~0.2.0",
|
|
42
|
+
"@vnejs/uis.react": "~0.2.0",
|
|
43
|
+
"@vnejs/uis.utils": "~0.2.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
47
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
48
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
49
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
50
|
+
"@vnejs/contracts.scenario.qte": "~0.2.0",
|
|
51
|
+
"@vnejs/contracts.controllers.scenario.qte": "~0.2.0",
|
|
52
|
+
"@vnejs/module.components": "~0.2.0",
|
|
53
|
+
"@vnejs/module.core": "~0.2.0",
|
|
54
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
55
|
+
"@vnejs/registry": "~0.2.0",
|
|
56
|
+
"@vnejs/sources-set": "~0.2.0",
|
|
57
|
+
"@vnejs/uis.react": "~0.2.0",
|
|
58
|
+
"@vnejs/uis.utils": "~0.2.0"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "@vnejs/contracts.scenario.qte";
|
|
2
|
+
import "@vnejs/contracts.controllers.scenario.qte";
|
|
3
|
+
|
|
4
|
+
import { regPlugin } from "@vnejs/registry";
|
|
5
|
+
|
|
6
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.scenario.qte";
|
|
7
|
+
|
|
8
|
+
import { QteViewControllerAccept } from "./modules/controller.accept.js";
|
|
9
|
+
import { QteViewController } from "./modules/controller.js";
|
|
10
|
+
import { QteViewView } from "./modules/view.js";
|
|
11
|
+
|
|
12
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [QteViewController, QteViewControllerAccept, QteViewView]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class QteViewControllerAccept extends ModuleControllerAccept<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams> {
|
|
6
|
+
name = "qte_view.controller.accept";
|
|
7
|
+
|
|
8
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
9
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
10
|
+
EVENT_ACCEPT = this.EVENTS.QTE_VIEW.ACTION;
|
|
11
|
+
|
|
12
|
+
CONTROLS_ZINDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
13
|
+
|
|
14
|
+
onAccept = () => undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { ViewActionPayload } from "@vnejs/module.components";
|
|
4
|
+
|
|
5
|
+
import type { QteVisibilityPayload } from "@vnejs/contracts.controllers.scenario.qte";
|
|
6
|
+
|
|
7
|
+
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
8
|
+
import { getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
9
|
+
|
|
10
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
11
|
+
|
|
12
|
+
export class QteViewController extends ModuleController<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
13
|
+
name = "qte_view.controller";
|
|
14
|
+
|
|
15
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
16
|
+
EVENT_UPDATE_STATE = this.EVENTS.QTE_VIEW.UPDATE_STATE;
|
|
17
|
+
EVENT_UPDATE_FAST = this.EVENTS.QTE_VIEW.UPDATE_FAST;
|
|
18
|
+
EVENT_UPDATE_FORCE = this.EVENTS.QTE_VIEW.UPDATE_FORCE;
|
|
19
|
+
EVENT_SHOW = this.EVENTS.QTE_VIEW.SHOW;
|
|
20
|
+
EVENT_HIDE = this.EVENTS.QTE_VIEW.HIDE;
|
|
21
|
+
|
|
22
|
+
CONTROLS = {};
|
|
23
|
+
CONTROLS_INDEX = this.PARAMS.QTE_VIEW.ZINDEX;
|
|
24
|
+
|
|
25
|
+
activeStartedAt: number | null = null;
|
|
26
|
+
isResolved = false;
|
|
27
|
+
resultTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
28
|
+
phaseTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
29
|
+
failTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
30
|
+
|
|
31
|
+
subscribe = () => {
|
|
32
|
+
super.subscribe();
|
|
33
|
+
|
|
34
|
+
this.on(this.EVENTS.QTE_VIEW.ACTION, this.onAction);
|
|
35
|
+
|
|
36
|
+
this.on(this.EVENTS.QTE.OPENED, this.onQteOpened);
|
|
37
|
+
this.on(this.EVENTS.QTE.CLOSED, this.onQteClosed);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
onAction = () => {
|
|
41
|
+
if (this.state.phase !== "active" || this.isResolved || !this.state.item || this.activeStartedAt === null) return;
|
|
42
|
+
|
|
43
|
+
const { start, size, duration } = this.state.item;
|
|
44
|
+
const progress = getProgressFromElapsed(performance.now() - this.activeStartedAt, duration);
|
|
45
|
+
const success = isProgressInsideZone(progress, start, size);
|
|
46
|
+
|
|
47
|
+
this.resolveRound(success);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
onQteOpened = (payload: QteVisibilityPayload = {}) => this.emit(this.EVENTS.QTE_VIEW.SHOW, payload);
|
|
51
|
+
|
|
52
|
+
onQteClosed = (payload: QteVisibilityPayload = {}) => this.emit(this.EVENTS.QTE_VIEW.HIDE, payload);
|
|
53
|
+
|
|
54
|
+
getDefaultState = (): QtePluginControllerState => ({
|
|
55
|
+
isShow: false,
|
|
56
|
+
isForce: false,
|
|
57
|
+
id: "",
|
|
58
|
+
item: null,
|
|
59
|
+
phase: "idle",
|
|
60
|
+
result: "idle",
|
|
61
|
+
pointerProgress: 0,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
onShowBefore = async ({ id = "", item = null }: ViewActionPayload = {}) => {
|
|
65
|
+
this.clearTimers();
|
|
66
|
+
this.isResolved = false;
|
|
67
|
+
this.activeStartedAt = null;
|
|
68
|
+
this.updateState({
|
|
69
|
+
id: String(id),
|
|
70
|
+
item: (item as QtePluginControllerState["item"]) ?? null,
|
|
71
|
+
phase: "initial",
|
|
72
|
+
result: "idle",
|
|
73
|
+
pointerProgress: 0,
|
|
74
|
+
});
|
|
75
|
+
this.schedulePhases();
|
|
76
|
+
};
|
|
77
|
+
schedulePhases = () => {
|
|
78
|
+
const { TRANSITION } = this.PARAMS.QTE_VIEW;
|
|
79
|
+
|
|
80
|
+
this.phaseTimeout = setTimeout(() => {
|
|
81
|
+
if (this.isResolved) return;
|
|
82
|
+
|
|
83
|
+
this.startActive();
|
|
84
|
+
}, TRANSITION);
|
|
85
|
+
};
|
|
86
|
+
startActive = () => {
|
|
87
|
+
if (!this.state.item) return;
|
|
88
|
+
|
|
89
|
+
this.activeStartedAt = performance.now();
|
|
90
|
+
this.updateStateAndViewFast({ phase: "active" });
|
|
91
|
+
this.scheduleFailTimeout();
|
|
92
|
+
};
|
|
93
|
+
scheduleFailTimeout = () => {
|
|
94
|
+
if (!this.state.item) return;
|
|
95
|
+
|
|
96
|
+
const { duration } = this.state.item;
|
|
97
|
+
|
|
98
|
+
this.failTimeout = setTimeout(() => this.resolveRound(false), Math.max(duration, 1));
|
|
99
|
+
};
|
|
100
|
+
onHideAfter = () => {
|
|
101
|
+
this.clearTimers();
|
|
102
|
+
};
|
|
103
|
+
resolveRound = (success: boolean) => {
|
|
104
|
+
if (this.isResolved) return;
|
|
105
|
+
|
|
106
|
+
this.isResolved = true;
|
|
107
|
+
this.clearFailTimeout();
|
|
108
|
+
|
|
109
|
+
const duration = this.state.item?.duration ?? 0;
|
|
110
|
+
const pointerProgress = this.activeStartedAt === null ? 0 : getProgressFromElapsed(performance.now() - this.activeStartedAt, duration);
|
|
111
|
+
|
|
112
|
+
this.updateStateAndViewFast({
|
|
113
|
+
phase: "resolved",
|
|
114
|
+
result: success ? "success" : "fail",
|
|
115
|
+
pointerProgress,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
this.resultTimeout = setTimeout(() => {
|
|
119
|
+
void this.emit(this.EVENTS.QTE.RESULT, { success });
|
|
120
|
+
}, this.PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
121
|
+
};
|
|
122
|
+
clearFailTimeout = () => {
|
|
123
|
+
if (this.failTimeout) clearTimeout(this.failTimeout);
|
|
124
|
+
this.failTimeout = null;
|
|
125
|
+
};
|
|
126
|
+
clearTimers = () => {
|
|
127
|
+
this.clearFailTimeout();
|
|
128
|
+
if (this.phaseTimeout) clearTimeout(this.phaseTimeout);
|
|
129
|
+
if (this.resultTimeout) clearTimeout(this.resultTimeout);
|
|
130
|
+
this.phaseTimeout = null;
|
|
131
|
+
this.resultTimeout = null;
|
|
132
|
+
this.activeStartedAt = null;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
4
|
+
|
|
5
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
6
|
+
|
|
7
|
+
import { render } from "../view/index.js";
|
|
8
|
+
|
|
9
|
+
export class QteViewView extends ModuleView<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState> {
|
|
10
|
+
name = "qte_view.view";
|
|
11
|
+
|
|
12
|
+
EVENT_UPDATE_VIEW = this.EVENTS.QTE_VIEW.UPDATE;
|
|
13
|
+
|
|
14
|
+
LOC_LABEL = this.PARAMS.QTE_VIEW.LOC_LABEL;
|
|
15
|
+
|
|
16
|
+
TRANSITION = this.PARAMS.QTE_VIEW.TRANSITION;
|
|
17
|
+
|
|
18
|
+
renderFunc = render;
|
|
19
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { QteViewControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createQteViewTestModule, registerQteViewPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("QteViewControllerAccept", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerQteViewPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
15
|
+
const { module, observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
16
|
+
const accept = module as QteViewControllerAccept;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
key: "qte_view.controller.accept",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: accept.PARAMS.QTE_VIEW.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("HIDE pops ACCEPT controls", async () => {
|
|
33
|
+
const { observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
34
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
38
|
+
|
|
39
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "qte_view.controller.accept" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("ACCEPT and INTERACT emit QTE_VIEW.ACTION", async () => {
|
|
43
|
+
const { module, observer } = createQteViewTestModule(QteViewControllerAccept);
|
|
44
|
+
const accept = module as QteViewControllerAccept;
|
|
45
|
+
const action = spyEvent(observer, SUBSCRIBE_EVENTS.ACTION);
|
|
46
|
+
|
|
47
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
|
|
48
|
+
accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
|
|
49
|
+
await Promise.resolve();
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
|
|
52
|
+
expect(action).toHaveBeenCalledTimes(2);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { QteViewController } from "../modules/controller.js";
|
|
6
|
+
|
|
7
|
+
import { createQteViewTestModule, registerQteViewPluginVne, QTE_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("QteViewController", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerQteViewPluginVne();
|
|
12
|
+
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "performance"] });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("OPENED bridge emits SHOW with payload", async () => {
|
|
16
|
+
const { observer } = createQteViewTestModule(QteViewController);
|
|
17
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
18
|
+
const payload = { id: "door_lock", item: { start: 70, size: 20, duration: 1500 } };
|
|
19
|
+
|
|
20
|
+
await observer.emit(QTE_EVENTS.OPENED, payload);
|
|
21
|
+
|
|
22
|
+
expect(show).toHaveBeenCalledExactlyOnceWith(payload);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("SHOW starts in initial, then active after screen transition", async () => {
|
|
26
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
27
|
+
const item = { start: 70, size: 20, duration: 1500 };
|
|
28
|
+
const { TRANSITION } = (module as QteViewController).PARAMS.QTE_VIEW;
|
|
29
|
+
|
|
30
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
31
|
+
|
|
32
|
+
expect((module as QteViewController).state.id).toBe("door_lock");
|
|
33
|
+
expect((module as QteViewController).state.item).toEqual(item);
|
|
34
|
+
expect((module as QteViewController).state.phase).toBe("initial");
|
|
35
|
+
|
|
36
|
+
await vi.advanceTimersByTimeAsync(TRANSITION);
|
|
37
|
+
expect((module as QteViewController).state.phase).toBe("active");
|
|
38
|
+
expect((module as QteViewController).activeStartedAt).not.toBeNull();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("ACTION resolves success inside zone by elapsed time", async () => {
|
|
42
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
43
|
+
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
44
|
+
const item = { start: 40, size: 20, duration: 1000 };
|
|
45
|
+
|
|
46
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
47
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
48
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
49
|
+
|
|
50
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACTION);
|
|
51
|
+
|
|
52
|
+
expect((module as QteViewController).state.result).toBe("success");
|
|
53
|
+
|
|
54
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
55
|
+
|
|
56
|
+
expect(result).toHaveBeenCalledExactlyOnceWith({ success: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("ACTION resolves fail outside zone", async () => {
|
|
60
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
61
|
+
const item = { start: 70, size: 20, duration: 1000 };
|
|
62
|
+
|
|
63
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
64
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
65
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
66
|
+
|
|
67
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACTION);
|
|
68
|
+
|
|
69
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("auto-fails when marker reaches the end of the track", async () => {
|
|
73
|
+
const { module, observer } = createQteViewTestModule(QteViewController);
|
|
74
|
+
const result = spyEvent(observer, QTE_EVENTS.RESULT);
|
|
75
|
+
const item = { start: 50, size: 10, duration: 1000 };
|
|
76
|
+
|
|
77
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW, { id: "door_lock", item });
|
|
78
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.TRANSITION);
|
|
79
|
+
await vi.advanceTimersByTimeAsync(600);
|
|
80
|
+
|
|
81
|
+
expect((module as QteViewController).state.result).toBe("idle");
|
|
82
|
+
|
|
83
|
+
await vi.advanceTimersByTimeAsync(400);
|
|
84
|
+
await vi.advanceTimersByTimeAsync((module as QteViewController).PARAMS.QTE_VIEW.RESULT_DELAY);
|
|
85
|
+
|
|
86
|
+
expect((module as QteViewController).state.result).toBe("fail");
|
|
87
|
+
expect(result).toHaveBeenCalledExactlyOnceWith({ success: false });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { getFailAtProgress, getProgressFromElapsed, isProgressInsideZone } from "../utils/qte.js";
|
|
4
|
+
|
|
5
|
+
describe("qte utils", () => {
|
|
6
|
+
it("getProgressFromElapsed maps time to percent", () => {
|
|
7
|
+
expect(getProgressFromElapsed(0, 1000)).toBe(0);
|
|
8
|
+
expect(getProgressFromElapsed(500, 1000)).toBe(50);
|
|
9
|
+
expect(getProgressFromElapsed(1500, 1000)).toBe(100);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("isProgressInsideZone checks inclusive bounds", () => {
|
|
13
|
+
expect(isProgressInsideZone(70, 70, 20)).toBe(true);
|
|
14
|
+
expect(isProgressInsideZone(90, 70, 20)).toBe(true);
|
|
15
|
+
expect(isProgressInsideZone(69, 70, 20)).toBe(false);
|
|
16
|
+
expect(isProgressInsideZone(91, 70, 20)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("getFailAtProgress is end of track", () => {
|
|
20
|
+
expect(getFailAtProgress()).toBe(100);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SourcesSet } from "@vnejs/sources-set";
|
|
2
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
3
|
+
|
|
4
|
+
import { PARAMS as QTE_VIEW_PARAMS, PLUGIN_NAME as QTE_VIEW, SUBSCRIBE_EVENTS as QTE_VIEW_EVENTS } from "@vnejs/contracts.controllers.scenario.qte";
|
|
5
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
6
|
+
import { PARAMS as QTE_PARAMS, PLUGIN_NAME as QTE, SUBSCRIBE_EVENTS as QTE_EVENTS } from "@vnejs/contracts.scenario.qte";
|
|
7
|
+
|
|
8
|
+
export const registerQteViewPluginVne = () => {
|
|
9
|
+
registerCoreVne();
|
|
10
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
11
|
+
registerVnePlugin(QTE, { events: QTE_EVENTS, params: QTE_PARAMS });
|
|
12
|
+
registerVnePlugin(QTE_VIEW, { events: QTE_VIEW_EVENTS, params: QTE_VIEW_PARAMS });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const createQteViewTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
16
|
+
ModuleClass: T,
|
|
17
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
18
|
+
) => {
|
|
19
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
20
|
+
shared: {
|
|
21
|
+
viewForceAnimationSources: new SourcesSet(),
|
|
22
|
+
...(options.shared ?? {}),
|
|
23
|
+
},
|
|
24
|
+
...options,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.SHOW);
|
|
28
|
+
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.HIDE);
|
|
29
|
+
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.UPDATE);
|
|
30
|
+
stubSilentEvent(result.observer, QTE_VIEW_EVENTS.ACTION);
|
|
31
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
32
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { QTE_VIEW_EVENTS as SUBSCRIBE_EVENTS, QTE_EVENTS, CONTROLS_EVENTS };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { PluginName, SubscribeEvents, Params } from "@vnejs/contracts.controllers.scenario.qte";
|
|
4
|
+
import type { PluginName as ControlsPluginName, Constants as ControlsConstants } from "@vnejs/contracts.controls";
|
|
5
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
|
|
6
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/contracts.core.vendors";
|
|
7
|
+
import type { PluginName as QtePluginName, SubscribeEvents as QteSubscribeEvents, Params as QteParams } from "@vnejs/contracts.scenario.qte";
|
|
8
|
+
|
|
9
|
+
export type QtePluginEvents = ModuleComponentsEvents &
|
|
10
|
+
Record<QtePluginName, QteSubscribeEvents> &
|
|
11
|
+
Record<PluginName, SubscribeEvents> &
|
|
12
|
+
Record<VendorsPluginName, VendorsSubscribeEvents> &
|
|
13
|
+
Record<LogsPluginName, LogsSubscribeEvents>;
|
|
14
|
+
|
|
15
|
+
export type QtePluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
16
|
+
|
|
17
|
+
export type QtePluginSettings = ModuleComponentsSettings;
|
|
18
|
+
|
|
19
|
+
export type QtePluginParams = ModuleComponentsParams & Record<QtePluginName, QteParams> & Record<PluginName, Params>;
|
package/src/utils/qte.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ModuleControllerState } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { QteItem } from "@vnejs/contracts.controllers.scenario.qte";
|
|
4
|
+
|
|
5
|
+
export type QtePhase = "idle" | "initial" | "active" | "resolved";
|
|
6
|
+
export type QteResult = "idle" | "success" | "fail";
|
|
7
|
+
|
|
8
|
+
export type QtePluginControllerState = ModuleControllerState & {
|
|
9
|
+
id: string;
|
|
10
|
+
item: QteItem | null;
|
|
11
|
+
phase: QtePhase;
|
|
12
|
+
result: QteResult;
|
|
13
|
+
pointerProgress: number;
|
|
14
|
+
locs?: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getProgressFromElapsed = (elapsedMs: number, duration: number) => {
|
|
18
|
+
if (duration <= 0) return 100;
|
|
19
|
+
|
|
20
|
+
return Math.min(Math.max((elapsedMs / duration) * 100, 0), 100);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const isProgressInsideZone = (progress: number, start: number, size: number) => {
|
|
24
|
+
const zoneEnd = Math.min(start + size, 100);
|
|
25
|
+
|
|
26
|
+
return progress >= start && progress <= zoneEnd;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getFailAtProgress = () => 100;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { cn, getVneLength, injectStyles, sel } from "@vnejs/uis.utils";
|
|
2
|
+
|
|
3
|
+
export const b = cn("Qte");
|
|
4
|
+
|
|
5
|
+
const RAIL_WIDTH = 3840;
|
|
6
|
+
const RAIL_HEIGHT = 36;
|
|
7
|
+
const POINTER_SIZE = 96;
|
|
8
|
+
/** Доля времени анимации до 100% ширины; остальное — выезд маркера за край (110%). */
|
|
9
|
+
const POINTER_ACTIVE_KEYFRAME_PERCENT = (100 / 110) * 100;
|
|
10
|
+
const POINTER_ANIMATION_DURATION_FACTOR = 1.1;
|
|
11
|
+
export const POINTER_RETREAT_SPEED_FACTOR = 2;
|
|
12
|
+
const POINTER_GLOW_TRANSITION_MS = 400;
|
|
13
|
+
|
|
14
|
+
const CSS = `
|
|
15
|
+
@keyframes qte-pointer-move {
|
|
16
|
+
0% {
|
|
17
|
+
left: 0%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
${POINTER_ACTIVE_KEYFRAME_PERCENT}% {
|
|
21
|
+
left: 100%;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
100% {
|
|
25
|
+
left: 110%;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
${sel(b("shell", { phase: "initial" }))},
|
|
30
|
+
${sel(b("shell", { phase: "resolved" }))} {
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
${sel(b("block"))} {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
align-items: center;
|
|
38
|
+
width: ${getVneLength(RAIL_WIDTH)};
|
|
39
|
+
gap: ${getVneLength(48)};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
${sel(b("status"))} {
|
|
43
|
+
display: grid;
|
|
44
|
+
place-items: center;
|
|
45
|
+
width: ${getVneLength(528)};
|
|
46
|
+
text-align: center;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
color: #ffffff;
|
|
49
|
+
font-size: ${getVneLength(72)};
|
|
50
|
+
font-weight: 900;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
${sel(b("statusLine"))} {
|
|
54
|
+
grid-area: 1 / 1;
|
|
55
|
+
opacity: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
${sel(b("statusLine", { shown: true }))} {
|
|
59
|
+
opacity: 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
${sel(b("rail"))} {
|
|
63
|
+
position: relative;
|
|
64
|
+
width: ${getVneLength(RAIL_WIDTH)};
|
|
65
|
+
height: ${getVneLength(RAIL_HEIGHT)};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
${sel(b("track"))} {
|
|
69
|
+
position: absolute;
|
|
70
|
+
inset: 0;
|
|
71
|
+
background: var(--vne-color-disabled, rgba(255, 255, 255, 30%));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
${sel(b("sector"))} {
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: 0;
|
|
77
|
+
bottom: 0;
|
|
78
|
+
border-radius: ${getVneLength(18)};
|
|
79
|
+
background: var(--vne-color-main, rgba(255, 255, 255, 100%));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
${sel(b("pointerMove"))} {
|
|
83
|
+
position: absolute;
|
|
84
|
+
top: 50%;
|
|
85
|
+
left: 0;
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
transform: translate(-50%, -50%);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
${sel(b("pointerMove", { moving: true }))} {
|
|
91
|
+
animation-name: qte-pointer-move;
|
|
92
|
+
animation-duration: calc(var(--qte-duration, 1800ms) * ${POINTER_ANIMATION_DURATION_FACTOR});
|
|
93
|
+
animation-timing-function: linear;
|
|
94
|
+
animation-fill-mode: forwards;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
${sel(b("pointerMove", { retreat: true }))} {
|
|
98
|
+
animation: none;
|
|
99
|
+
left: calc(var(--qte-pointer-progress, 0) * 1%);
|
|
100
|
+
transition-property: left;
|
|
101
|
+
transition-timing-function: linear;
|
|
102
|
+
transition-duration: var(--qte-retreat-duration, 0ms);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
${sel(b("pointerMove", { retreat: true, retreatActive: true }))} {
|
|
106
|
+
left: 0%;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
${sel(b("pointer"))} {
|
|
110
|
+
width: ${getVneLength(POINTER_SIZE)};
|
|
111
|
+
height: ${getVneLength(POINTER_SIZE)};
|
|
112
|
+
border-radius: 50%;
|
|
113
|
+
opacity: 1;
|
|
114
|
+
background: #ffffff;
|
|
115
|
+
filter: drop-shadow(0 0 ${getVneLength(12)} rgba(0, 0, 0, 0.3));
|
|
116
|
+
box-shadow: 0 0 0 0 transparent;
|
|
117
|
+
transition:
|
|
118
|
+
box-shadow ${POINTER_GLOW_TRANSITION_MS}ms ease,
|
|
119
|
+
filter ${POINTER_GLOW_TRANSITION_MS}ms ease;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
${sel(b("pointer", { failFade: true }))} {
|
|
123
|
+
opacity: 1;
|
|
124
|
+
transition:
|
|
125
|
+
opacity var(--qte-result-delay, 500ms) linear,
|
|
126
|
+
box-shadow ${POINTER_GLOW_TRANSITION_MS}ms ease,
|
|
127
|
+
filter ${POINTER_GLOW_TRANSITION_MS}ms ease;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
${sel(b("pointer", { failFade: true, failFadeActive: true }))} {
|
|
131
|
+
opacity: 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
${sel(b("pointer", { success: true }))} {
|
|
135
|
+
box-shadow:
|
|
136
|
+
0 0 ${getVneLength(28)} var(--vne-color-main, rgba(255, 255, 255, 100%)),
|
|
137
|
+
0 0 ${getVneLength(56)} var(--vne-color-main, rgba(255, 255, 255, 100%));
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
|
|
141
|
+
injectStyles(CSS);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { PositionBox, Screen, createRenderFunc, useEffect, useIsForceHook, useState, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { QtePluginControllerState } from "../utils/qte.js";
|
|
8
|
+
|
|
9
|
+
import type { QtePluginConstants, QtePluginEvents, QtePluginParams, QtePluginSettings } from "../types.js";
|
|
10
|
+
|
|
11
|
+
import { POINTER_RETREAT_SPEED_FACTOR, b } from "./index.styles.js";
|
|
12
|
+
|
|
13
|
+
type QteComponentProps = ReactComponentProps<QtePluginEvents, QtePluginConstants, QtePluginSettings, QtePluginParams, QtePluginControllerState>;
|
|
14
|
+
|
|
15
|
+
const Qte = ({ store, onMount, emit, EVENTS, PARAMS }: QteComponentProps) => {
|
|
16
|
+
const {
|
|
17
|
+
isShow = false,
|
|
18
|
+
isForce = false,
|
|
19
|
+
phase = "",
|
|
20
|
+
result = "",
|
|
21
|
+
item = null,
|
|
22
|
+
locs = {},
|
|
23
|
+
pointerProgress = 0,
|
|
24
|
+
} = useStoreState<QtePluginControllerState>(store, onMount);
|
|
25
|
+
|
|
26
|
+
const isRealForce = useIsForceHook(isForce);
|
|
27
|
+
const propsView = PARAMS.QTE_VIEW.VIEW_PROPS;
|
|
28
|
+
const transition = isRealForce ? 0 : PARAMS.QTE_VIEW.TRANSITION;
|
|
29
|
+
const duration = item?.duration ?? 0;
|
|
30
|
+
|
|
31
|
+
const start = item?.start ?? 0;
|
|
32
|
+
const size = item?.size ?? 0;
|
|
33
|
+
const sectorWidth = Math.min(size, Math.max(100 - start, 0));
|
|
34
|
+
|
|
35
|
+
const isPointerRetreat = phase === "resolved" && result === "fail";
|
|
36
|
+
const isFailResult = isPointerRetreat;
|
|
37
|
+
const isPointerMoving = phase === "active" || (phase === "resolved" && result === "success");
|
|
38
|
+
const isPointerSuccess = result === "success";
|
|
39
|
+
const resultDelayMs = isRealForce ? 0 : PARAMS.QTE_VIEW.RESULT_DELAY;
|
|
40
|
+
|
|
41
|
+
const [isRetreatActive, setRetreatActive] = useState(false);
|
|
42
|
+
const [isFailFadeActive, setFailFadeActive] = useState(false);
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!isPointerRetreat) {
|
|
46
|
+
setRetreatActive(false);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const frame = requestAnimationFrame(() => setRetreatActive(true));
|
|
51
|
+
|
|
52
|
+
return () => cancelAnimationFrame(frame);
|
|
53
|
+
}, [isPointerRetreat, pointerProgress]);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!isFailResult) {
|
|
57
|
+
setFailFadeActive(false);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const frame = requestAnimationFrame(() => setFailFadeActive(true));
|
|
62
|
+
|
|
63
|
+
return () => cancelAnimationFrame(frame);
|
|
64
|
+
}, [isFailResult]);
|
|
65
|
+
|
|
66
|
+
const sectorStyle = { left: `${start}%`, width: `${sectorWidth}%` };
|
|
67
|
+
|
|
68
|
+
const retreatDurationMs = (pointerProgress / 100) * duration * POINTER_RETREAT_SPEED_FACTOR;
|
|
69
|
+
|
|
70
|
+
const pointerMoveStyle = {
|
|
71
|
+
["--qte-duration" as string]: `${duration}ms`,
|
|
72
|
+
["--qte-pointer-progress" as string]: String(pointerProgress),
|
|
73
|
+
["--qte-retreat-duration" as string]: `${retreatDurationMs}ms`,
|
|
74
|
+
["--qte-result-delay" as string]: `${resultDelayMs}ms`,
|
|
75
|
+
} as Record<string, string>;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Screen
|
|
79
|
+
{...propsView.screen}
|
|
80
|
+
isDisableAutoread={true}
|
|
81
|
+
isIgnoreOnScreenshot={true}
|
|
82
|
+
isShow={isShow}
|
|
83
|
+
isForce={isRealForce}
|
|
84
|
+
transition={transition}
|
|
85
|
+
>
|
|
86
|
+
<PositionBox {...propsView.position}>
|
|
87
|
+
<div className={b("shell", { phase })}>
|
|
88
|
+
<div className={b("block")}>
|
|
89
|
+
<div
|
|
90
|
+
className={b("status")}
|
|
91
|
+
aria-live="polite"
|
|
92
|
+
>
|
|
93
|
+
<span className={b("statusLine", { shown: result === "success" })}>{locs.success ?? ""}</span>
|
|
94
|
+
<span className={b("statusLine", { shown: result === "fail" })}>{locs.fail ?? ""}</span>
|
|
95
|
+
</div>
|
|
96
|
+
<div
|
|
97
|
+
className={b("rail")}
|
|
98
|
+
onClick={() => void emit(EVENTS.QTE_VIEW.ACTION)}
|
|
99
|
+
vne-cursor-type="pointer"
|
|
100
|
+
vne-cursor-target-possible=""
|
|
101
|
+
>
|
|
102
|
+
<div className={b("track")} />
|
|
103
|
+
<div
|
|
104
|
+
className={b("sector")}
|
|
105
|
+
style={sectorStyle}
|
|
106
|
+
/>
|
|
107
|
+
<div
|
|
108
|
+
className={b("pointerMove", {
|
|
109
|
+
moving: isPointerMoving,
|
|
110
|
+
retreat: isPointerRetreat,
|
|
111
|
+
retreatActive: isPointerRetreat && isRetreatActive,
|
|
112
|
+
})}
|
|
113
|
+
style={pointerMoveStyle}
|
|
114
|
+
>
|
|
115
|
+
<div
|
|
116
|
+
className={b("pointer", {
|
|
117
|
+
success: isPointerSuccess,
|
|
118
|
+
failFade: isFailResult,
|
|
119
|
+
failFadeActive: isFailResult && isFailFadeActive,
|
|
120
|
+
})}
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</PositionBox>
|
|
127
|
+
</Screen>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const render: ViewRenderFunc<QtePluginControllerState> = createRenderFunc(Qte);
|
package/tsconfig.json
ADDED
package/README.md
DELETED