@vnejs/plugins.view.coralina.interface.controls 0.0.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.
package/const/const.js ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ SHOW: "vne:interface_controls:show",
3
+ HIDE: "vne:interface_controls:hide",
4
+ UPDATE: "vne:interface_controls:update",
5
+ };
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import { SUBSCRIBE_EVENTS } from "./const/events";
4
+
5
+ import { InterfaceControlsController } from "./modules/controller";
6
+ import { InterfaceControlsView } from "./modules/view";
7
+
8
+ regPlugin("INTERFACE_CONTROLS", { events: SUBSCRIBE_EVENTS }, [InterfaceControlsController, InterfaceControlsView]);
@@ -0,0 +1,48 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class InterfaceControlsController extends Module.Controller {
4
+ name = "interface.controls.controller";
5
+
6
+ emitGameMenu = () => this.emit(this.EVENTS.INTERFACE.GAMEMENU);
7
+
8
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS.UPDATE;
9
+ controls = {
10
+ [this.CONST.CONTROLS.BUTTONS.MENU]: this.emitGameMenu,
11
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitGameMenu,
12
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => this.emit(this.EVENTS.INTERFACE.HISTORY),
13
+ [this.CONST.CONTROLS.BUTTONS.INTERFACE_HIDE]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
14
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => this.emit(this.EVENTS.INTERFACE.INTERACT),
15
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => this.emit(this.EVENTS.INTERFACE.HISTORY_BACK),
16
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => this.emit(this.EVENTS.INTERFACE.HISTORY),
17
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE),
18
+ };
19
+ controlsUnvisible = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERFACE.VISIBLE) };
20
+ controlsIndex = 1100;
21
+ controlsCheckNext = true;
22
+
23
+ subscribe = () => {
24
+ this.on(this.EVENTS.INTERFACE_CONTROLS.SHOW, this.onShow);
25
+ this.on(this.EVENTS.INTERFACE_CONTROLS.HIDE, this.onHide);
26
+
27
+ this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
28
+ this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisible);
29
+ };
30
+
31
+ onShowChanged = ({ force = false } = {}) => {
32
+ const { isShow = false } = this.globalState.interface;
33
+ const event = isShow ? this.EVENTS.INTERFACE_CONTROLS.SHOW : this.EVENTS.INTERFACE_CONTROLS.HIDE;
34
+
35
+ if (this.state.isShow !== isShow) return this.emit(event, { force });
36
+ };
37
+ onVisible = async ({ force = false } = {}) => {
38
+ const { isVisible = false } = this.globalState.interface;
39
+
40
+ if (this.state.isVisible === isVisible) return;
41
+
42
+ const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
43
+ await this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
44
+ await this.updateStateAndView({ isVisible }, force, !force);
45
+ };
46
+
47
+ getDefaultState = () => ({ isShow: false, isVisible: false });
48
+ }
@@ -0,0 +1,11 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class InterfaceControlsView extends Module.View {
6
+ name = "interface.controls.view";
7
+ animationTime = 500;
8
+ renderFunc = render;
9
+ updateEvent = this.EVENTS.INTERFACE_CONTROLS.UPDATE;
10
+ updateHandler = this.onUpdateReactComponent;
11
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@vnejs/plugins.view.coralina.interface.controls",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major": "npm version major && npm publish --access public",
8
+ "publish:minor": "npm version minor && npm publish --access public",
9
+ "publish:patch": "npm version patch && npm publish --access public"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "description": "",
14
+ "peerDependencies": {
15
+ "@vnejs/shared": "*",
16
+ "@vnejs/module": "*"
17
+ }
18
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/view/index.jsx ADDED
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+
4
+ import { cn } from "@bem-react/classname";
5
+
6
+ import "./index.styl";
7
+
8
+ const b = cn("InterfaceControls");
9
+
10
+ class InterfaceControls extends React.Component {
11
+ state = {};
12
+ onInterfaceClick = () => this.props.emit(this.props.EVENTS.INTERFACE.INTERACT);
13
+ emitEvent = (e, event) => {
14
+ e.stopPropagation();
15
+ this.props.emit(event);
16
+ };
17
+ onHistoryClick = (e) => this.emitEvent(e, this.props.EVENTS.INTERFACE.HISTORY);
18
+ onGameMenuClick = (e) => this.emitEvent(e, this.props.EVENTS.INTERFACE.GAMEMENU);
19
+ onHideClick = (e) => this.emitEvent(e, this.props.EVENTS.INTERFACE.VISIBLE);
20
+ render() {
21
+ const { isShow = false, isVisible = false, isForce = false } = this.state;
22
+
23
+ return (
24
+ <div
25
+ className={b({ isShow, isVisible, isForce })}
26
+ id="InterfaceControls"
27
+ vne-autoread-allow={isShow && isVisible ? "1" : ""}
28
+ onClick={this.onInterfaceClick}
29
+ >
30
+ <div className={b("control", { settings: true })} onClick={this.onGameMenuClick} />
31
+ <div className={b("control", { history: true })} onClick={this.onHistoryClick} />
32
+ <div className={b("control", { hide: true })} onClick={this.onHideClick} />
33
+ </div>
34
+ );
35
+ }
36
+ }
37
+
38
+ export const render = (props, root, resolve) => ReactDOM.render(<InterfaceControls {...props} />, root, resolve);
@@ -0,0 +1,54 @@
1
+ .InterfaceControls
2
+ position: absolute
3
+ right: 15%
4
+ bottom: 1%
5
+ left: 15%
6
+ font-family: "Montserrat"
7
+ pointer-events: none
8
+ opacity: 0
9
+ z-index: 1100
10
+
11
+ display: flex
12
+ align-items: center
13
+ flex-shrink: 0
14
+ gap: calc(50 / 2688 * 100%);
15
+
16
+ &-control
17
+ width: calc(120 / 2688 * 100%)
18
+ aspect-ratio: 12/10
19
+ transition: box-shadow 300ms, background-image 300ms
20
+ cursor: pointer
21
+ background-position: center
22
+ background-repeat: no-repeat
23
+ background-size: contain
24
+
25
+ &_settings
26
+ background-image: url("./images/Settings.png")
27
+
28
+ &:hover
29
+ background-image: url("./images/Settings_H.png")
30
+
31
+ &_history
32
+ background-image: url("./images/History.png")
33
+
34
+ &:hover
35
+ background-image: url("./images/History_H.png")
36
+
37
+ &_hide
38
+ background-image: url("./images/Hide.png")
39
+
40
+ &:hover
41
+ background-image: url("./images/Hide_H.png")
42
+
43
+ &-control ~ &-control
44
+ margin-left: calc(50 / 2688 * 100%)
45
+
46
+ &_isShow
47
+ pointer-events: all
48
+ opacity: 1
49
+
50
+ &:not(&_isVisible)
51
+ opacity: 0
52
+
53
+ &:not(&_isForce)
54
+ transition: opacity 500ms