@vnejs/plugins.controllers.screens.gamemenu 0.0.0-stage → 0.2.14
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 +1 -0
- package/dist/index.js +19 -0
- package/dist/modules/controller.accept.d.ts +12 -0
- package/dist/modules/controller.accept.js +15 -0
- package/dist/modules/controller.arrows.d.ts +11 -0
- package/dist/modules/controller.arrows.js +14 -0
- package/dist/modules/controller.d.ts +17 -0
- package/dist/modules/controller.js +24 -0
- package/dist/modules/gamemenu.d.ts +11 -0
- package/dist/modules/gamemenu.js +19 -0
- package/dist/modules/hide.controls.d.ts +8 -0
- package/dist/modules/hide.controls.js +7 -0
- package/dist/modules/hide.state.d.ts +6 -0
- package/dist/modules/hide.state.js +5 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.js +1 -0
- package/dist/utils/gamemenu.d.ts +2 -0
- package/dist/utils/gamemenu.js +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +16 -0
- package/package.json +61 -4
- package/src/index.ts +23 -0
- package/src/modules/controller.accept.ts +31 -0
- package/src/modules/controller.arrows.ts +29 -0
- package/src/modules/controller.ts +41 -0
- package/src/modules/gamemenu.ts +30 -0
- package/src/modules/hide.controls.ts +17 -0
- package/src/modules/hide.state.ts +14 -0
- package/src/modules/view.ts +17 -0
- package/src/tests/accept.test.ts +92 -0
- package/src/tests/arrows.test.ts +109 -0
- package/src/tests/gamemenu.test.ts +41 -0
- package/src/tests/hide.controls.test.ts +57 -0
- package/src/tests/hide.state.test.ts +27 -0
- package/src/tests/setup.ts +35 -0
- package/src/types.ts +25 -0
- package/src/utils/gamemenu.ts +3 -0
- package/src/view/index.tsx +59 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.gamemenu";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.gamemenu";
|
|
2
|
+
import { regPlugin } from "@vnejs/registry";
|
|
3
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
4
|
+
import { GamemenuControllerAccept } from "./modules/controller.accept.js";
|
|
5
|
+
import { GamemenuControllerArrows } from "./modules/controller.arrows.js";
|
|
6
|
+
import { GamemenuController } from "./modules/controller.js";
|
|
7
|
+
import { Gamemenu } from "./modules/gamemenu.js";
|
|
8
|
+
import { GamemenuHideControls } from "./modules/hide.controls.js";
|
|
9
|
+
import { GamemenuHideState } from "./modules/hide.state.js";
|
|
10
|
+
import { GamemenuView } from "./modules/view.js";
|
|
11
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
12
|
+
GamemenuController,
|
|
13
|
+
GamemenuControllerAccept,
|
|
14
|
+
GamemenuControllerArrows,
|
|
15
|
+
GamemenuHideControls,
|
|
16
|
+
GamemenuHideState,
|
|
17
|
+
Gamemenu,
|
|
18
|
+
GamemenuView,
|
|
19
|
+
]);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
4
|
+
export declare class GamemenuControllerAccept extends ModuleControllerAccept<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_SHOW: "vne:gamemenu:show";
|
|
7
|
+
EVENT_HIDE: "vne:gamemenu:hide";
|
|
8
|
+
EVENT_ACCEPT: "vne:gamemenu:accept";
|
|
9
|
+
EVENT_UPDATE_STATE: "vne:gamemenu:update_state";
|
|
10
|
+
CONTROLS_ZINDEX: number;
|
|
11
|
+
onAccept: () => Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
import { isNotDisabledNotHided } from "@vnejs/helpers";
|
|
3
|
+
export class GamemenuControllerAccept extends ModuleControllerAccept {
|
|
4
|
+
name = "gamemenu.controller.accept";
|
|
5
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
6
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
7
|
+
EVENT_ACCEPT = this.EVENTS.GAMEMENU.ACCEPT;
|
|
8
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
9
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
10
|
+
onAccept = async () => {
|
|
11
|
+
const items = (await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) ?? [];
|
|
12
|
+
const realItem = items.filter(isNotDisabledNotHided)[this.state.currentArrowVerticalItem ?? -1];
|
|
13
|
+
this.emit(this.EVENTS.GAMEMENU.CLICK, { index: items.indexOf(realItem) });
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
export declare class GamemenuControllerArrows extends ModuleControllerArrowsVertical<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_SHOW: "vne:gamemenu:show";
|
|
6
|
+
EVENT_HIDE: "vne:gamemenu:hide";
|
|
7
|
+
EVENT_UPDATE_STATE: "vne:gamemenu:update_state";
|
|
8
|
+
EVENT_UPDATE_FAST: "vne:gamemenu:update_fast";
|
|
9
|
+
CONTROLS_ZINDEX: number;
|
|
10
|
+
getMaxCurrentItem: () => Promise<number>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
|
|
2
|
+
import { isNotDisabledNotHided } from "@vnejs/helpers";
|
|
3
|
+
export class GamemenuControllerArrows extends ModuleControllerArrowsVertical {
|
|
4
|
+
name = "gamemenu.controller.arrows";
|
|
5
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
6
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
7
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
8
|
+
EVENT_UPDATE_FAST = this.EVENTS.GAMEMENU.UPDATE_FAST;
|
|
9
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
10
|
+
getMaxCurrentItem = async () => {
|
|
11
|
+
const items = (await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) ?? [];
|
|
12
|
+
return items.filter(isNotDisabledNotHided).length - 1;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
4
|
+
export declare class GamemenuController extends ModuleController<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:gamemenu:update";
|
|
7
|
+
EVENT_UPDATE_STATE: "vne:gamemenu:update_state";
|
|
8
|
+
EVENT_UPDATE_FAST: "vne:gamemenu:update_fast";
|
|
9
|
+
EVENT_UPDATE_FORCE: "vne:gamemenu:update_force";
|
|
10
|
+
EVENT_SHOW: "vne:gamemenu:show";
|
|
11
|
+
EVENT_HIDE: "vne:gamemenu:hide";
|
|
12
|
+
CONTROLS: {};
|
|
13
|
+
CONTROLS_INDEX: number;
|
|
14
|
+
onShowBefore: () => Promise<void>;
|
|
15
|
+
onExternalUpdate: () => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
|
|
16
|
+
updateStateItems: () => Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import { isNotDisabledNotHided, omitOnClick } from "@vnejs/helpers";
|
|
3
|
+
export class GamemenuController extends ModuleController {
|
|
4
|
+
name = "gamemenu.controller";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GAMEMENU.UPDATE;
|
|
6
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
7
|
+
EVENT_UPDATE_FAST = this.EVENTS.GAMEMENU.UPDATE_FAST;
|
|
8
|
+
EVENT_UPDATE_FORCE = this.EVENTS.GAMEMENU.UPDATE_FORCE;
|
|
9
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
10
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
11
|
+
CONTROLS = {};
|
|
12
|
+
CONTROLS_INDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
13
|
+
onShowBefore = async () => {
|
|
14
|
+
return this.updateStateItems();
|
|
15
|
+
};
|
|
16
|
+
onExternalUpdate = async () => {
|
|
17
|
+
await this.updateStateItems();
|
|
18
|
+
return this.updateViewFast();
|
|
19
|
+
};
|
|
20
|
+
updateStateItems = async () => {
|
|
21
|
+
const items = (await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)).map(omitOnClick);
|
|
22
|
+
this.updateState({ items, realItems: items.filter(isNotDisabledNotHided) });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { GameMenuItem, GameMenuItemFactory } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
3
|
+
import type { GameMenuClickPayload } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
4
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
5
|
+
export declare class Gamemenu extends ModuleCore<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
|
|
6
|
+
name: string;
|
|
7
|
+
subscribe: () => void;
|
|
8
|
+
onItems: () => Promise<GameMenuItem[]>;
|
|
9
|
+
onClick: ({ index }?: GameMenuClickPayload) => Promise<void>;
|
|
10
|
+
getItemByFunc: (func: GameMenuItemFactory) => GameMenuItem;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
export class Gamemenu extends ModuleCore {
|
|
3
|
+
name = "gamemenu";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.GAMEMENU.ITEMS, this.onItems);
|
|
6
|
+
this.on(this.EVENTS.GAMEMENU.CLICK, this.onClick);
|
|
7
|
+
};
|
|
8
|
+
onItems = () => Promise.all(this.PARAMS.GAMEMENU.ITEMS.map(this.getItemByFunc));
|
|
9
|
+
onClick = async ({ index } = {}) => {
|
|
10
|
+
if (index === null || index === undefined)
|
|
11
|
+
return;
|
|
12
|
+
const items = (await this.emitOne(this.EVENTS.GAMEMENU.ITEMS));
|
|
13
|
+
const item = items[index];
|
|
14
|
+
if (!item || item.isDisabled || item.isHided)
|
|
15
|
+
return;
|
|
16
|
+
return item.onClick?.();
|
|
17
|
+
};
|
|
18
|
+
getItemByFunc = (func) => func(this);
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
export declare class GamemenuHideControls extends ModuleControllerHideOnControls<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_SHOW: "vne:gamemenu:show";
|
|
6
|
+
EVENT_HIDE: "vne:gamemenu:hide";
|
|
7
|
+
CONTROLS_ZINDEX: number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
|
|
2
|
+
export class GamemenuHideControls extends ModuleControllerHideOnControls {
|
|
3
|
+
name = "gamemenu.hide.controls";
|
|
4
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
5
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
6
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
export declare class GamemenuHideState extends ModuleControllerHideOnState<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_HIDE: "vne:gamemenu:hide";
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
3
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
4
|
+
export declare class GamemenuView extends ModuleView<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:gamemenu:update";
|
|
7
|
+
LOC_LABEL: string;
|
|
8
|
+
TRANSITION: number;
|
|
9
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<GameMenuPluginState>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class GamemenuView extends ModuleView {
|
|
4
|
+
name = "gamemenu.view";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GAMEMENU.UPDATE;
|
|
6
|
+
LOC_LABEL = this.PARAMS.GAMEMENU.LOC_LABEL;
|
|
7
|
+
TRANSITION = this.PARAMS.GAMEMENU.TRANSITION;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
3
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
5
|
+
import type { GameMenuViewItem } from "./utils/gamemenu.js";
|
|
6
|
+
export type GameMenuPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
7
|
+
export type GameMenuPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
8
|
+
export type GameMenuPluginSettings = ModuleComponentsSettings;
|
|
9
|
+
export type GameMenuPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
10
|
+
export type GameMenuPluginState = {
|
|
11
|
+
isShow: boolean;
|
|
12
|
+
isForce: boolean;
|
|
13
|
+
items?: GameMenuViewItem[];
|
|
14
|
+
realItems?: GameMenuViewItem[];
|
|
15
|
+
locs?: Record<string, string>;
|
|
16
|
+
currentItem?: number | null;
|
|
17
|
+
currentArrowVerticalItem?: number | null;
|
|
18
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PositionBox, Screen, TextControls, createRenderFunc, useStoreState } from "@vnejs/uis.react";
|
|
3
|
+
const Gamemenu = ({ store, onMount, PARAMS, emit, EVENTS }) => {
|
|
4
|
+
const { isShow = false, isForce = false, items = [], realItems = [], locs = {}, currentArrowVerticalItem: currentItem = null, } = useStoreState(store, onMount);
|
|
5
|
+
const selectedKey = realItems[currentItem ?? -1]?.locKey;
|
|
6
|
+
const texts = items.map(({ locKey, isDisabled, isHided }, i) => ({
|
|
7
|
+
text: locs[locKey],
|
|
8
|
+
isDisabled,
|
|
9
|
+
isNotRender: isHided,
|
|
10
|
+
value: i,
|
|
11
|
+
}));
|
|
12
|
+
const selectedIndex = items.findIndex((value) => selectedKey === value?.locKey);
|
|
13
|
+
const propsView = PARAMS.GAMEMENU.VIEW_PROPS;
|
|
14
|
+
return (_jsx(Screen, { ...propsView.screen, isShow: isShow, isForce: isForce, isDisableAutoread: isShow, children: _jsx(PositionBox, { ...propsView.position, children: _jsx(TextControls, { ...propsView.controls, selectedIndex: selectedIndex >= 0 ? selectedIndex : undefined, texts: texts, onClick: (index) => void emit(EVENTS.GAMEMENU.CLICK, { index: Number(index) }) }) }) }));
|
|
15
|
+
};
|
|
16
|
+
export const render = createRenderFunc(Gamemenu);
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.screens.gamemenu",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.14",
|
|
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.controllers.screens.gamemenu": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.2.0",
|
|
37
|
+
"@vnejs/module.core": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
40
|
+
"@vnejs/module.controller.arrows.vertical": "~0.2.0",
|
|
41
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
42
|
+
"@vnejs/module.controller.hide.on.controls": "~0.2.0",
|
|
43
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
44
|
+
"@vnejs/registry": "~0.2.0",
|
|
45
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
49
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
50
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
51
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
52
|
+
"@vnejs/contracts.controllers.screens.gamemenu": "~0.2.0",
|
|
53
|
+
"@vnejs/helpers": "~0.2.0",
|
|
54
|
+
"@vnejs/module.core": "~0.2.0",
|
|
55
|
+
"@vnejs/module.components": "~0.2.0",
|
|
56
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
57
|
+
"@vnejs/module.controller.arrows.vertical": "~0.2.0",
|
|
58
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
59
|
+
"@vnejs/module.controller.hide.on.controls": "~0.2.0",
|
|
60
|
+
"@vnejs/registry": "~0.2.0",
|
|
61
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.gamemenu";
|
|
2
|
+
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
|
|
5
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
6
|
+
|
|
7
|
+
import { GamemenuControllerAccept } from "./modules/controller.accept.js";
|
|
8
|
+
import { GamemenuControllerArrows } from "./modules/controller.arrows.js";
|
|
9
|
+
import { GamemenuController } from "./modules/controller.js";
|
|
10
|
+
import { Gamemenu } from "./modules/gamemenu.js";
|
|
11
|
+
import { GamemenuHideControls } from "./modules/hide.controls.js";
|
|
12
|
+
import { GamemenuHideState } from "./modules/hide.state.js";
|
|
13
|
+
import { GamemenuView } from "./modules/view.js";
|
|
14
|
+
|
|
15
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
16
|
+
GamemenuController,
|
|
17
|
+
GamemenuControllerAccept,
|
|
18
|
+
GamemenuControllerArrows,
|
|
19
|
+
GamemenuHideControls,
|
|
20
|
+
GamemenuHideState,
|
|
21
|
+
Gamemenu,
|
|
22
|
+
GamemenuView,
|
|
23
|
+
]);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import { isNotDisabledNotHided } from "@vnejs/helpers";
|
|
4
|
+
|
|
5
|
+
import type { GameMenuItem } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
6
|
+
|
|
7
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
8
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
9
|
+
export class GamemenuControllerAccept extends ModuleControllerAccept<
|
|
10
|
+
GameMenuPluginEvents,
|
|
11
|
+
GameMenuPluginConstants,
|
|
12
|
+
GameMenuPluginSettings,
|
|
13
|
+
GameMenuPluginParams,
|
|
14
|
+
GameMenuPluginState
|
|
15
|
+
> {
|
|
16
|
+
name = "gamemenu.controller.accept";
|
|
17
|
+
|
|
18
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
19
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
20
|
+
EVENT_ACCEPT = this.EVENTS.GAMEMENU.ACCEPT;
|
|
21
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
22
|
+
|
|
23
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
24
|
+
|
|
25
|
+
onAccept = async () => {
|
|
26
|
+
const items = ((await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) as GameMenuItem[] | undefined) ?? [];
|
|
27
|
+
const realItem = items.filter(isNotDisabledNotHided)[this.state.currentArrowVerticalItem ?? -1];
|
|
28
|
+
|
|
29
|
+
this.emit(this.EVENTS.GAMEMENU.CLICK, { index: items.indexOf(realItem) });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
|
|
2
|
+
|
|
3
|
+
import { isNotDisabledNotHided } from "@vnejs/helpers";
|
|
4
|
+
|
|
5
|
+
import type { GameMenuItem } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
6
|
+
|
|
7
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
8
|
+
|
|
9
|
+
export class GamemenuControllerArrows extends ModuleControllerArrowsVertical<
|
|
10
|
+
GameMenuPluginEvents,
|
|
11
|
+
GameMenuPluginConstants,
|
|
12
|
+
GameMenuPluginSettings,
|
|
13
|
+
GameMenuPluginParams
|
|
14
|
+
> {
|
|
15
|
+
name = "gamemenu.controller.arrows";
|
|
16
|
+
|
|
17
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
18
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
19
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
20
|
+
EVENT_UPDATE_FAST = this.EVENTS.GAMEMENU.UPDATE_FAST;
|
|
21
|
+
|
|
22
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
23
|
+
|
|
24
|
+
getMaxCurrentItem = async () => {
|
|
25
|
+
const items = ((await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) as GameMenuItem[] | undefined) ?? [];
|
|
26
|
+
|
|
27
|
+
return items.filter(isNotDisabledNotHided).length - 1;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { isNotDisabledNotHided, omitOnClick } from "@vnejs/helpers";
|
|
4
|
+
|
|
5
|
+
import type { GameMenuItem } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
6
|
+
|
|
7
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
8
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
9
|
+
export class GamemenuController extends ModuleController<
|
|
10
|
+
GameMenuPluginEvents,
|
|
11
|
+
GameMenuPluginConstants,
|
|
12
|
+
GameMenuPluginSettings,
|
|
13
|
+
GameMenuPluginParams,
|
|
14
|
+
GameMenuPluginState
|
|
15
|
+
> {
|
|
16
|
+
name = "gamemenu.controller";
|
|
17
|
+
|
|
18
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GAMEMENU.UPDATE;
|
|
19
|
+
EVENT_UPDATE_STATE = this.EVENTS.GAMEMENU.UPDATE_STATE;
|
|
20
|
+
EVENT_UPDATE_FAST = this.EVENTS.GAMEMENU.UPDATE_FAST;
|
|
21
|
+
EVENT_UPDATE_FORCE = this.EVENTS.GAMEMENU.UPDATE_FORCE;
|
|
22
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
23
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
24
|
+
|
|
25
|
+
CONTROLS = {};
|
|
26
|
+
CONTROLS_INDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
27
|
+
|
|
28
|
+
onShowBefore = async () => {
|
|
29
|
+
return this.updateStateItems();
|
|
30
|
+
};
|
|
31
|
+
onExternalUpdate = async () => {
|
|
32
|
+
await this.updateStateItems();
|
|
33
|
+
|
|
34
|
+
return this.updateViewFast();
|
|
35
|
+
};
|
|
36
|
+
updateStateItems = async () => {
|
|
37
|
+
const items = ((await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) as GameMenuItem[]).map(omitOnClick);
|
|
38
|
+
|
|
39
|
+
this.updateState({ items, realItems: items.filter(isNotDisabledNotHided) });
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { GameMenuItem, GameMenuItemFactory } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
4
|
+
import type { GameMenuClickPayload } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
5
|
+
|
|
6
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export class Gamemenu extends ModuleCore<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
|
|
9
|
+
name = "gamemenu";
|
|
10
|
+
|
|
11
|
+
subscribe = () => {
|
|
12
|
+
this.on(this.EVENTS.GAMEMENU.ITEMS, this.onItems);
|
|
13
|
+
this.on(this.EVENTS.GAMEMENU.CLICK, this.onClick);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
onItems = () => Promise.all(this.PARAMS.GAMEMENU.ITEMS.map(this.getItemByFunc));
|
|
17
|
+
|
|
18
|
+
onClick = async ({ index }: GameMenuClickPayload = {}) => {
|
|
19
|
+
if (index === null || index === undefined) return;
|
|
20
|
+
|
|
21
|
+
const items = (await this.emitOne(this.EVENTS.GAMEMENU.ITEMS)) as GameMenuItem[];
|
|
22
|
+
const item = items[index];
|
|
23
|
+
|
|
24
|
+
if (!item || item.isDisabled || item.isHided) return;
|
|
25
|
+
|
|
26
|
+
return item.onClick?.();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
getItemByFunc = (func: GameMenuItemFactory) => func(this);
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
|
|
2
|
+
|
|
3
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class GamemenuHideControls extends ModuleControllerHideOnControls<
|
|
6
|
+
GameMenuPluginEvents,
|
|
7
|
+
GameMenuPluginConstants,
|
|
8
|
+
GameMenuPluginSettings,
|
|
9
|
+
GameMenuPluginParams
|
|
10
|
+
> {
|
|
11
|
+
name = "gamemenu.hide.controls";
|
|
12
|
+
|
|
13
|
+
EVENT_SHOW = this.EVENTS.GAMEMENU.SHOW;
|
|
14
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
15
|
+
|
|
16
|
+
CONTROLS_ZINDEX = this.PARAMS.GAMEMENU.ZINDEX;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
|
|
2
|
+
|
|
3
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class GamemenuHideState extends ModuleControllerHideOnState<
|
|
6
|
+
GameMenuPluginEvents,
|
|
7
|
+
GameMenuPluginConstants,
|
|
8
|
+
GameMenuPluginSettings,
|
|
9
|
+
GameMenuPluginParams
|
|
10
|
+
> {
|
|
11
|
+
name = "gamemenu.hide.state";
|
|
12
|
+
|
|
13
|
+
EVENT_HIDE = this.EVENTS.GAMEMENU.HIDE;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
4
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class GamemenuView extends ModuleView<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
|
|
8
|
+
name = "gamemenu.view";
|
|
9
|
+
|
|
10
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GAMEMENU.UPDATE;
|
|
11
|
+
|
|
12
|
+
LOC_LABEL = this.PARAMS.GAMEMENU.LOC_LABEL;
|
|
13
|
+
|
|
14
|
+
TRANSITION = this.PARAMS.GAMEMENU.TRANSITION;
|
|
15
|
+
|
|
16
|
+
renderFunc = render;
|
|
17
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent, stubEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GamemenuControllerAccept } from "../modules/controller.accept.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGameMenuTestModule, registerGameMenuPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GamemenuControllerAccept", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGameMenuPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes ACCEPT and INTERACT controls", async () => {
|
|
15
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerAccept);
|
|
16
|
+
const accept = module as GamemenuControllerAccept;
|
|
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: "gamemenu.controller.accept",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: accept.PARAMS.GAMEMENU.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 } = createGameMenuTestModule(GamemenuControllerAccept);
|
|
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: "gamemenu.controller.accept" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("ACCEPT and INTERACT emit GAMEMENU.ACCEPT", async () => {
|
|
43
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerAccept);
|
|
44
|
+
const accept = module as GamemenuControllerAccept;
|
|
45
|
+
const acceptEvent = spyEvent(observer, SUBSCRIBE_EVENTS.ACCEPT);
|
|
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(acceptEvent).toHaveBeenCalledTimes(2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("UPDATE_STATE caches currentArrowVerticalItem for CLICK", async () => {
|
|
56
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerAccept);
|
|
57
|
+
const accept = module as GamemenuControllerAccept;
|
|
58
|
+
const click = spyEvent(observer, SUBSCRIBE_EVENTS.CLICK);
|
|
59
|
+
const onClick = () => undefined;
|
|
60
|
+
|
|
61
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => [
|
|
62
|
+
{ locKey: "a", onClick },
|
|
63
|
+
{ locKey: "b", onClick },
|
|
64
|
+
{ locKey: "c", onClick },
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { currentArrowVerticalItem: 2 });
|
|
68
|
+
|
|
69
|
+
expect(accept.state.currentArrowVerticalItem).toBe(2);
|
|
70
|
+
|
|
71
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
72
|
+
|
|
73
|
+
expect(click).toHaveBeenCalledExactlyOnceWith({ index: 2 });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("ACCEPT maps realItems index to full items index skipping disabled", async () => {
|
|
77
|
+
const { observer } = createGameMenuTestModule(GamemenuControllerAccept);
|
|
78
|
+
const click = spyEvent(observer, SUBSCRIBE_EVENTS.CLICK);
|
|
79
|
+
const onClick = () => undefined;
|
|
80
|
+
|
|
81
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => [
|
|
82
|
+
{ locKey: "quickLoad", isDisabled: true, onClick },
|
|
83
|
+
{ locKey: "save", onClick },
|
|
84
|
+
{ locKey: "load", onClick },
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { currentArrowVerticalItem: 0 });
|
|
88
|
+
await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
|
|
89
|
+
|
|
90
|
+
expect(click).toHaveBeenCalledExactlyOnceWith({ index: 1 });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent, stubEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GamemenuControllerArrows } from "../modules/controller.arrows.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, PARAMS, createGameMenuTestModule, registerGameMenuPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
const onClick = () => undefined;
|
|
10
|
+
|
|
11
|
+
const setItems = (...locKeys: { locKey: string; isDisabled?: boolean; isHided?: boolean }[]) => {
|
|
12
|
+
PARAMS.ITEMS.splice(0, PARAMS.ITEMS.length, ...locKeys.map((item) => () => ({ ...item, onClick })));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe("GamemenuControllerArrows", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
registerGameMenuPluginVne();
|
|
18
|
+
setItems({ locKey: "continue" }, { locKey: "settings" });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
PARAMS.ITEMS.splice(0, PARAMS.ITEMS.length);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("SHOW pushes arrow controls above the controller layer", async () => {
|
|
26
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
27
|
+
const arrows = module as GamemenuControllerArrows;
|
|
28
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => PARAMS.ITEMS.map((factory) => factory(module)));
|
|
29
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
30
|
+
|
|
31
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
32
|
+
|
|
33
|
+
expect(arrows.currentItem).toBeNull();
|
|
34
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
35
|
+
expect.objectContaining({
|
|
36
|
+
key: "gamemenu.controller.arrows",
|
|
37
|
+
checkNext: true,
|
|
38
|
+
index: arrows.PARAMS.GAMEMENU.ZINDEX + 1,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("HIDE pops arrow controls", async () => {
|
|
44
|
+
const { observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
45
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
46
|
+
|
|
47
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
48
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
49
|
+
|
|
50
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gamemenu.controller.arrows" });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("first ARROW_BOTTOM selects 0 and emits UPDATE_STATE plus UPDATE_FAST", async () => {
|
|
54
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
55
|
+
const arrows = module as GamemenuControllerArrows;
|
|
56
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => PARAMS.ITEMS.map((factory) => factory(module)));
|
|
57
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
58
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
59
|
+
|
|
60
|
+
await arrows.incCurrentItem();
|
|
61
|
+
|
|
62
|
+
expect(arrows.currentItem).toBe(0);
|
|
63
|
+
expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ currentArrowVerticalItem: 0 });
|
|
64
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("arrow wrap cycles visible items", async () => {
|
|
68
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
69
|
+
const arrows = module as GamemenuControllerArrows;
|
|
70
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => PARAMS.ITEMS.map((factory) => factory(module)));
|
|
71
|
+
const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
72
|
+
|
|
73
|
+
await arrows.incCurrentItem();
|
|
74
|
+
await arrows.incCurrentItem();
|
|
75
|
+
expect(arrows.currentItem).toBe(1);
|
|
76
|
+
|
|
77
|
+
await arrows.incCurrentItem();
|
|
78
|
+
expect(arrows.currentItem).toBe(0);
|
|
79
|
+
expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 0 });
|
|
80
|
+
|
|
81
|
+
await arrows.decCurrentItem();
|
|
82
|
+
expect(arrows.currentItem).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("first ARROW_UP selects the last visible item", async () => {
|
|
86
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
87
|
+
const arrows = module as GamemenuControllerArrows;
|
|
88
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => PARAMS.ITEMS.map((factory) => factory(module)));
|
|
89
|
+
|
|
90
|
+
await arrows.decCurrentItem();
|
|
91
|
+
|
|
92
|
+
expect(arrows.currentItem).toBe(1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("disabled and hided items are skipped when computing max", async () => {
|
|
96
|
+
setItems({ locKey: "continue", isDisabled: true }, { locKey: "settings" }, { locKey: "gallery", isHided: true }, { locKey: "save" });
|
|
97
|
+
|
|
98
|
+
const { module, observer } = createGameMenuTestModule(GamemenuControllerArrows);
|
|
99
|
+
const arrows = module as GamemenuControllerArrows;
|
|
100
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => PARAMS.ITEMS.map((factory) => factory(module)));
|
|
101
|
+
|
|
102
|
+
await arrows.incCurrentItem();
|
|
103
|
+
await arrows.incCurrentItem();
|
|
104
|
+
expect(arrows.currentItem).toBe(1);
|
|
105
|
+
|
|
106
|
+
await arrows.incCurrentItem();
|
|
107
|
+
expect(arrows.currentItem).toBe(0);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { stubEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { Gamemenu } from "../modules/gamemenu.js";
|
|
6
|
+
|
|
7
|
+
import { createGameMenuTestModule, registerGameMenuPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("Gamemenu", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGameMenuPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("CLICK invokes item onClick from params", async () => {
|
|
15
|
+
const onClick = vi.fn();
|
|
16
|
+
const { module, observer } = createGameMenuTestModule(Gamemenu, { subscribe: false });
|
|
17
|
+
|
|
18
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => [{ locKey: "save", onClick }]);
|
|
19
|
+
|
|
20
|
+
await (module as Gamemenu).onClick({ index: 0 });
|
|
21
|
+
|
|
22
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("CLICK skips disabled and hided items", async () => {
|
|
26
|
+
const disabledClick = vi.fn();
|
|
27
|
+
const hidedClick = vi.fn();
|
|
28
|
+
const { module, observer } = createGameMenuTestModule(Gamemenu, { subscribe: false });
|
|
29
|
+
|
|
30
|
+
stubEvent(observer, SUBSCRIBE_EVENTS.ITEMS, () => [
|
|
31
|
+
{ locKey: "quickLoad", isDisabled: true, onClick: disabledClick },
|
|
32
|
+
{ locKey: "hidden", isHided: true, onClick: hidedClick },
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
await (module as Gamemenu).onClick({ index: 0 });
|
|
36
|
+
await (module as Gamemenu).onClick({ index: 1 });
|
|
37
|
+
|
|
38
|
+
expect(disabledClick).not.toHaveBeenCalled();
|
|
39
|
+
expect(hidedClick).not.toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GamemenuHideControls } from "../modules/hide.controls.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGameMenuTestModule, registerGameMenuPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GamemenuHideControls", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGameMenuPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes BACK, MENU and GAMEMENU controls", async () => {
|
|
15
|
+
const { module, observer } = createGameMenuTestModule(GamemenuHideControls);
|
|
16
|
+
const hide = module as GamemenuHideControls;
|
|
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: "gamemenu.hide.controls",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: hide.PARAMS.GAMEMENU.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.BACK);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.MENU);
|
|
30
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.GAMEMENU);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("HIDE pops hide.controls", async () => {
|
|
34
|
+
const { observer } = createGameMenuTestModule(GamemenuHideControls);
|
|
35
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
36
|
+
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
38
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
39
|
+
|
|
40
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gamemenu.hide.controls" });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("BACK, MENU and GAMEMENU emit GAMEMENU.HIDE", async () => {
|
|
44
|
+
const { module, observer } = createGameMenuTestModule(GamemenuHideControls);
|
|
45
|
+
const hide = module as GamemenuHideControls;
|
|
46
|
+
const hideEvent = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
47
|
+
|
|
48
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.BACK]();
|
|
49
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.MENU]();
|
|
50
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.GAMEMENU]();
|
|
51
|
+
await Promise.resolve();
|
|
52
|
+
await Promise.resolve();
|
|
53
|
+
await Promise.resolve();
|
|
54
|
+
|
|
55
|
+
expect(hideEvent).toHaveBeenCalledTimes(3);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
|
|
6
|
+
|
|
7
|
+
import { GamemenuHideState } from "../modules/hide.state.js";
|
|
8
|
+
|
|
9
|
+
import { createGameMenuTestModule, registerGameMenuPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
10
|
+
|
|
11
|
+
describe("GamemenuHideState", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registerGameMenuPluginVne();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("STATE.SET and STATE.CLEAR emit HIDE with isForce", async () => {
|
|
17
|
+
const { observer } = createGameMenuTestModule(GamemenuHideState);
|
|
18
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
19
|
+
|
|
20
|
+
await observer.emit(STATE_EVENTS.SET);
|
|
21
|
+
await observer.emit(STATE_EVENTS.CLEAR);
|
|
22
|
+
|
|
23
|
+
expect(hide).toHaveBeenCalledTimes(2);
|
|
24
|
+
expect(hide).toHaveBeenNthCalledWith(1, { isForce: true });
|
|
25
|
+
expect(hide).toHaveBeenNthCalledWith(2, { isForce: true });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
2
|
+
|
|
3
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
4
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
5
|
+
|
|
6
|
+
export const registerGameMenuPluginVne = () => {
|
|
7
|
+
registerCoreVne();
|
|
8
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
9
|
+
registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createGameMenuTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
13
|
+
ModuleClass: T,
|
|
14
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
15
|
+
) => {
|
|
16
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
17
|
+
state: {
|
|
18
|
+
gameMenu: { items: [], realItems: [], isShow: false },
|
|
19
|
+
...(options.state ?? {}),
|
|
20
|
+
},
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
|
|
25
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
|
|
26
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
|
|
27
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
28
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
29
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CLICK);
|
|
30
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.ITEMS);
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.gamemenu";
|
|
4
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
5
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
6
|
+
|
|
7
|
+
import type { GameMenuViewItem } from "./utils/gamemenu.js";
|
|
8
|
+
|
|
9
|
+
export type GameMenuPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StatePluginName, StateSubscribeEvents>;
|
|
10
|
+
|
|
11
|
+
export type GameMenuPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
|
|
12
|
+
|
|
13
|
+
export type GameMenuPluginSettings = ModuleComponentsSettings;
|
|
14
|
+
|
|
15
|
+
export type GameMenuPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
16
|
+
|
|
17
|
+
export type GameMenuPluginState = {
|
|
18
|
+
isShow: boolean;
|
|
19
|
+
isForce: boolean;
|
|
20
|
+
items?: GameMenuViewItem[];
|
|
21
|
+
realItems?: GameMenuViewItem[];
|
|
22
|
+
locs?: Record<string, string>;
|
|
23
|
+
currentItem?: number | null;
|
|
24
|
+
currentArrowVerticalItem?: number | null;
|
|
25
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { PositionBox, Screen, TextControls, createRenderFunc, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { GameMenuViewItem } from "../utils/gamemenu.js";
|
|
8
|
+
|
|
9
|
+
import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
|
|
10
|
+
import type { GameMenuPluginState } from "../types.js";
|
|
11
|
+
type GameMenuComponentProps = ReactComponentProps<
|
|
12
|
+
GameMenuPluginEvents,
|
|
13
|
+
GameMenuPluginConstants,
|
|
14
|
+
GameMenuPluginSettings,
|
|
15
|
+
GameMenuPluginParams,
|
|
16
|
+
GameMenuPluginState
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
const Gamemenu = ({ store, onMount, PARAMS, emit, EVENTS }: GameMenuComponentProps) => {
|
|
20
|
+
const {
|
|
21
|
+
isShow = false,
|
|
22
|
+
isForce = false,
|
|
23
|
+
items = [],
|
|
24
|
+
realItems = [],
|
|
25
|
+
locs = {},
|
|
26
|
+
currentArrowVerticalItem: currentItem = null,
|
|
27
|
+
} = useStoreState<GameMenuPluginState>(store, onMount);
|
|
28
|
+
|
|
29
|
+
const selectedKey = realItems[currentItem ?? -1]?.locKey;
|
|
30
|
+
const texts = items.map(({ locKey, isDisabled, isHided }: GameMenuViewItem, i: number) => ({
|
|
31
|
+
text: locs[locKey],
|
|
32
|
+
isDisabled,
|
|
33
|
+
isNotRender: isHided,
|
|
34
|
+
value: i,
|
|
35
|
+
}));
|
|
36
|
+
const selectedIndex = items.findIndex((value: GameMenuViewItem) => selectedKey === value?.locKey);
|
|
37
|
+
|
|
38
|
+
const propsView = PARAMS.GAMEMENU.VIEW_PROPS;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Screen
|
|
42
|
+
{...propsView.screen}
|
|
43
|
+
isShow={isShow}
|
|
44
|
+
isForce={isForce}
|
|
45
|
+
isDisableAutoread={isShow}
|
|
46
|
+
>
|
|
47
|
+
<PositionBox {...propsView.position}>
|
|
48
|
+
<TextControls
|
|
49
|
+
{...propsView.controls}
|
|
50
|
+
selectedIndex={selectedIndex >= 0 ? selectedIndex : undefined}
|
|
51
|
+
texts={texts}
|
|
52
|
+
onClick={(index?: unknown) => void emit(EVENTS.GAMEMENU.CLICK, { index: Number(index) })}
|
|
53
|
+
/>
|
|
54
|
+
</PositionBox>
|
|
55
|
+
</Screen>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const render: ViewRenderFunc<GameMenuPluginState> = createRenderFunc(Gamemenu);
|
package/tsconfig.json
ADDED
package/README.md
DELETED