@vnejs/plugins.view.coralina.interface.controls 0.1.0 → 0.1.2

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/const/events.js CHANGED
@@ -2,4 +2,5 @@ export const SUBSCRIBE_EVENTS = {
2
2
  SHOW: "vne:interface_controls:show",
3
3
  HIDE: "vne:interface_controls:hide",
4
4
  UPDATE: "vne:interface_controls:update",
5
+ CLICK: "vne:interface_controls:click",
5
6
  };
@@ -0,0 +1,23 @@
1
+ export const VIEW_PROPS = {
2
+ adv: {
3
+ icon: { width: 96, height: 96, isOpacityOnHover: true },
4
+ view: { left: 360, bottom: 24, translateX: "calc(1px * var(--vne-length-240))" },
5
+ flex: { gap: 36 },
6
+ },
7
+ line: {
8
+ icon: { width: 96, height: 96, isOpacityOnHover: true },
9
+ view: { left: 360, bottom: 24 },
10
+ flex: { gap: 36 },
11
+ },
12
+ wall: {
13
+ icon: { width: 96, height: 96, isOpacityOnHover: true },
14
+ view: { left: 360, bottom: 24 },
15
+ flex: { gap: 36 },
16
+ },
17
+ };
18
+
19
+ export const ITEMS = [
20
+ { icon: "menu", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.GAMEMENU) },
21
+ { icon: "history", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.HISTORY) },
22
+ { icon: "hide", onClick: ({ emit, EVENTS = {} } = {}) => emit(EVENTS.INTERFACE.VISIBLE) },
23
+ ];
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 { InterfaceControlsController } from "./modules/controller";
6
7
  import { InterfaceControlsView } from "./modules/view";
7
8
 
8
- regPlugin("INTERFACE_CONTROLS", { events: SUBSCRIBE_EVENTS }, [InterfaceControlsController, InterfaceControlsView]);
9
+ regPlugin("INTERFACE_CONTROLS_VIEW", { events: SUBSCRIBE_EVENTS, params }, [InterfaceControlsController, InterfaceControlsView]);
@@ -1,13 +1,11 @@
1
1
  import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- import { ZINDEX } from "../view";
