@vnejs/plugins.views.screens.gamemenu 0.1.4 → 0.1.6

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.
@@ -0,0 +1 @@
1
+ import "@vnejs/plugins.views.screens.gamemenu.contract";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import "@vnejs/plugins.views.screens.gamemenu.contract";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.gamemenu.contract";
4
+ import { GameMenuController } from "./modules/controller.js";
5
+ import { GameMenu } from "./modules/gamemenu.js";
6
+ import { GameMenuView } from "./modules/view.js";
7
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [GameMenuController, GameMenu, GameMenuView]);
@@ -0,0 +1,22 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
3
+ import type { GameMenuPluginState } from "../utils/gamemenu.js";
4
+ export declare class GameMenuController extends ModuleController<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
5
+ name: string;
6
+ updateEvent: "vne:gamemenu:update";
7
+ controls: {
8
+ abstract_back: () => undefined;
9
+ abstract_menu: () => undefined;
10
+ abstract_gamemenu: () => undefined;
11
+ abstract_accept: () => undefined;
12
+ abstract_arrow_up: () => undefined;
13
+ abstract_arrow_bottom: () => undefined;
14
+ };
15
+ controlsIndex: number;
16
+ subscribe: () => void;
17
+ beforeShow: () => Promise<void>;
18
+ afterHide: () => void;
19
+ onAccept: () => undefined;
20
+ onLangChanged: () => Promise<unknown[] | undefined>;
21
+ updateStateItems: () => void;
22
+ }
@@ -0,0 +1,37 @@
1
+ import { isNotDisabledNotHided, omitOnClick } from "@vnejs/helpers";
2
+ import { ModuleController } from "@vnejs/module.components";
3
+ export class GameMenuController extends ModuleController {
4
+ name = "gameMenu.controller";
5
+ updateEvent = this.EVENTS.GAMEMENU.UPDATE;
6
+ controls = {
7
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
8
+ [this.CONST.CONTROLS.BUTTONS.MENU]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
9
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
10
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.emit(this.EVENTS.GAMEMENU.ACCEPT),
11
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decCurrentItem(),
12
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incCurrentItem(),
13
+ };
14
+ controlsIndex = this.PARAMS.GAMEMENU.ZINDEX;
15
+ subscribe = () => {
16
+ this.on(this.EVENTS.GAMEMENU.SHOW, this.onShow);
17
+ this.on(this.EVENTS.GAMEMENU.HIDE, this.onHide);
18
+ this.on(this.EVENTS.GAMEMENU.ACCEPT, this.onAccept);
19
+ this.on(this.EVENTS.LOCS.CHANGED, this.onLangChanged);
20
+ this.on(this.EVENTS.STATE.SET, this.onHideForce);
21
+ this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
22
+ };
23
+ beforeShow = async () => {
24
+ this.updateStateItems();
25
+ this.maxCurrentItem = this.state.realItems.length - 1;
26
+ };
27
+ afterHide = () => this.setDefaultState();
28
+ onAccept = () => void this.emit(this.EVENTS.GAMEMENU.CLICK, { index: this.currentItem });
29
+ onLangChanged = async () => {
30
+ this.updateStateItems();
31
+ return this.updateViewFast();
32
+ };
33
+ updateStateItems = () => {
34
+ const items = this.PARAMS.GAMEMENU.ITEMS.map(omitOnClick);
35
+ this.updateState({ items, realItems: items.filter((item) => isNotDisabledNotHided(item)) });
36
+ };
37
+ }
@@ -0,0 +1,8 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
3
+ import type { GameMenuClickPayload } from "../utils/gamemenu.js";
4
+ export declare class GameMenu extends Module<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onClick: ({ index }?: GameMenuClickPayload) => void | Promise<void>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { Module } from "@vnejs/module";
2
+ export class GameMenu extends Module {
3
+ name = "gameMenu";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.GAMEMENU.CLICK, this.onClick);
6
+ };
7
+ onClick = ({ index = 0 } = {}) => this.PARAMS.GAMEMENU.ITEMS[index].onClick(this);
8
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
3
+ import type { GameMenuPluginState } from "../utils/gamemenu.js";
4
+ export declare class GameMenuView extends ModuleView<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams, GameMenuPluginState> {
5
+ name: string;
6
+ locLabel: string;
7
+ animationTime: number;
8
+ updateEvent: "vne:gamemenu:update";
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<GameMenuPluginState>;
10
+ updateHandler: (state?: GameMenuPluginState | undefined) => Promise<void>;
11
+ }
@@ -0,0 +1,10 @@
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
+ locLabel = this.PARAMS.GAMEMENU.LOC_LABEL;
6
+ animationTime = this.PARAMS.GAMEMENU.TRANSITION;
7
+ updateEvent = this.EVENTS.GAMEMENU.UPDATE;
8
+ renderFunc = render;
9
+ updateHandler = this.onUpdateStoreComponent;
10
+ }
@@ -0,0 +1,9 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/plugins.controls.contract";
3
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
4
+ import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/plugins.text.locs.contract";
5
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.screens.gamemenu.contract";
6
+ export type GameMenuPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<LocsPluginName, LocsSubscribeEvents>;
7
+ export type GameMenuPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
8
+ export type GameMenuPluginSettings = ModuleComponentsSettings;
9
+ export type GameMenuPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { GameMenuItem } from "@vnejs/plugins.views.screens.gamemenu.contract";
2
+ export type GameMenuViewItem = Omit<GameMenuItem, "onClick">;
3
+ export type GameMenuPluginState = {
4
+ isShow: boolean;
5
+ isForce: boolean;
6
+ items?: GameMenuViewItem[];
7
+ realItems?: GameMenuViewItem[];
8
+ locs?: Record<string, string>;
9
+ currentItem?: number | null;
10
+ };
11
+ export type GameMenuClickPayload = {
12
+ index?: number;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { GameMenuPluginState } from "../utils/gamemenu.js";
3
+ export declare const render: ViewRenderFunc<GameMenuPluginState>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PositionBox, Screen, TextControls, createRenderFunc, useCallback, useMemo, useStoreState } from "@vnejs/uis.react";
3
+ const GameMenu = ({ store, onMount, PARAMS, emit, EVENTS }) => {
4
+ const { isShow = false, isForce = false, items = [], locs = {}, currentItem: selectedIndex = null } = useStoreState(store, onMount);
5
+ const onClick = useCallback((index) => void emit(EVENTS.GAMEMENU.CLICK, { index: Number(index) }), [emit, EVENTS.GAMEMENU.CLICK]);
6
+ const mapItemsToText = useCallback(({ locKey }, i) => ({ value: i, text: locs[locKey] }), [locs]);
7
+ const texts = useMemo(() => items.map(mapItemsToText), [items, mapItemsToText]);
8
+ const propsView = PARAMS.GAMEMENU.VIEW_PROPS;
9
+ const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce, isDisableAutoread: isShow }), [isShow, isForce, propsView.screen]);
10
+ const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex: selectedIndex ?? undefined, texts, onClick }), [propsView.controls, selectedIndex, texts, onClick]);
11
+ return (_jsx(Screen, { ...propsScreen, children: _jsx(PositionBox, { ...propsView.position, children: _jsx(TextControls, { ...propsControls }) }) }));
12
+ };
13
+ export const render = createRenderFunc(GameMenu);
package/package.json CHANGED
@@ -1,17 +1,48 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.screens.gamemenu",
3
- "version": "0.1.4",
4
- "main": "index.js",
3
+ "version": "0.1.6",
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
+ ],
5
20
  "scripts": {
6
21
  "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
7
23
  "publish:major:plugin": "npm run publish:major",
8
24
  "publish:minor:plugin": "npm run publish:minor",
9
25
  "publish:patch:plugin": "npm run publish:patch",
10
- "publish:major": "npm version major && npm publish --access public",
11
- "publish:minor": "npm version minor && npm publish --access public",
12
- "publish:patch": "npm version patch && npm publish --access public"
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"
13
29
  },
