@vnejs/plugins.views.achievement 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.
package/const/const.js ADDED
@@ -0,0 +1 @@
1
+ export const EXEC_ACTIONS = { UNLOCK: "unlock" };
@@ -0,0 +1,7 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ LOAD: "vne:achievement:load",
3
+ UNLOCK: "vne:achievement:unlock",
4
+ APPEND: "vne:achievement:append",
5
+ UPDATE: "vne:achievement:update",
6
+ UNLOCKED: "vne:achievement:unlocked",
7
+ };
@@ -0,0 +1,28 @@
1
+ export const TRANSITION = 500;
2
+ export const ZINDEX = 100000;
3
+ export const LOC_LABEL = "achievement";
4
+
5
+ export const SHOW_DURATION = 5000;
6
+
7
+ export const VIEW_PROPS = {
8
+ title: { size: 60, isActive: true },
9
+ description: { size: 48 },
10
+
11
+ wrap: { borderRadius: 120, height: 204, width: 1260, padding: 0, borderWidth: 0, isSelected: true },
12
+
13
+ flex: { direction: "row", gap: 36, height: "100%", align: "center" },
14
+ flexText: { justify: "spaceEvenly", direction: "column", height: 180 },
15
+
16
+ icon: { width: 180, height: 180, isDisabled: true, marginLeft: 24 },
17
+ };
18
+
19
+ export const TOP = 120;
20
+ export const TOP_SHIFT = 240;
21
+
22
+ export const LEFT = 0;
23
+ export const LEFT_SHIFT = 60;
24
+
25
+ export const INFO = {
26
+ kekw: { title: "title", description: "description.kekw", icon: "kekw" },
27
+ qwert: { title: "title", description: "description.qwert", icon: "qwert" },
28
+ };
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import * as constants from "./const/const";
4
+ import { SUBSCRIBE_EVENTS } from "./const/events";
5
+ import * as params from "./const/params";
6
+
7
+ import { Achievement } from "./modules/achievement";
8
+ import { AchievementController } from "./modules/controller";
9
+ import { AchievementExec } from "./modules/exec";
10
+ import { AchievementView } from "./modules/view";
11
+
12
+ regPlugin("ACHIEVEMENT", { constants, events: SUBSCRIBE_EVENTS, params }, [Achievement, AchievementController, AchievementExec, AchievementView]);
@@ -0,0 +1,23 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ const STORAGE_VALUE = 1;
4
+
5
+ export class Achievement extends Module {
6
+ name = "achievement";
7
+
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.ACHIEVEMENT.CLEAR, this.onAchievementClear);
10
+ this.on(this.EVENTS.ACHIEVEMENT.UNLOCK, this.onAchievementUnlock);
11
+ };
12
+
13
+ onAchievementClear = () => this.emitOne(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
14
+
15
+ onAchievementUnlock = async ({ id = "", isSkipIfPossible = false }) => {
16
+ const storageValue = await this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key: id });
17
+
18
+ this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: id, value: STORAGE_VALUE });
19
+ this.emit(this.EVENTS.ACHIEVEMENT.UNLOCKED, { id });
20
+
21
+ if (!isSkipIfPossible || storageValue !== STORAGE_VALUE) return this.emit(this.EVENTS.ACHIEVEMENT.APPEND, { id });
22
+ };
23
+ }
@@ -0,0 +1,32 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class AchievementController extends ModuleController {
4
+ name = "achievement.controller";
5
+
6
+ updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
7
+
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.ACHIEVEMENT.LOAD, this.onLoad);
10
+ this.on(this.EVENTS.ACHIEVEMENT.APPEND, this.onAppend);
11
+ };
12
+
13
+ onLoad = ({ id = "" }) => {
14
+ if (this.PARAMS.ACHIEVEMENT.INFO[id].icon) return this.getIconSrc(this.PARAMS.ACHIEVEMENT.INFO[id].icon);
15
+ };
16
+ onAppend = ({ id = "" }) => void this.append(id);
17
+
18
+ append = async (id = "") => {
19
+ const initialInfo = { id, isShow: false, isNotShowed: true };
20
+
21
+ if (this.PARAMS.ACHIEVEMENT.INFO[id].icon) initialInfo.icon = await this.getIconSrc(this.PARAMS.ACHIEVEMENT.INFO[id].icon);
22
+
23
+ this.updateStateAndViewFast({ array: [...(this.state.array || []), initialInfo] });
24
+ await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
25
+ this.updateStateAndViewFast({ array: this.state.array.map((i) => (i.id === id ? { ...i, isShow: true, isNotShowed: false } : i)) });
26
+ await this.waitTimeout(this.PARAMS.ACHIEVEMENT.SHOW_DURATION);
27
+ this.updateStateAndViewFast({ array: this.state.array.map((i) => (i.id === id ? { ...i, isShow: false } : i)) });
28
+ await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
29
+ this.updateStateAndViewFast({ array: this.state.array.filter((i) => i.id !== id) });
30
+ };
31
+ getIconSrc = async (icon = "") => (await this.loadImageMedia(`achievement/${icon}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src;
32
+ }
@@ -0,0 +1,38 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import { tokenizeExecLine } from "@vnejs/helpers.tokenize-exec-line";
4
+
5
+ export class AchievementExec extends Module {
6
+ name = "achievement.exec";
7
+
8
+ init = () =>
9
+ Promise.all([
10
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "achievement", handler: this.onLineExec }),
11
+ this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: "achievement", handler: this.onLineLoad }),
12
+ ]);
13
+
14
+ onLineExec = async ({ keywords = [], line = "" } = {}) => {
15
+ const [action = "", ...tokens] = tokenizeExecLine(line);
16
+
17
+ await this.emitActionExec(action, tokens, keywords);
18
+
19
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
20
+ };
21
+ onLineLoad = ({ line = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
22
+ const [action = "", ...tokens] = tokenizeExecLine(line);
23
+
24
+ return this.emitActionLoad(action, tokens, priority);
25
+ };
26
+
27
+ emitActionExec = (action = "", tokens = [], keywords = []) => {
28
+ const isSkipIfPossible = keywords.includes("skip-if-possible");
29
+
30
+ if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK) return this.emitUnlockExec(tokens, isSkipIfPossible);
31
+ };
32
+ emitUnlockExec = ([id = ""], isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.UNLOCK, { id, isSkipIfPossible });
33
+
34
+ emitActionLoad = (action = "", tokens = [], priority) => {
35
+ if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK) return this.emitUnlockLoad(tokens, priority);
36
+ };
37
+ emitUnlockLoad = ([id = ""], priority) => this.emitOne(this.EVENTS.ACHIEVEMENT.LOAD, { id, priority });
38
+ }
@@ -0,0 +1,14 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class AchievementView extends ModuleView {
6
+ name = "achievement.view";
7
+
8
+ locLabel = this.PARAMS.ACHIEVEMENT.LOC_LABEL;
9
+ animationTime = this.PARAMS.ACHIEVEMENT.TRANSITION;
10
+ updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
11
+
12
+ renderFunc = render;
13
+ updateHandler = this.onUpdateStoreComponent;
14
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.achievement",
3
+ "version": "0.1.1",
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,52 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { View, Text, Wrap, Flex, Icon } from "@vnejs/uis.react";
5
+ import { getVneLength } from "@vnejs/uis.utils";
6
+
7
+ const renderOneView = ({ icon, id, isShow, isNotShowed, props, locs }, i) => (
8
+ <View
9
+ top={props.PARAMS.ACHIEVEMENT.TOP}
10
+ left={props.PARAMS.ACHIEVEMENT.LEFT}
11
+ translateY={getVneLength(props.PARAMS.ACHIEVEMENT.TOP_SHIFT * i)}
12
+ translateX={getVneLength(isNotShowed || !isShow ? 0 : props.PARAMS.ACHIEVEMENT.LEFT_SHIFT)}
13
+ isShow={isShow || isNotShowed}
14
+ transition={props.PARAMS.ACHIEVEMENT.TRANSITION}
15
+ zIndex={props.PARAMS.ACHIEVEMENT.ZINDEX}
16
+ key={id}
17
+ isHidden={isNotShowed}
18
+ >
19
+ <Wrap {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.wrap}>
20
+ <Flex {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.flex}>
21
+ <Icon
22
+ {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.icon}
23
+ src={icon}
24
+ isNotRender={!icon}
25
+ />
26
+ <Flex {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.flexText}>
27
+ <Text
28
+ {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.title}
29
+ text={locs[props.PARAMS.ACHIEVEMENT.INFO[id]?.title] || props.PARAMS.ACHIEVEMENT.INFO[id]?.title}
30
+ />
31
+ <Text
32
+ {...props.PARAMS.ACHIEVEMENT.VIEW_PROPS.description}
33
+ text={locs[props.PARAMS.ACHIEVEMENT.INFO[id]?.description] || props.PARAMS.ACHIEVEMENT.INFO[id]?.description}
34
+ />
35
+ </Flex>
36
+ </Flex>
37
+ </Wrap>
38
+ </View>
39
+ );
40
+
41
+ const Achievement = ({ store, onMount, ...props } = {}) => {
42
+ const [{ locs = {}, array = [] }, setState] = useState({});
43
+
44
+ useEffect(() => store.subscribe(setState), []);
45
+ useEffect(() => void onMount(), []);
46
+
47
+ const arrayWithProps = useMemo(() => array.map((a) => ({ ...a, props, locs })), [array, locs]);
48
+
49
+ return arrayWithProps.map(renderOneView);
50
+ };
51
+
52
+ export const render = (props, root) => createRoot(root).render(<Achievement {...props} />);