@vnejs/plugins.views.achievement 0.1.3 → 0.1.4
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/dist/index.d.ts +1 -0
- package/dist/index.js +14 -0
- package/dist/modules/achievement.d.ts +9 -0
- package/dist/modules/achievement.js +17 -0
- package/dist/modules/controller.d.ts +12 -0
- package/dist/modules/controller.js +28 -0
- package/dist/modules/exec.d.ts +21 -0
- package/dist/modules/exec.js +29 -0
- package/dist/modules/logs.d.ts +8 -0
- package/dist/modules/logs.js +8 -0
- package/dist/modules/view.d.ts +11 -0
- package/dist/modules/view.js +10 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/utils/achievement.d.ts +26 -0
- package/dist/utils/achievement.js +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +13 -0
- package/package.json +39 -6
- package/src/index.ts +16 -0
- package/{modules/achievement.js → src/modules/achievement.ts} +5 -2
- package/src/modules/controller.ts +46 -0
- package/src/modules/exec.ts +52 -0
- package/src/modules/logs.ts +15 -0
- package/src/modules/view.ts +22 -0
- package/src/types.ts +20 -0
- package/src/utils/achievement.ts +31 -0
- package/src/view/index.tsx +67 -0
- package/tsconfig.json +10 -0
- package/const/const.js +0 -2
- package/const/events.js +0 -7
- package/const/params.js +0 -28
- package/index.js +0 -19
- package/modules/controller.js +0 -32
- package/modules/exec.js +0 -38
- package/modules/logs.js +0 -12
- package/modules/view.js +0 -14
- package/view/index.jsx +0 -52
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.achievement.contract";
|
|
3
|
+
import { Achievement } from "./modules/achievement.js";
|
|
4
|
+
import { AchievementController } from "./modules/controller.js";
|
|
5
|
+
import { AchievementExec } from "./modules/exec.js";
|
|
6
|
+
import { AchievementLogs } from "./modules/logs.js";
|
|
7
|
+
import { AchievementView } from "./modules/view.js";
|
|
8
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
9
|
+
Achievement,
|
|
10
|
+
AchievementController,
|
|
11
|
+
AchievementExec,
|
|
12
|
+
AchievementLogs,
|
|
13
|
+
AchievementView,
|
|
14
|
+
]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
3
|
+
import type { AchievementUnlockPayload } from "../utils/achievement.js";
|
|
4
|
+
export declare class Achievement extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onAchievementClear: () => Promise<unknown> | undefined;
|
|
8
|
+
onAchievementUnlock: ({ id, isSkipIfPossible }?: AchievementUnlockPayload) => Promise<unknown[] | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
const STORAGE_VALUE = 1;
|
|
3
|
+
export class Achievement extends Module {
|
|
4
|
+
name = "achievement";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.ACHIEVEMENT.CLEAR, this.onAchievementClear);
|
|
7
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCK, this.onAchievementUnlock);
|
|
8
|
+
};
|
|
9
|
+
onAchievementClear = () => this.emitOne(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
|
|
10
|
+
onAchievementUnlock = async ({ id = "", isSkipIfPossible = false } = {}) => {
|
|
11
|
+
const storageValue = await this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key: id });
|
|
12
|
+
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: id, value: STORAGE_VALUE });
|
|
13
|
+
this.emit(this.EVENTS.ACHIEVEMENT.UNLOCKED, { id });
|
|
14
|
+
if (!isSkipIfPossible || storageValue !== STORAGE_VALUE)
|
|
15
|
+
return this.emit(this.EVENTS.ACHIEVEMENT.APPEND, { id });
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
3
|
+
import type { AchievementAppendPayload, AchievementPluginState, AchievementLoadPayload } from "../utils/achievement.js";
|
|
4
|
+
export declare class AchievementController extends ModuleController<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams, AchievementPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
updateEvent: "vne:achievement:update";
|
|
7
|
+
subscribe: () => void;
|
|
8
|
+
onLoad: ({ id }?: AchievementLoadPayload) => Promise<string> | undefined;
|
|
9
|
+
onAppend: ({ id }?: AchievementAppendPayload) => undefined;
|
|
10
|
+
append: (id?: string) => Promise<void>;
|
|
11
|
+
getIconSrc: (icon?: string) => Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
export class AchievementController extends ModuleController {
|
|
3
|
+
name = "achievement.controller";
|
|
4
|
+
updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOAD, this.onLoad);
|
|
7
|
+
this.on(this.EVENTS.ACHIEVEMENT.APPEND, this.onAppend);
|
|
8
|
+
};
|
|
9
|
+
onLoad = ({ id = "" } = {}) => {
|
|
10
|
+
if (this.PARAMS.ACHIEVEMENT.INFO[id]?.icon)
|
|
11
|
+
return this.getIconSrc(this.PARAMS.ACHIEVEMENT.INFO[id].icon);
|
|
12
|
+
};
|
|
13
|
+
onAppend = ({ id = "" } = {}) => void this.append(id);
|
|
14
|
+
append = async (id = "") => {
|
|
15
|
+
const initialInfo = { id, isShow: false, isNotShowed: true };
|
|
16
|
+
const info = this.PARAMS.ACHIEVEMENT.INFO[id];
|
|
17
|
+
if (info?.icon)
|
|
18
|
+
initialInfo.icon = await this.getIconSrc(info.icon);
|
|
19
|
+
this.updateStateAndViewFast({ array: [...(this.state.array || []), initialInfo] });
|
|
20
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
|
|
21
|
+
this.updateStateAndViewFast({ array: this.state.array?.map((i) => (i.id === id ? { ...i, isShow: true, isNotShowed: false } : i)) });
|
|
22
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.SHOW_DURATION);
|
|
23
|
+
this.updateStateAndViewFast({ array: this.state.array?.map((i) => (i.id === id ? { ...i, isShow: false } : i)) });
|
|
24
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
|
|
25
|
+
this.updateStateAndViewFast({ array: this.state.array?.filter((i) => i.id !== id) });
|
|
26
|
+
};
|
|
27
|
+
getIconSrc = async (icon = "") => (await this.loadImageMedia(`achievement/${icon}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
3
|
+
type LineExecPayload = {
|
|
4
|
+
keywords?: string[];
|
|
5
|
+
line?: string;
|
|
6
|
+
};
|
|
7
|
+
type LineLoadPayload = {
|
|
8
|
+
line?: string;
|
|
9
|
+
priority?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class AchievementExec extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
12
|
+
name: string;
|
|
13
|
+
init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
|
|
14
|
+
onLineExec: ({ keywords, line }?: LineExecPayload) => Promise<void>;
|
|
15
|
+
onLineLoad: ({ line, priority }?: LineLoadPayload) => Promise<unknown> | undefined;
|
|
16
|
+
emitActionExec: (action?: string, tokens?: string[], keywords?: string[]) => Promise<unknown> | undefined;
|
|
17
|
+
emitUnlockExec: (id?: string, isSkipIfPossible?: boolean) => Promise<unknown> | undefined;
|
|
18
|
+
emitActionLoad: (action?: string, tokens?: string[], priority?: number) => Promise<unknown> | undefined;
|
|
19
|
+
emitUnlockLoad: (id?: string, priority?: number) => Promise<unknown> | undefined;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
export class AchievementExec extends Module {
|
|
4
|
+
name = "achievement.exec";
|
|
5
|
+
init = () => Promise.all([
|
|
6
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "achievement", handler: this.onLineExec }),
|
|
7
|
+
this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: "achievement", handler: this.onLineLoad }),
|
|
8
|
+
]);
|
|
9
|
+
onLineExec = async ({ keywords = [], line = "" } = {}) => {
|
|
10
|
+
const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
|
|
11
|
+
await this.emitActionExec(action, tokens, keywords);
|
|
12
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
13
|
+
};
|
|
14
|
+
onLineLoad = ({ line = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
|
|
15
|
+
const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
|
|
16
|
+
return this.emitActionLoad(action, tokens, priority);
|
|
17
|
+
};
|
|
18
|
+
emitActionExec = (action = "", tokens = [], keywords = []) => {
|
|
19
|
+
const isSkipIfPossible = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.SKIP_IF_POSSIBLE);
|
|
20
|
+
if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK)
|
|
21
|
+
return this.emitUnlockExec(tokens[0], isSkipIfPossible);
|
|
22
|
+
};
|
|
23
|
+
emitUnlockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.UNLOCK, { id, isSkipIfPossible });
|
|
24
|
+
emitActionLoad = (action = "", tokens = [], priority) => {
|
|
25
|
+
if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK)
|
|
26
|
+
return this.emitUnlockLoad(tokens[0], priority);
|
|
27
|
+
};
|
|
28
|
+
emitUnlockLoad = (id = "", priority) => this.emitOne(this.EVENTS.ACHIEVEMENT.LOAD, { id, priority });
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
3
|
+
import type { AchievementUnlockedPayload } from "../utils/achievement.js";
|
|
4
|
+
export declare class AchievementLogs extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
onAchievementUnlocked: ({ id }?: AchievementUnlockedPayload) => undefined;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class AchievementLogs extends Module {
|
|
3
|
+
name = "achievement.logs";
|
|
4
|
+
subscribe = () => {
|
|
5
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
|
|
6
|
+
};
|
|
7
|
+
onAchievementUnlocked = ({ id = "" } = {}) => void this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id } });
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
3
|
+
import type { AchievementPluginState } from "../utils/achievement.js";
|
|
4
|
+
export declare class AchievementView extends ModuleView<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams, AchievementPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
locLabel: "achievement";
|
|
7
|
+
animationTime: 500;
|
|
8
|
+
updateEvent: "vne:achievement:update";
|
|
9
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<AchievementPluginState>;
|
|
10
|
+
updateHandler: (state?: AchievementPluginState | undefined) => Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class AchievementView extends ModuleView {
|
|
4
|
+
name = "achievement.view";
|
|
5
|
+
locLabel = this.PARAMS.ACHIEVEMENT.LOC_LABEL;
|
|
6
|
+
animationTime = this.PARAMS.ACHIEVEMENT.TRANSITION;
|
|
7
|
+
updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
|
|
8
|
+
renderFunc = render;
|
|
9
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
10
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Constants as LogsConstants, PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
|
|
3
|
+
import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
4
|
+
import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
|
|
5
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.achievement.contract";
|
|
6
|
+
export type AchievementPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StoragePluginName, StorageSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents>;
|
|
7
|
+
export type AchievementPluginConstants = ModuleComponentsConstants & Record<PluginName, Constants> & Record<ScenarioPluginName, ScenarioConstants> & Record<LogsPluginName, LogsConstants>;
|
|
8
|
+
export type AchievementPluginSettings = ModuleComponentsSettings;
|
|
9
|
+
export type AchievementPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type AchievementItem = {
|
|
2
|
+
id: string;
|
|
3
|
+
isShow: boolean;
|
|
4
|
+
isNotShowed: boolean;
|
|
5
|
+
icon?: string;
|
|
6
|
+
};
|
|
7
|
+
export type AchievementPluginState = {
|
|
8
|
+
isShow: boolean;
|
|
9
|
+
isForce: boolean;
|
|
10
|
+
array?: AchievementItem[];
|
|
11
|
+
locs?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export type AchievementUnlockPayload = {
|
|
14
|
+
id?: string;
|
|
15
|
+
isSkipIfPossible?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type AchievementAppendPayload = {
|
|
18
|
+
id?: string;
|
|
19
|
+
};
|
|
20
|
+
export type AchievementLoadPayload = {
|
|
21
|
+
id?: string;
|
|
22
|
+
priority?: number;
|
|
23
|
+
};
|
|
24
|
+
export type AchievementUnlockedPayload = {
|
|
25
|
+
id?: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, Icon, Text, View, Wrap, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
|
|
3
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
4
|
+
const renderOneView = ({ icon, id, isShow, isNotShowed, locs, PARAMS }, i) => {
|
|
5
|
+
const info = PARAMS.ACHIEVEMENT.INFO[id];
|
|
6
|
+
return (_jsx(View, { top: PARAMS.ACHIEVEMENT.TOP, left: PARAMS.ACHIEVEMENT.LEFT, translateY: getVneLength(PARAMS.ACHIEVEMENT.TOP_SHIFT * i), translateX: getVneLength(isNotShowed || !isShow ? 0 : PARAMS.ACHIEVEMENT.LEFT_SHIFT), isShow: isShow || isNotShowed, transition: PARAMS.ACHIEVEMENT.TRANSITION, zIndex: PARAMS.ACHIEVEMENT.ZINDEX, isHidden: isNotShowed, children: _jsx(Wrap, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.wrap, children: _jsxs(Flex, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.flex, children: [_jsx(Icon, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.icon, src: icon, isNotRender: !icon }), _jsxs(Flex, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.flexText, children: [_jsx(Text, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.title, text: locs[info?.title || ""] || info?.title }), _jsx(Text, { ...PARAMS.ACHIEVEMENT.VIEW_PROPS.description, text: locs[info?.description || ""] || info?.description })] })] }) }) }, id));
|
|
7
|
+
};
|
|
8
|
+
const Achievement = ({ store, onMount, PARAMS }) => {
|
|
9
|
+
const { locs = {}, array = [] } = useStoreState(store, onMount);
|
|
10
|
+
const arrayWithProps = useMemo(() => array.map((a) => ({ ...a, locs })), [array, locs]);
|
|
11
|
+
return arrayWithProps.map((item, i) => renderOneView({ ...item, PARAMS }, i));
|
|
12
|
+
};
|
|
13
|
+
export const render = createRenderFunc(Achievement);
|
package/package.json
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.views.achievement",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"publish:patch": "
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.views.achievement.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.1.0",
|
|
37
|
+
"@vnejs/module": "~0.0.1",
|
|
38
|
+
"@vnejs/module.components": "~0.0.1",
|
|
39
|
+
"@vnejs/plugins.core.components.contract": "~0.0.1",
|
|
40
|
+
"@vnejs/plugins.core.logs.contract": "~0.0.1",
|
|
41
|
+
"@vnejs/plugins.core.scenario.contract": "~0.0.1",
|
|
42
|
+
"@vnejs/plugins.core.storage.contract": "~0.0.1",
|
|
43
|
+
"@vnejs/shared": "~0.0.9",
|
|
44
|
+
"@vnejs/uis.react": "~0.1.0",
|
|
45
|
+
"@vnejs/uis.utils": "~0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
49
|
+
}
|
|
17
50
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.achievement.contract";
|
|
3
|
+
|
|
4
|
+
import { Achievement } from "./modules/achievement.js";
|
|
5
|
+
import { AchievementController } from "./modules/controller.js";
|
|
6
|
+
import { AchievementExec } from "./modules/exec.js";
|
|
7
|
+
import { AchievementLogs } from "./modules/logs.js";
|
|
8
|
+
import { AchievementView } from "./modules/view.js";
|
|
9
|
+
|
|
10
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
11
|
+
Achievement,
|
|
12
|
+
AchievementController,
|
|
13
|
+
AchievementExec,
|
|
14
|
+
AchievementLogs,
|
|
15
|
+
AchievementView,
|
|
16
|
+
]);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Module } from "@vnejs/module";
|
|
2
2
|
|
|
3
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
4
|
+
import type { AchievementUnlockPayload } from "../utils/achievement.js";
|
|
5
|
+
|
|
3
6
|
const STORAGE_VALUE = 1;
|
|
4
7
|
|
|
5
|
-
export class Achievement extends Module {
|
|
8
|
+
export class Achievement extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
6
9
|
name = "achievement";
|
|
7
10
|
|
|
8
11
|
subscribe = () => {
|
|
@@ -12,7 +15,7 @@ export class Achievement extends Module {
|
|
|
12
15
|
|
|
13
16
|
onAchievementClear = () => this.emitOne(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
|
|
14
17
|
|
|
15
|
-
onAchievementUnlock = async ({ id = "", isSkipIfPossible = false }) => {
|
|
18
|
+
onAchievementUnlock = async ({ id = "", isSkipIfPossible = false }: AchievementUnlockPayload = {}) => {
|
|
16
19
|
const storageValue = await this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key: id });
|
|
17
20
|
|
|
18
21
|
this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: id, value: STORAGE_VALUE });
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
4
|
+
import type { AchievementAppendPayload, AchievementPluginState, AchievementItem, AchievementLoadPayload } from "../utils/achievement.js";
|
|
5
|
+
|
|
6
|
+
export class AchievementController extends ModuleController<
|
|
7
|
+
AchievementPluginEvents,
|
|
8
|
+
AchievementPluginConstants,
|
|
9
|
+
AchievementPluginSettings,
|
|
10
|
+
AchievementPluginParams,
|
|
11
|
+
AchievementPluginState
|
|
12
|
+
> {
|
|
13
|
+
name = "achievement.controller";
|
|
14
|
+
|
|
15
|
+
updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
|
|
16
|
+
|
|
17
|
+
subscribe = () => {
|
|
18
|
+
this.on(this.EVENTS.ACHIEVEMENT.LOAD, this.onLoad);
|
|
19
|
+
this.on(this.EVENTS.ACHIEVEMENT.APPEND, this.onAppend);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
onLoad = ({ id = "" }: AchievementLoadPayload = {}) => {
|
|
23
|
+
if (this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO]?.icon)
|
|
24
|
+
return this.getIconSrc(this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO].icon!);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
onAppend = ({ id = "" }: AchievementAppendPayload = {}) => void this.append(id);
|
|
28
|
+
|
|
29
|
+
append = async (id = "") => {
|
|
30
|
+
const initialInfo: AchievementItem = { id, isShow: false, isNotShowed: true };
|
|
31
|
+
const info = this.PARAMS.ACHIEVEMENT.INFO[id as keyof typeof this.PARAMS.ACHIEVEMENT.INFO];
|
|
32
|
+
|
|
33
|
+
if (info?.icon) initialInfo.icon = await this.getIconSrc(info.icon);
|
|
34
|
+
|
|
35
|
+
this.updateStateAndViewFast({ array: [...(this.state.array || []), initialInfo] });
|
|
36
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
|
|
37
|
+
this.updateStateAndViewFast({ array: this.state.array?.map((i) => (i.id === id ? { ...i, isShow: true, isNotShowed: false } : i)) });
|
|
38
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.SHOW_DURATION);
|
|
39
|
+
this.updateStateAndViewFast({ array: this.state.array?.map((i) => (i.id === id ? { ...i, isShow: false } : i)) });
|
|
40
|
+
await this.waitTimeout(this.PARAMS.ACHIEVEMENT.TRANSITION);
|
|
41
|
+
this.updateStateAndViewFast({ array: this.state.array?.filter((i) => i.id !== id) });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
getIconSrc = async (icon = "") =>
|
|
45
|
+
((await this.loadImageMedia(`achievement/${icon}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY] as string | number)) as { src: string }).src;
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
|
|
4
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
5
|
+
|
|
6
|
+
type LineExecPayload = {
|
|
7
|
+
keywords?: string[];
|
|
8
|
+
line?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type LineLoadPayload = {
|
|
12
|
+
line?: string;
|
|
13
|
+
priority?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class AchievementExec extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
17
|
+
name = "achievement.exec";
|
|
18
|
+
|
|
19
|
+
init = () =>
|
|
20
|
+
Promise.all([
|
|
21
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "achievement", handler: this.onLineExec }),
|
|
22
|
+
this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: "achievement", handler: this.onLineLoad }),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
onLineExec = async ({ keywords = [], line = "" }: LineExecPayload = {}) => {
|
|
26
|
+
const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
|
|
27
|
+
|
|
28
|
+
await this.emitActionExec(action, tokens, keywords);
|
|
29
|
+
|
|
30
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
onLineLoad = ({ line = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND }: LineLoadPayload = {}) => {
|
|
34
|
+
const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
|
|
35
|
+
|
|
36
|
+
return this.emitActionLoad(action, tokens, priority);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
emitActionExec = (action = "", tokens: string[] = [], keywords: string[] = []) => {
|
|
40
|
+
const isSkipIfPossible = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.SKIP_IF_POSSIBLE);
|
|
41
|
+
|
|
42
|
+
if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK) return this.emitUnlockExec(tokens[0], isSkipIfPossible);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
emitUnlockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.UNLOCK, { id, isSkipIfPossible });
|
|
46
|
+
|
|
47
|
+
emitActionLoad = (action = "", tokens: string[] = [], priority?: number) => {
|
|
48
|
+
if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK) return this.emitUnlockLoad(tokens[0], priority);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
emitUnlockLoad = (id = "", priority?: number) => this.emitOne(this.EVENTS.ACHIEVEMENT.LOAD, { id, priority });
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
|
|
3
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
4
|
+
import type { AchievementUnlockedPayload } from "../utils/achievement.js";
|
|
5
|
+
|
|
6
|
+
export class AchievementLogs extends Module<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
|
|
7
|
+
name = "achievement.logs";
|
|
8
|
+
|
|
9
|
+
subscribe = () => {
|
|
10
|
+
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
onAchievementUnlocked = ({ id = "" }: AchievementUnlockedPayload = {}) =>
|
|
14
|
+
void this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id } });
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view/index.js";
|
|
4
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
5
|
+
import type { AchievementPluginState } from "../utils/achievement.js";
|
|
6
|
+
|
|
7
|
+
export class AchievementView extends ModuleView<
|
|
8
|
+
AchievementPluginEvents,
|
|
9
|
+
AchievementPluginConstants,
|
|
10
|
+
AchievementPluginSettings,
|
|
11
|
+
AchievementPluginParams,
|
|
12
|
+
AchievementPluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "achievement.view";
|
|
15
|
+
|
|
16
|
+
locLabel = this.PARAMS.ACHIEVEMENT.LOC_LABEL;
|
|
17
|
+
animationTime = this.PARAMS.ACHIEVEMENT.TRANSITION;
|
|
18
|
+
updateEvent = this.EVENTS.ACHIEVEMENT.UPDATE;
|
|
19
|
+
|
|
20
|
+
renderFunc = render;
|
|
21
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
22
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Constants as LogsConstants, PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
|
|
3
|
+
import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
4
|
+
import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
|
|
5
|
+
import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.achievement.contract";
|
|
6
|
+
|
|
7
|
+
export type AchievementPluginEvents = ModuleComponentsEvents &
|
|
8
|
+
Record<PluginName, SubscribeEvents> &
|
|
9
|
+
Record<StoragePluginName, StorageSubscribeEvents> &
|
|
10
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
11
|
+
Record<LogsPluginName, LogsSubscribeEvents>;
|
|
12
|
+
|
|
13
|
+
export type AchievementPluginConstants = ModuleComponentsConstants &
|
|
14
|
+
Record<PluginName, Constants> &
|
|
15
|
+
Record<ScenarioPluginName, ScenarioConstants> &
|
|
16
|
+
Record<LogsPluginName, LogsConstants>;
|
|
17
|
+
|
|
18
|
+
export type AchievementPluginSettings = ModuleComponentsSettings;
|
|
19
|
+
|
|
20
|
+
export type AchievementPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type AchievementItem = {
|
|
2
|
+
id: string;
|
|
3
|
+
isShow: boolean;
|
|
4
|
+
isNotShowed: boolean;
|
|
5
|
+
icon?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type AchievementPluginState = {
|
|
9
|
+
isShow: boolean;
|
|
10
|
+
isForce: boolean;
|
|
11
|
+
array?: AchievementItem[];
|
|
12
|
+
locs?: Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type AchievementUnlockPayload = {
|
|
16
|
+
id?: string;
|
|
17
|
+
isSkipIfPossible?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type AchievementAppendPayload = {
|
|
21
|
+
id?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type AchievementLoadPayload = {
|
|
25
|
+
id?: string;
|
|
26
|
+
priority?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type AchievementUnlockedPayload = {
|
|
30
|
+
id?: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
3
|
+
import { Flex, Icon, Text, View, Wrap, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
5
|
+
|
|
6
|
+
import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
|
|
7
|
+
import type { AchievementPluginState, AchievementItem } from "../utils/achievement.js";
|
|
8
|
+
|
|
9
|
+
type AchievementComponentProps = ReactComponentProps<
|
|
10
|
+
AchievementPluginEvents,
|
|
11
|
+
AchievementPluginConstants,
|
|
12
|
+
AchievementPluginSettings,
|
|
13
|
+
AchievementPluginParams,
|
|
14
|
+
AchievementPluginState
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
type AchievementViewItem = AchievementItem & {
|
|
18
|
+
locs: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const renderOneView = ({ icon, id, isShow, isNotShowed, locs, PARAMS }: AchievementViewItem & Pick<AchievementComponentProps, "PARAMS">, i: number) => {
|
|
22
|
+
const info = PARAMS.ACHIEVEMENT.INFO[id as keyof typeof PARAMS.ACHIEVEMENT.INFO];
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<View
|
|
26
|
+
top={PARAMS.ACHIEVEMENT.TOP}
|
|
27
|
+
left={PARAMS.ACHIEVEMENT.LEFT}
|
|
28
|
+
translateY={getVneLength(PARAMS.ACHIEVEMENT.TOP_SHIFT * i)}
|
|
29
|
+
translateX={getVneLength(isNotShowed || !isShow ? 0 : PARAMS.ACHIEVEMENT.LEFT_SHIFT)}
|
|
30
|
+
isShow={isShow || isNotShowed}
|
|
31
|
+
transition={PARAMS.ACHIEVEMENT.TRANSITION}
|
|
32
|
+
zIndex={PARAMS.ACHIEVEMENT.ZINDEX}
|
|
33
|
+
key={id}
|
|
34
|
+
isHidden={isNotShowed}
|
|
35
|
+
>
|
|
36
|
+
<Wrap {...PARAMS.ACHIEVEMENT.VIEW_PROPS.wrap}>
|
|
37
|
+
<Flex {...PARAMS.ACHIEVEMENT.VIEW_PROPS.flex}>
|
|
38
|
+
<Icon
|
|
39
|
+
{...PARAMS.ACHIEVEMENT.VIEW_PROPS.icon}
|
|
40
|
+
src={icon}
|
|
41
|
+
isNotRender={!icon}
|
|
42
|
+
/>
|
|
43
|
+
<Flex {...PARAMS.ACHIEVEMENT.VIEW_PROPS.flexText}>
|
|
44
|
+
<Text
|
|
45
|
+
{...PARAMS.ACHIEVEMENT.VIEW_PROPS.title}
|
|
46
|
+
text={locs[info?.title || ""] || info?.title}
|
|
47
|
+
/>
|
|
48
|
+
<Text
|
|
49
|
+
{...PARAMS.ACHIEVEMENT.VIEW_PROPS.description}
|
|
50
|
+
text={locs[info?.description || ""] || info?.description}
|
|
51
|
+
/>
|
|
52
|
+
</Flex>
|
|
53
|
+
</Flex>
|
|
54
|
+
</Wrap>
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const Achievement = ({ store, onMount, PARAMS }: AchievementComponentProps) => {
|
|
60
|
+
const { locs = {}, array = [] } = useStoreState<AchievementPluginState>(store, onMount);
|
|
61
|
+
|
|
62
|
+
const arrayWithProps = useMemo(() => array.map((a) => ({ ...a, locs })), [array, locs]);
|
|
63
|
+
|
|
64
|
+
return arrayWithProps.map((item, i) => renderOneView({ ...item, PARAMS }, i));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const render: ViewRenderFunc<AchievementPluginState> = createRenderFunc(Achievement);
|
package/tsconfig.json
ADDED
package/const/const.js
DELETED
package/const/events.js
DELETED
package/const/params.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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 { AchievementLogs } from "./modules/logs";
|
|
11
|
-
import { AchievementView } from "./modules/view";
|
|
12
|
-
|
|
13
|
-
regPlugin("ACHIEVEMENT", { constants, events: SUBSCRIBE_EVENTS, params }, [
|
|
14
|
-
Achievement,
|
|
15
|
-
AchievementController,
|
|
16
|
-
AchievementExec,
|
|
17
|
-
AchievementLogs,
|
|
18
|
-
AchievementView,
|
|
19
|
-
]);
|
package/modules/controller.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
package/modules/exec.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Module } from "@vnejs/module";
|
|
2
|
-
|
|
3
|
-
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
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(this.CONST.SCENARIO.LINE_KEYWORDS.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
|
-
}
|
package/modules/logs.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Module } from "@vnejs/module";
|
|
2
|
-
|
|
3
|
-
export class AchievementLogs extends Module {
|
|
4
|
-
name = "achievement.logs";
|
|
5
|
-
|
|
6
|
-
subscribe = () => {
|
|
7
|
-
this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
onAchievementUnlocked = ({ id = "" } = {}) =>
|
|
11
|
-
void this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id } });
|
|
12
|
-
}
|
package/modules/view.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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/view/index.jsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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} />);
|