4
-
5
3
  export class InterfaceControlsController extends ModuleController {
6
4
  name = "interface.controls.controller";
7
5
 
8
6
  emitGameMenu = () => this.emit(this.EVENTS.INTERFACE.GAMEMENU);
9
7
 
10
- updateEvent = this.EVENTS.INTERFACE_CONTROLS.UPDATE;
8
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
11
9
  controls = {
12
10
  [this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
13
11
  [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
@@ -19,22 +17,28 @@ export class InterfaceControlsController extends ModuleController {
19
17
  [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
20
18
  };
21
19
  controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE) };
22
- controlsIndex = ZINDEX;
20
+ controlsIndex = this.PARAMS.INTERFACE_VIEW.ZINDEX + 100;
23
21
  controlsCheckNext = true;
24
22
 
25
23
  subscribe = () => {
26
- this.on(this.EVENTS.INTERFACE_CONTROLS.SHOW, this.onShow);
27
- this.on(this.EVENTS.INTERFACE_CONTROLS.HIDE, this.onHide);
24
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW, this.onShow);
25
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE, this.onHide);
26
+ this.on(this.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, this.onClick);
28
27
 
29
28
  this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
30
29
  this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
31
30
  this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
32
31
  this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
32
+
33
+ this.on(this.EVENTS.SYSTEM.STARTED, this.getIconsSrcs);
34
+ this.on(this.EVENTS.MEMORY.CLEARED, this.getIconsSrcs);
33
35
  };
34
36
 
37
+ beforeShow = async () => this.updateState({ icons: await this.getIconsSrcs() });
38
+
35
39
  onShowChanged = ({ isForce = false } = {}) => {
36
40
  const { isShow = false } = this.globalState.interface;
37
- const event = isShow ? this.EVENTS.INTERFACE_CONTROLS.SHOW : this.EVENTS.INTERFACE_CONTROLS.HIDE;
41
+ const event = isShow ? this.EVENTS.INTERFACE_CONTROLS_VIEW.SHOW : this.EVENTS.INTERFACE_CONTROLS_VIEW.HIDE;
38
42
 
39
43
  if (this.state.isShow !== isShow) return this.emit(event, { isForce });
40
44
  };
@@ -51,6 +55,8 @@ export class InterfaceControlsController extends ModuleController {
51
55
  if (this.state.isVisible !== isVisible) return this.updateStateAndView({ isVisible }, isForce, !isForce);
52
56
  };
53
57
 
58
+ onClick = ({ index = 0 } = {}) => this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS?.[index]?.onClick(this);
59
+
54
60
  onStateChanged = () => {
55
61
  const { isShow = false, isVisible = false, view = "" } = this.globalState.interface;
56
62
 
@@ -61,8 +67,20 @@ export class InterfaceControlsController extends ModuleController {
61
67
 
62
68
  toggleUnvisibleControls = (isVisible) => {
63
69
  const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
70
+
64
71
  return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
65
72
  };
66
73
 
67
74
  getDefaultState = () => ({ isShow: false, isVisible: false, view: "" });
75
+
76
+ getIconsSrcs = () => Promise.all(this.PARAMS.INTERFACE_CONTROLS_VIEW.ITEMS.map(this.getOneIconSrcs));
77
+
78
+ getOneIconSrcs = async ({ icon = "", iconHover = "" } = {}) => {
79
+ const [result, quality] = [{}, this.shared.settings[this.SETTINGS.CANVAS.QUALITY]];
80
+
81
+ if (icon) result.src = (await this.loadImageMedia(`interface/${icon}`, "icons", quality, false, false)).src;
82
+ if (iconHover) result.srcHover = (await this.loadImageMedia(`interface/${iconHover}`, "icons", quality, false, false)).src;
83
+
84
+ return result;
85
+ };
68
86
  }
package/modules/view.js CHANGED
@@ -1,11 +1,13 @@
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 InterfaceControlsView extends ModuleView {
6
6
  name = "interface.controls.view";
7
- animationTime = TRANSITION;
7
+
8
+ animationTime = this.PARAMS.INTERFACE_VIEW.TRANSITION;
9
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS_VIEW.UPDATE;
10
+
8
11
  renderFunc = render;
9
- updateEvent = this.EVENTS.INTERFACE_CONTROLS.UPDATE;
10
- updateHandler = this.onUpdateReactComponent;
12
+ updateHandler = this.onUpdateStoreComponent;
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.view.coralina.interface.controls",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/view/index.jsx CHANGED
@@ -1,61 +1,48 @@
1
- import React from "react";
1
+ import React, { useCallback, useEffect, useMemo, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
 
4
4
  import { Flex, Icon, View } from "@vnejs/uis.base";
5
5
 
6
- import settingsSrc from "./images/Settings.png";
7
- import historySrc from "./images/History.png";
8
- import hideSrc from "./images/Hide.png";
9
-
10
- export const TRANSITION = 500;
11
- export const ZINDEX = 1100;
12
-
13
- const ICON_COMMON_PROPS = { width: 96, height: 96, isOpacityOnHover: true };
14
-
15
- class InterfaceControls extends React.Component {
16
- state = { isShow: false, isVisible: false, isForce: false, view: "" };
17
-
18
- onHistoryClick = () => this.props.emit(this.props.EVENTS.INTERFACE.HISTORY);
19
- onGameMenuClick = () => this.props.emit(this.props.EVENTS.INTERFACE.GAMEMENU);
20
- onHideClick = () => this.props.emit(this.props.EVENTS.INTERFACE.VISIBLE);
21
- render() {
22
- const { isShow = false, isVisible = false, isForce = false, view = "" } = this.state;
23
-
24
- const left = view === "adv" ? 600 : 360;
25
-
26
- return (
27
- <View
28
- isShow={isShow}
29
- isForce={isForce}
30
- isHidden={!isVisible}
31
- transition={TRANSITION}
32
- zIndex={ZINDEX}
33
- left={left}
34
- bottom={24}
35
- >
36
- <Flex gap={36}>
37
- <Icon
38
- {...ICON_COMMON_PROPS}
39
- transition={isForce ? 0 : TRANSITION}
40
- src={settingsSrc}
41
- onClick={this.onGameMenuClick}
42
- />
43
- <Icon
44
- {...ICON_COMMON_PROPS}
45
- transition={isForce ? 0 : TRANSITION}
46
- src={historySrc}
47
- onClick={this.onHistoryClick}
48
- />
49
- <Icon
50
- {...ICON_COMMON_PROPS}
51
- transition={isForce ? 0 : TRANSITION}
52
- src={hideSrc}
53
- onClick={this.onHideClick}
54
- />
55
- </Flex>
56
- </View>
57
- );
58
- }
59
- }
60
-
61
- export const render = (props, root, resolve) => ReactDOM.render(<InterfaceControls {...props} />, root, resolve);
6
+ const InterfaceControls = ({ store, onMount, ...props } = {}) => {
7
+ const [{ isShow = false, isVisible = false, isForce = false, view = "", icons = [] }, setState] = useState({});
8
+
9
+ useEffect(() => store.subscribe(setState), []);
10
+ useEffect(() => void onMount(), []);
11
+
12
+ const onItemClick = useCallback((index = 0) => props.emit(props.EVENTS.INTERFACE_CONTROLS_VIEW.CLICK, { index }), []);
13
+
14
+ const transition = isForce ? 0 : props.PARAMS.INTERFACE_VIEW.TRANSITION;
15
+
16
+ const propsByView = useMemo(() => props.PARAMS.INTERFACE_CONTROLS_VIEW.VIEW_PROPS[view] || {}, [view]);
17
+ const propsIcon = useMemo(() => ({ ...propsByView.icon, transition }), [propsByView, transition]);
18
+
19
+ const renderedIcons = useMemo(
20
+ () =>
21
+ icons.map(({ src, srcHover }, i) => (
22
+ <Icon
23
+ {...propsIcon}
24
+ srcHover={srcHover}
25
+ src={src}
26
+ onClick={onItemClick}
27
+ value={i}
28
+ key={i}
29
+ />
30
+ )),
31
+ [propsIcon, icons],
32
+ );
33
+
34
+ return (
35
+ <View
36
+ {...propsByView.view}
37
+ isShow={isShow}
38
+ isForce={isForce}
39
+ isHidden={!isVisible}
40
+ transition={transition}
41
+ zIndex={props.PARAMS.INTERFACE_VIEW.ZINDEX + 100}
42
+ >
43
+ <Flex {...propsByView.flex}>{renderedIcons}</Flex>
44
+ </View>
45
+ );
46
+ };
47
+
48
+ export const render = (props, root) => ReactDOM.render(<InterfaceControls {...props} />, root);
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file