14
30
  "author": "",
15
31
  "license": "ISC",
16
- "description": ""
32
+ "dependencies": {
33
+ "@vnejs/plugins.views.screens.gamemenu.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.1.0",
37
+ "@vnejs/module": "~0.0.1",
38
+ "@vnejs/module.components": "~0.0.1",
39
+ "@vnejs/plugins.controls.contract": "~0.0.1",
40
+ "@vnejs/plugins.core.state.contract": "~0.0.1",
41
+ "@vnejs/plugins.text.locs.contract": "~0.0.1",
42
+ "@vnejs/shared": "~0.0.9",
43
+ "@vnejs/uis.react": "~0.1.0"
44
+ },
45
+ "devDependencies": {
46
+ "@vnejs/configs.ts-common": "~0.0.1"
47
+ }
17
48
  }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import "@vnejs/plugins.views.screens.gamemenu.contract";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.gamemenu.contract";
5
+
6
+ import { GameMenuController } from "./modules/controller.js";
7
+ import { GameMenu } from "./modules/gamemenu.js";
8
+ import { GameMenuView } from "./modules/view.js";
9
+
10
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [GameMenuController, GameMenu, GameMenuView]);
@@ -0,0 +1,58 @@
1
+ import { isNotDisabledNotHided, omitOnClick } from "@vnejs/helpers";
2
+ import { ModuleController } from "@vnejs/module.components";
3
+
4
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
5
+ import type { GameMenuPluginState } from "../utils/gamemenu.js";
6
+
7
+ export class GameMenuController extends ModuleController<
8
+ GameMenuPluginEvents,
9
+ GameMenuPluginConstants,
10
+ GameMenuPluginSettings,
11
+ GameMenuPluginParams,
12
+ GameMenuPluginState
13
+ > {
14
+ name = "gameMenu.controller";
15
+
16
+ updateEvent = this.EVENTS.GAMEMENU.UPDATE;
17
+ controls = {
18
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
19
+ [this.CONST.CONTROLS.BUTTONS.MENU]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
20
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => void this.emit(this.EVENTS.GAMEMENU.HIDE),
21
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.emit(this.EVENTS.GAMEMENU.ACCEPT),
22
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decCurrentItem(),
23
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incCurrentItem(),
24
+ };
25
+ controlsIndex = this.PARAMS.GAMEMENU.ZINDEX;
26
+
27
+ subscribe = () => {
28
+ this.on(this.EVENTS.GAMEMENU.SHOW, this.onShow);
29
+ this.on(this.EVENTS.GAMEMENU.HIDE, this.onHide);
30
+ this.on(this.EVENTS.GAMEMENU.ACCEPT, this.onAccept);
31
+
32
+ this.on(this.EVENTS.LOCS.CHANGED, this.onLangChanged);
33
+
34
+ this.on(this.EVENTS.STATE.SET, this.onHideForce);
35
+ this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
36
+ };
37
+
38
+ beforeShow = async () => {
39
+ this.updateStateItems();
40
+
41
+ this.maxCurrentItem = this.state.realItems!.length - 1;
42
+ };
43
+ afterHide = () => this.setDefaultState();
44
+
45
+ onAccept = () => void this.emit(this.EVENTS.GAMEMENU.CLICK, { index: this.currentItem! });
46
+
47
+ onLangChanged = async () => {
48
+ this.updateStateItems();
49
+
50
+ return this.updateViewFast();
51
+ };
52
+
53
+ updateStateItems = () => {
54
+ const items = this.PARAMS.GAMEMENU.ITEMS.map(omitOnClick);
55
+
56
+ this.updateState({ items, realItems: items.filter((item) => isNotDisabledNotHided(item as Parameters<typeof isNotDisabledNotHided>[0])) });
57
+ };
58
+ }
@@ -0,0 +1,14 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
4
+ import type { GameMenuClickPayload } from "../utils/gamemenu.js";
5
+
6
+ export class GameMenu extends Module<GameMenuPluginEvents, GameMenuPluginConstants, GameMenuPluginSettings, GameMenuPluginParams> {
7
+ name = "gameMenu";
8
+
9
+ subscribe = () => {
10
+ this.on(this.EVENTS.GAMEMENU.CLICK, this.onClick);
11
+ };
12
+
13
+ onClick = ({ index = 0 }: GameMenuClickPayload = {}) => this.PARAMS.GAMEMENU.ITEMS[index].onClick(this);
14
+ }
@@ -0,0 +1,22 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view/index.js";
4
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
5
+ import type { GameMenuPluginState } from "../utils/gamemenu.js";
6
+
7
+ export class GameMenuView extends ModuleView<
8
+ GameMenuPluginEvents,
9
+ GameMenuPluginConstants,
10
+ GameMenuPluginSettings,
11
+ GameMenuPluginParams,
12
+ GameMenuPluginState
13
+ > {
14
+ name = "gameMenu.view";
15
+
16
+ locLabel = this.PARAMS.GAMEMENU.LOC_LABEL;
17
+ animationTime = this.PARAMS.GAMEMENU.TRANSITION;
18
+ updateEvent = this.EVENTS.GAMEMENU.UPDATE;
19
+
20
+ renderFunc = render;
21
+ updateHandler = this.onUpdateStoreComponent;
22
+ }
package/src/types.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/plugins.controls.contract";
3
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
4
+ import type { PluginName as LocsPluginName, SubscribeEvents as LocsSubscribeEvents } from "@vnejs/plugins.text.locs.contract";
5
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.screens.gamemenu.contract";
6
+
7
+ export type GameMenuPluginEvents = ModuleComponentsEvents &
8
+ Record<PluginName, SubscribeEvents> &
9
+ Record<StatePluginName, StateSubscribeEvents> &
10
+ Record<LocsPluginName, LocsSubscribeEvents>;
11
+
12
+ export type GameMenuPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
13
+
14
+ export type GameMenuPluginSettings = ModuleComponentsSettings;
15
+
16
+ export type GameMenuPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
@@ -0,0 +1,16 @@
1
+ import type { GameMenuItem } from "@vnejs/plugins.views.screens.gamemenu.contract";
2
+
3
+ export type GameMenuViewItem = Omit<GameMenuItem, "onClick">;
4
+
5
+ export type GameMenuPluginState = {
6
+ isShow: boolean;
7
+ isForce: boolean;
8
+ items?: GameMenuViewItem[];
9
+ realItems?: GameMenuViewItem[];
10
+ locs?: Record<string, string>;
11
+ currentItem?: number | null;
12
+ };
13
+
14
+ export type GameMenuClickPayload = {
15
+ index?: number;
16
+ };
@@ -0,0 +1,41 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ReactComponentProps } from "@vnejs/uis.react";
3
+ import { PositionBox, Screen, TextControls, createRenderFunc, useCallback, useMemo, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { GameMenuPluginConstants, GameMenuPluginEvents, GameMenuPluginParams, GameMenuPluginSettings } from "../types.js";
6
+ import type { GameMenuPluginState, GameMenuViewItem } from "../utils/gamemenu.js";
7
+
8
+ type GameMenuComponentProps = ReactComponentProps<
9
+ GameMenuPluginEvents,
10
+ GameMenuPluginConstants,
11
+ GameMenuPluginSettings,
12
+ GameMenuPluginParams,
13
+ GameMenuPluginState
14
+ >;
15
+
16
+ const GameMenu = ({ store, onMount, PARAMS, emit, EVENTS }: GameMenuComponentProps) => {
17
+ const { isShow = false, isForce = false, items = [], locs = {}, currentItem: selectedIndex = null } = useStoreState<GameMenuPluginState>(store, onMount);
18
+
19
+ const onClick = useCallback((index?: unknown) => void emit(EVENTS.GAMEMENU.CLICK, { index: Number(index) }), [emit, EVENTS.GAMEMENU.CLICK]);
20
+ const mapItemsToText = useCallback(({ locKey }: GameMenuViewItem, i: number) => ({ value: i, text: locs[locKey] }), [locs]);
21
+
22
+ const texts = useMemo(() => items.map(mapItemsToText), [items, mapItemsToText]);
23
+
24
+ const propsView = PARAMS.GAMEMENU.VIEW_PROPS;
25
+
26
+ const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce, isDisableAutoread: isShow }), [isShow, isForce, propsView.screen]);
27
+ const propsControls = useMemo(
28
+ () => ({ ...propsView.controls, selectedIndex: selectedIndex ?? undefined, texts, onClick }),
29
+ [propsView.controls, selectedIndex, texts, onClick],
30
+ );
31
+
32
+ return (
33
+ <Screen {...propsScreen}>
34
+ <PositionBox {...propsView.position}>
35
+ <TextControls {...propsControls} />
36
+ </PositionBox>
37
+ </Screen>
38
+ );
39
+ };
40
+
41
+ export const render: ViewRenderFunc<GameMenuPluginState> = createRenderFunc(GameMenu);
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "jsx": "react-jsx"
7
+ },
8
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
9
+ "exclude": ["dist", "node_modules"]
10
+ }
package/const/events.js DELETED
@@ -1,11 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- SHOW: "vne:gamemenu:show",
3
- HIDE: "vne:gamemenu:hide",
4
-
5
- ITEMS: "vne:gamemenu:items",
6
- CLICK: "vne:gamemenu:click",
7
-
8
- UPDATE: "vne:gamemenu:update",
9
-
10
- ACCEPT: "vne:gamemenu:accept",
11
- };
package/const/params.js DELETED
@@ -1,11 +0,0 @@
1
- export const ITEMS = [];
2
-
3
- export const TRANSITION = 500;
4
- export const ZINDEX = 3000;
5
- export const LOC_LABEL = "gameMenu";
6
-
7
- export const VIEW_PROPS = {
8
- screen: { isIgnoreOnScreenshot: true, withBlur: true, withDark: true, zIndex: ZINDEX, transition: TRANSITION },
9
- position: { isCentered: true },
10
- controls: { flexDirection: "column", flexGap: 60, textSize: 96, textAlign: "center" },
11
- };
package/index.js DELETED
@@ -1,10 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import { SUBSCRIBE_EVENTS } from "./const/events";
4
- import * as params from "./const/params";
5
-
6
- import { GameMenuController } from "./modules/controller";
7
- import { GameMenu } from "./modules/gamemenu";
8
- import { GameMenuView } from "./modules/view";
9
-
10
- regPlugin("GAMEMENU", { events: SUBSCRIBE_EVENTS, params }, [GameMenuController, GameMenu, GameMenuView]);
@@ -1,49 +0,0 @@
1
- import { ModuleController } from "@vnejs/module.components";
2
- import { isNotDisabledNotHided, omitOnClick } from "@vnejs/helpers";
3
-
4
- export class GameMenuController extends ModuleController {
5
- name = "gameMenu.controller";
6
-
7
- updateEvent = this.EVENTS.GAMEMENU.UPDATE;
8
- controls = {
9
- [this.CONST.CONTROLS.BUTTONS.BACK]: () => this.emit(this.EVENTS.GAMEMENU.HIDE),
10
- [this.CONST.CONTROLS.BUTTONS.MENU]: () => this.emit(this.EVENTS.GAMEMENU.HIDE),
11
- [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => this.emit(this.EVENTS.GAMEMENU.HIDE),
12
- [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => this.emit(this.EVENTS.GAMEMENU.ACCEPT),
13
- [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
14
- [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
15
- };
16
- controlsIndex = this.PARAMS.GAMEMENU.ZINDEX;
17
-
18
- subscribe = () => {
19
- this.on(this.EVENTS.GAMEMENU.SHOW, this.onShow);
20
- this.on(this.EVENTS.GAMEMENU.HIDE, this.onHide);
21
- this.on(this.EVENTS.GAMEMENU.ACCEPT, this.onAccept);
22
-
23
- this.on(this.EVENTS.LOCS.CHANGED, this.onLangChanged);
24
-
25
- this.on(this.EVENTS.STATE.SET, this.onHideForce);
26
- this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
27
- };
28
-
29
- beforeShow = async () => {
30
- this.updateStateItems();
31
-
32
- this.maxCurrentItem = this.state.realItems.length - 1;
33
- };
34
- afterHide = () => this.setDefaultState();
35
-
36
- onAccept = () => this.emit(this.EVENTS.GAMEMENU.CLICK, { index: this.currentItem });
37
-
38
- onLangChanged = async () => {
39
- this.updateStateItems();
40
-
41
- return this.updateViewFast();
42
- };
43
-
44
- updateStateItems = () => {
45
- const items = this.PARAMS.GAMEMENU.ITEMS.map(omitOnClick);
46
-
47
- this.updateState({ items, realItems: items.filter(isNotDisabledNotHided) });
48
- };
49
- }
@@ -1,11 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- export class GameMenu extends Module {
4
- name = "gameMenu";
5
-
6
- subscribe = () => {
7
- this.on(this.EVENTS.GAMEMENU.CLICK, this.onClick);
8
- };
9
-
10
- onClick = ({ index = 0 } = {}) => this.PARAMS.GAMEMENU.ITEMS[index].onClick(this);
11
- }
package/modules/view.js DELETED
@@ -1,14 +0,0 @@
1
- import { ModuleView } from "@vnejs/module.components";
2
-
3
- import { render } from "../view";
4
-
5
- export class GameMenuView extends ModuleView {
6
- name = "gameMenu.view";
7
-
8
- locLabel = this.PARAMS.GAMEMENU.LOC_LABEL;
9
- animationTime = this.PARAMS.GAMEMENU.TRANSITION;
10
- updateEvent = this.EVENTS.GAMEMENU.UPDATE;
11
-
12
- renderFunc = render;
13
- updateHandler = this.onUpdateStoreComponent;
14
- }
package/view/index.jsx DELETED
@@ -1,31 +0,0 @@
1
- import { useCallback, useEffect, useMemo, useState } from "react";
2
- import { createRoot } from "react-dom/client";
3
-
4
- import { PositionBox, Screen, TextControls } from "@vnejs/uis.react";
5
-
6
- const GameMenu = ({ store, onMount, ...props } = {}) => {
7
- const [{ isShow = false, isForce = false, items = [], locs = {}, currentItem: selectedIndex = null }, setState] = useState({});
8
-
9
- useEffect(() => store.subscribe(setState), []);
10
- useEffect(() => void onMount(), []);
11
-
12
- const onClick = useCallback((index) => props.emit(props.EVENTS.GAMEMENU.CLICK, { index }), []);
13
- const mapItemsToText = useCallback(({ locKey }, i) => ({ value: i, text: locs[locKey] }), [locs]);
14
-
15
- const texts = useMemo(() => items.map(mapItemsToText), [items, mapItemsToText]);
16
-
17
- const propsView = props.PARAMS.GAMEMENU.VIEW_PROPS;
18
-
19
- const propsScreen = useMemo(() => ({ ...propsView.screen, isShow, isForce, isDisableAutoread: isShow }), [isShow, isForce]);
20
- const propsControls = useMemo(() => ({ ...propsView.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
21
-
22
- return (
23
- <Screen {...propsScreen}>
24
- <PositionBox {...propsView.position}>
25
- <TextControls {...propsControls} />
26
- </PositionBox>
27
- </Screen>
28
- );
29
- };
30
-
31
- export const render = (props, root) => createRoot(root).render(<GameMenu {...props} />);