@vnejs/plugins.views.screens.credits 0.1.5

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,5 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ SHOW: "vne:credits:show",
3
+ HIDE: "vne:credits:hide",
4
+ UPDATE: "vne:credits:update",
5
+ };
@@ -0,0 +1,11 @@
1
+ export const LINES = [];
2
+
3
+ export const TRANSITION = 1000;
4
+ export const ZINDEX = 2000;
5
+
6
+ export const VIEW_PROPS = {
7
+ screen: { isDisableAutoread: true, zIndex: ZINDEX, transition: TRANSITION },
8
+ scroll: { waitCommonDelay: TRANSITION, waitStartDelay: 500, waitEndDelay: 2000, duration: 120 * 1000 },
9
+ flex: { paddingHorizontal: 720, paddingVertical: 120, gap: 36, direction: "column" },
10
+ text: { size: 72, align: "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 { CreditsController } from "./modules/controller";
7
+ import { Credits } from "./modules/credits";
8
+ import { CreditsView } from "./modules/view";
9
+
10
+ regPlugin("CREDITS", { events: SUBSCRIBE_EVENTS, params }, [CreditsController, Credits, CreditsView]);
@@ -0,0 +1,24 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class CreditsController extends ModuleController {
4
+ name = "credits.controller";
5
+
6
+ onInteract = () => this.emit(this.EVENTS.CREDITS.HIDE);
7
+
8
+ updateEvent = this.EVENTS.CREDITS.UPDATE;
9
+ controls = {
10
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.onInteract,
11
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: this.onInteract,
12
+ [this.CONST.CONTROLS.BUTTONS.MENU]: this.onInteract,
13
+ };
14
+ controlsIndex = this.PARAMS.CREDITS.ZINDEX;
15
+
16
+ subscribe = () => {
17
+ this.on(this.EVENTS.CREDITS.SHOW, this.onShow);
18
+ this.on(this.EVENTS.CREDITS.HIDE, this.onHide);
19
+
20
+ this.on(this.EVENTS.STATE.CLEAR, this.onHide);
21
+ };
22
+
23
+ afterHide = () => this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
24
+ }
@@ -0,0 +1,16 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import { tokenizeExecLine } from "@vnejs/helpers";
4
+
5
+ export class Credits extends Module {
6
+ name = "credits";
7
+
8
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
9
+
10
+ onLineExec = ({ line = "" } = {}) => {
11
+ const [action = ""] = tokenizeExecLine(line);
12
+
13
+ if (action === "show") return this.emit(this.EVENTS.CREDITS.SHOW);
14
+ if (action === "hide") return this.emit(this.EVENTS.CREDITS.HIDE);
15
+ };
16
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class CreditsView extends ModuleView {
6
+ name = "credits.view";
7
+
8
+ animationTime = this.PARAMS.CREDITS.TRANSITION;
9
+ updateEvent = this.EVENTS.CREDITS.UPDATE;
10
+
11
+ renderFunc = render;
12
+ updateHandler = this.onUpdateStoreComponent;
13
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.screens.credits",
3
+ "version": "0.1.5",
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,38 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { Flex, Screen, ScrollContent, Text } from "@vnejs/uis.react";
5
+
6
+ const renderLine = ({ text, props } = {}, i) => (
7
+ <Text
8
+ {...props}
9
+ text={text}
10
+ key={i}
11
+ />
12
+ );
13
+
14
+ const Credits = ({ store, onMount, ...props } = {}) => {
15
+ const [{ isShow = false, isForce = false }, setState] = useState({});
16
+
17
+ useEffect(() => store.subscribe(setState), []);
18
+ useEffect(() => void onMount(), []);
19
+
20
+ const onClose = useCallback(() => props.emit(props.EVENTS.CREDITS.HIDE), []);
21
+
22
+ const propsByView = props.PARAMS.CREDITS.VIEW_PROPS;
23
+
24
+ const propsScreen = useMemo(() => ({ ...propsByView.screen, isShow, isForce, onClose }), [isShow, isForce]);
25
+ const propsScroll = useMemo(() => ({ ...propsByView.scroll, shouldScroll: isShow, onClose }), [isShow]);
26
+
27
+ const texts = useMemo(() => props.PARAMS.CREDITS.LINES.split("\n").map((text) => ({ text, props: propsByView.text })), []);
28
+
29
+ return (
30
+ <Screen {...propsScreen}>
31
+ <ScrollContent {...propsScroll}>
32
+ <Flex {...propsByView.flex}>{texts.map(renderLine)}</Flex>
33
+ </ScrollContent>
34
+ </Screen>
35
+ );
36
+ };
37
+
38
+ export const render = (props, root) => createRoot(root).render(<Credits {...props} />);