@vnejs/plugins.view.coralina.gamemenu 0.1.0 → 0.1.1

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,9 @@
1
+ export const TRANSITION = 500;
2
+ export const ZINDEX = 3000;
3
+ export const LOC_LABEL = "gameMenu";
4
+
5
+ export const VIEW_PROPS = {
6
+ screen: { isIgnoreOnScreenshot: true, withBackgroundBlur: true, withBackgroundDark: true, zIndex: ZINDEX, transition: TRANSITION },
7
+ position: { isCentered: true },
8
+ controls: { flexDirection: "column", flexGap: 60, textSize: 96, textAlign: "center" },
9
+ };
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
4
+ import * as params from "./const/params";
4
5
 
5
6
  import { GameMenuController } from "./modules/controller";
6
7
  import { GameMenuView } from "./modules/view";
7
8
 
8
- regPlugin("GAMEMENU_VIEW", { events: SUBSCRIBE_EVENTS }, [GameMenuController, GameMenuView]);
9
+ regPlugin("GAMEMENU_VIEW", { events: SUBSCRIBE_EVENTS, params }, [GameMenuController, GameMenuView]);
@@ -1,7 +1,5 @@
1
1
  import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- import { ZINDEX } from "../view";
4
-
5
3
  const toStateItem = ({ onClick, ...item }) => item;
6
4
  const onRealItems = (item) => !item.isDisabled && !item.isHide;
7
5
 
@@ -17,7 +15,7 @@ export class GameMenuController extends ModuleController {
17
15
  [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decCurrentItem,
18
16
  [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incCurrentItem,
19
17
  };
20
- controlsIndex = ZINDEX;
18
+ controlsIndex = this.PARAMS.GAMEMENU_VIEW.ZINDEX;
21
19
 
22
20
  subscribe = () => {
23
21
  this.on(this.EVENTS.GAMEMENU_VIEW.CLICK, this.onClick);
package/modules/view.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { ModuleView } from "@vnejs/module.components";
2
2
 
3
- import { render, TRANSITION } from "../view";
3
+ import { render } from "../view";
4
4
 
5
5
  export class GameMenuView extends ModuleView {
6
6
  name = "gameMenu.view";
7
- locLabel = "gameMenu";
8
- animationTime = TRANSITION;
9
- renderFunc = render;
7
+
8
+ locLabel = this.PARAMS.GAMEMENU_VIEW.LOC_LABEL;
9
+ animationTime = this.PARAMS.GAMEMENU_VIEW.TRANSITION;
10
10
  updateEvent = this.EVENTS.GAMEMENU_VIEW.UPDATE;
11
- updateHandler = this.onUpdateReactComponent;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.gamemenu",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/view/index.jsx CHANGED
@@ -1,57 +1,33 @@
1
- import React from "react";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
- import { Flex, PositionBox, Screen, Text, TextControls } from "@vnejs/uis.base";
5
-
6
- export const TRANSITION = 500;
7
- export const ZINDEX = 3000;
8
-
9
- class GameMenu extends React.Component {
10
- state = { isShow: false, isForce: false, items: [], texts: [], currentItem: null, locs: {} };
11
-
12
- componentDidUpdate(props, state) {
13
- if (state.items !== this.state.items || state.locs !== this.state.locs) {
14
- this.setState({
15
- texts: this.state.items.map(({ locKey, isDisabled, isHide }, i) => ({
16
- isDisabled,
17
- isNotRender: isHide,
18
- value: i,
19
- text: this.state.locs[locKey],
20
- })),
21
- });
22
- }
23
- }
24
-
25
- onClick = (index) => this.props.emit(this.props.EVENTS.GAMEMENU_VIEW.CLICK, { index });
26
-
27
- render() {
28
- const { isShow = false, isForce = false, texts = [], currentItem = null } = this.state;
29
-
30
- return (
31
- <Screen
32
- isShow={isShow}
33
- isForce={isForce}
34
- zIndex={ZINDEX}
35
- transition={TRANSITION}
36
- isDisableAutoread={isShow}
37
- isIgnoreOnScreenshot={true}
38
- withBlur={true}
39
- withDark={true}
40
- >
41
- <PositionBox isCentered={true}>
42
- <TextControls
43
- selectedIndex={currentItem}
44
- flexDirection={Flex.DIRECTION.COLUMN}
45
- flexGap={60}
46
- textSize={96}
47
- textAlign={Text.ALIGNS.CENTER}
48
- texts={texts}
49
- onClick={this.onClick}
50
- />
51
- </PositionBox>
52
- </Screen>
53
- );
54
- }
55
- }
56
-
57
- export const render = (props, root, resolve) => ReactDOM.render(<GameMenu {...props} />, root, resolve);
4
+ import { PositionBox, Screen, TextControls } from "@vnejs/uis.base";
5
+
6
+ const EMPTY_ARRAY = [];
7
+ const EMPTY_OBJ = {};
8
+
9
+ const GameMenu = ({ store, onMount, ...props } = {}) => {
10
+ const [{ isShow = false, isForce = false, items = EMPTY_ARRAY, locs = EMPTY_OBJ, currentItem: selectedIndex = null }, setState] = useState({});
11
+ const [texts, setTexts] = useState([]);
12
+
13
+ useEffect(() => store.subscribe(setState), []);
14
+ useEffect(() => void onMount(), []);
15
+
16
+ const onClick = useCallback((index) => props.emit(props.EVENTS.GAMEMENU_VIEW.CLICK, { index }), []);
17
+ const mapItemsToText = useCallback(({ locKey, isDisabled, isHide }, i) => ({ isDisabled, isNotRender: isHide, value: i, text: locs[locKey] }), [locs]);
18
+
19
+ useEffect(() => void setTexts(items.map(mapItemsToText)), [items, mapItemsToText]);
20
+
21
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.screen, isShow, isForce, isDisableAutoread: isShow }), [isShow, isForce]);
22
+ const propsControls = useMemo(() => ({ ...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
23
+
24
+ return (
25
+ <Screen {...propsScreen}>
26
+ <PositionBox {...props.PARAMS.GAMEMENU_VIEW.VIEW_PROPS.position}>
27
+ <TextControls {...propsControls} />
28
+ </PositionBox>
29
+ </Screen>
30
+ );
31
+ };
32
+
33
+ export const render = (props, root) => ReactDOM.render(<GameMenu {...props} />, root);