@vnejs/plugins.views.screens.gamemenu 0.1.4

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,11 @@
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
+ };
@@ -0,0 +1,11 @@
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 ADDED
@@ -0,0 +1,10 @@
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]);
@@ -0,0 +1,49 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,14 @@
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/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.screens.gamemenu",
3
+ "version": "0.1.4",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "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"
13
+ },
14
+ "author": "",
15
+ "license": "ISC",
16
+ "description": ""
17
+ }
package/view/index.jsx ADDED
@@ -0,0 +1,31 @@
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} />);