@vnejs/plugins.views.achievement 0.2.0 → 0.2.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.
@@ -1,9 +1,10 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
3
- import type { AchievementUnlockPayload } from "../utils/achievement.js";
3
+ import type { AchievementLockPayload, AchievementUnlockPayload } from "../utils/achievement.js";
4
4
  export declare class Achievement extends ModuleCore<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
7
  onAchievementClear: () => Promise<unknown> | undefined;
8
+ onAchievementLock: ({ id }?: AchievementLockPayload) => Promise<void>;
8
9
  onAchievementUnlock: ({ id, isSkipIfPossible }?: AchievementUnlockPayload) => Promise<unknown[] | undefined>;
9
10
  }
@@ -4,9 +4,14 @@ export class Achievement extends ModuleCore {
4
4
  name = "achievement";
5
5
  subscribe = () => {
6
6
  this.on(this.EVENTS.ACHIEVEMENT.CLEAR, this.onAchievementClear);
7
+ this.on(this.EVENTS.ACHIEVEMENT.LOCK, this.onAchievementLock);
7
8
  this.on(this.EVENTS.ACHIEVEMENT.UNLOCK, this.onAchievementUnlock);
8
9
  };
9
10
  onAchievementClear = () => this.emitOne(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
11
+ onAchievementLock = async ({ id = "" } = {}) => {
12
+ this.emit(this.EVENTS.STORAGE.RM, { module: this.name, key: id });
13
+ this.emit(this.EVENTS.ACHIEVEMENT.LOCKED, { id });
14
+ };
10
15
  onAchievementUnlock = async ({ id = "", isSkipIfPossible = false } = {}) => {
11
16
  const storageValue = await this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key: id });
12
17
  this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key: id, value: STORAGE_VALUE });
@@ -7,6 +7,7 @@ export declare class AchievementExec extends ModuleCore<AchievementPluginEvents,
7
7
  onLineExec: ({ keywords, line }?: LineExecHandlerArg) => Promise<void>;
8
8
  onLineLoad: ({ line, priority }?: LineLoadHandlerArg) => Promise<unknown> | undefined;
9
9
  emitActionExec: (action?: string, tokens?: string[], keywords?: string[]) => Promise<unknown> | undefined;
10
+ emitLockExec: (id?: string, isSkipIfPossible?: boolean) => Promise<unknown> | undefined;
10
11
  emitUnlockExec: (id?: string, isSkipIfPossible?: boolean) => Promise<unknown> | undefined;
11
12
  emitActionLoad: (action?: string, tokens?: string[], priority?: number) => Promise<unknown> | undefined;
12
13
  emitUnlockLoad: (id?: string, priority?: number) => Promise<unknown> | undefined;
@@ -17,9 +17,12 @@ export class AchievementExec extends ModuleCore {
17
17
  };
18
18
  emitActionExec = (action = "", tokens = [], keywords = []) => {
19
19
  const isSkipIfPossible = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.SKIP_IF_POSSIBLE);
20
+ if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.LOCK)
21
+ return this.emitLockExec(tokens[0], isSkipIfPossible);
20
22
  if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK)
21
23
  return this.emitUnlockExec(tokens[0], isSkipIfPossible);
22
24
  };
25
+ emitLockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.LOCK, { id, isSkipIfPossible });
23
26
  emitUnlockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.UNLOCK, { id, isSkipIfPossible });
24
27
  emitActionLoad = (action = "", tokens = [], priority) => {
25
28
  if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK)
@@ -1,8 +1,9 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
3
- import type { AchievementUnlockedPayload } from "../utils/achievement.js";
3
+ import type { AchievementLockedPayload, AchievementUnlockedPayload } from "../utils/achievement.js";
4
4
  export declare class AchievementLogs extends ModuleCore<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
+ onAchievementLocked: ({ id }?: AchievementLockedPayload) => undefined;
7
8
  onAchievementUnlocked: ({ id }?: AchievementUnlockedPayload) => undefined;
8
9
  }
@@ -2,7 +2,9 @@ import { ModuleCore } from "@vnejs/module.core";
2
2
  export class AchievementLogs extends ModuleCore {
3
3
  name = "achievement.logs";
4
4
  subscribe = () => {
5
+ this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
5
6
  this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
6
7
  };
8
+ onAchievementLocked = ({ id = "" } = {}) => void this.emitLog({ action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.LOCKED, id });
7
9
  onAchievementUnlocked = ({ id = "" } = {}) => void this.emitLog({ action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id });
8
10
  }
@@ -10,6 +10,10 @@ export type AchievementPluginState = {
10
10
  array?: AchievementItem[];
11
11
  locs?: Record<string, string>;
12
12
  };
13
+ export type AchievementLockPayload = {
14
+ id?: string;
15
+ isSkipIfPossible?: boolean;
16
+ };
13
17
  export type AchievementUnlockPayload = {
14
18
  id?: string;
15
19
  isSkipIfPossible?: boolean;
@@ -21,6 +25,9 @@ export type AchievementLoadPayload = {
21
25
  id?: string;
22
26
  priority?: number;
23
27
  };
28
+ export type AchievementLockedPayload = {
29
+ id?: string;
30
+ };
24
31
  export type AchievementUnlockedPayload = {
25
32
  id?: string;
26
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.achievement",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
 
3
3
  import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
4
- import type { AchievementUnlockPayload } from "../utils/achievement.js";
4
+ import type { AchievementLockPayload, AchievementUnlockPayload } from "../utils/achievement.js";
5
5
 
6
6
  const STORAGE_VALUE = 1;
7
7
 
@@ -10,11 +10,17 @@ export class Achievement extends ModuleCore<AchievementPluginEvents, Achievement
10
10
 
11
11
  subscribe = () => {
12
12
  this.on(this.EVENTS.ACHIEVEMENT.CLEAR, this.onAchievementClear);
13
+ this.on(this.EVENTS.ACHIEVEMENT.LOCK, this.onAchievementLock);
13
14
  this.on(this.EVENTS.ACHIEVEMENT.UNLOCK, this.onAchievementUnlock);
14
15
  };
15
16
 
16
17
  onAchievementClear = () => this.emitOne(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
17
18
 
19
+ onAchievementLock = async ({ id = "" }: AchievementLockPayload = {}) => {
20
+ this.emit(this.EVENTS.STORAGE.RM, { module: this.name, key: id });
21
+ this.emit(this.EVENTS.ACHIEVEMENT.LOCKED, { id });
22
+ };
23
+
18
24
  onAchievementUnlock = async ({ id = "", isSkipIfPossible = false }: AchievementUnlockPayload = {}) => {
19
25
  const storageValue = await this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key: id });
20
26
 
@@ -41,6 +41,5 @@ export class AchievementController extends ModuleController<
41
41
  this.updateStateAndViewFast({ array: this.state.array?.filter((i) => i.id !== id) });
42
42
  };
43
43
 
44
- getIconSrc = async (icon = "") =>
45
- (await this.loadImageMedia(`achievement/${icon}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src;
44
+ getIconSrc = async (icon = "") => (await this.loadImageMedia(`achievement/${icon}`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src;
46
45
  }
@@ -31,9 +31,12 @@ export class AchievementExec extends ModuleCore<AchievementPluginEvents, Achieve
31
31
  emitActionExec = (action = "", tokens: string[] = [], keywords: string[] = []) => {
32
32
  const isSkipIfPossible = keywords.includes(this.CONST.SCENARIO.LINE_KEYWORDS.SKIP_IF_POSSIBLE);
33
33
 
34
+ if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.LOCK) return this.emitLockExec(tokens[0], isSkipIfPossible);
34
35
  if (action === this.CONST.ACHIEVEMENT.EXEC_ACTIONS.UNLOCK) return this.emitUnlockExec(tokens[0], isSkipIfPossible);
35
36
  };
36
37
 
38
+ emitLockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.LOCK, { id, isSkipIfPossible });
39
+
37
40
  emitUnlockExec = (id = "", isSkipIfPossible = false) => this.emitOne(this.EVENTS.ACHIEVEMENT.UNLOCK, { id, isSkipIfPossible });
38
41
 
39
42
  emitActionLoad = (action = "", tokens: string[] = [], priority?: number) => {
@@ -1,15 +1,17 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
 
3
3
  import type { AchievementPluginConstants, AchievementPluginEvents, AchievementPluginParams, AchievementPluginSettings } from "../types.js";
4
- import type { AchievementUnlockedPayload } from "../utils/achievement.js";
4
+ import type { AchievementLockedPayload, AchievementUnlockedPayload } from "../utils/achievement.js";
5
5
 
6
6
  export class AchievementLogs extends ModuleCore<AchievementPluginEvents, AchievementPluginConstants, AchievementPluginSettings, AchievementPluginParams> {
7
7
  name = "achievement.logs";
8
8
 
9
9
  subscribe = () => {
10
+ this.on(this.EVENTS.ACHIEVEMENT.LOCKED, this.onAchievementLocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
10
11
  this.on(this.EVENTS.ACHIEVEMENT.UNLOCKED, this.onAchievementUnlocked, this.CONST.LOGS.FILTER_FROM_RESULT_OPTIONS);
11
12
  };
12
13
 
13
- onAchievementUnlocked = ({ id = "" }: AchievementUnlockedPayload = {}) =>
14
- void this.emitLog({ action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id });
14
+ onAchievementLocked = ({ id = "" }: AchievementLockedPayload = {}) => void this.emitLog({ action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.LOCKED, id });
15
+
16
+ onAchievementUnlocked = ({ id = "" }: AchievementUnlockedPayload = {}) => void this.emitLog({ action: this.CONST.ACHIEVEMENT.LOGS_ACTIONS.UNLOCKED, id });
15
17
  }
@@ -16,7 +16,7 @@ describe("AchievementExec", () => {
16
16
  const unlock = spyEvent(observer, SUBSCRIBE_EVENTS.UNLOCK);
17
17
 
18
18
  await (module as AchievementExec).init();
19
- await (module as AchievementExec).onLineExec({ line: 'unlock kekw', keywords: [] });
19
+ await (module as AchievementExec).onLineExec({ line: "unlock kekw", keywords: [] });
20
20
 
21
21
  expect(unlock).toHaveBeenCalledExactlyOnceWith({ id: "kekw", isSkipIfPossible: false });
22
22
  });
@@ -26,7 +26,7 @@ describe("AchievementExec", () => {
26
26
  const unlock = spyEvent(observer, SUBSCRIBE_EVENTS.UNLOCK);
27
27
 
28
28
  await (module as AchievementExec).onLineExec({
29
- line: 'unlock kekw',
29
+ line: "unlock kekw",
30
30
  keywords: [SCENARIO_CONST.LINE_KEYWORDS.SKIP_IF_POSSIBLE],
31
31
  });
32
32
 
@@ -37,7 +37,7 @@ describe("AchievementExec", () => {
37
37
  const { module, observer } = createAchievementTestModule(AchievementExec, { subscribe: false });
38
38
  const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
39
39
 
40
- await (module as AchievementExec).onLineLoad({ line: 'unlock kekw' });
40
+ await (module as AchievementExec).onLineLoad({ line: "unlock kekw" });
41
41
 
42
42
  expect(load).toHaveBeenCalledOnce();
43
43
  });
@@ -48,7 +48,7 @@ describe("AchievementExec", () => {
48
48
 
49
49
  observer.subscribe("vne:scenario:next", next);
50
50
 
51
- await (module as AchievementExec).onLineExec({ line: 'unlock kekw' });
51
+ await (module as AchievementExec).onLineExec({ line: "unlock kekw" });
52
52
 
53
53
  expect(next).toHaveBeenCalledOnce();
54
54
  });
@@ -2,13 +2,7 @@ import { CONSTANTS as LAYER_CONST, PLUGIN_NAME as LAYER, SETTINGS_KEYS as LAYER_
2
2
  import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
3
3
  import { SUBSCRIBE_EVENTS as STORAGE_EVENTS } from "@vnejs/contracts.core.storage";
4
4
  import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.views.achievement";
5
- import {
6
- createTestModule as baseCreateTestModule,
7
- registerCoreVne,
8
- registerVnePlugin,
9
- stubEvent,
10
- stubSilentEvent,
11
- } from "@vnejs/test-utils";
5
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
12
6
 
13
7
  export const registerAchievementPluginVne = () => {
14
8
  registerCoreVne();
package/src/types.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
2
  import type { Constants as LogsConstants, PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
3
- import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
3
+ import type {
4
+ Constants as ScenarioConstants,
5
+ PluginName as ScenarioPluginName,
6
+ SubscribeEvents as ScenarioSubscribeEvents,
7
+ } from "@vnejs/contracts.core.scenario";
4
8
  import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/contracts.core.storage";
5
9
  import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.views.achievement";
6
10
 
@@ -12,6 +12,11 @@ export type AchievementPluginState = {
12
12
  locs?: Record<string, string>;
13
13
  };
14
14
 
15
+ export type AchievementLockPayload = {
16
+ id?: string;
17
+ isSkipIfPossible?: boolean;
18
+ };
19
+
15
20
  export type AchievementUnlockPayload = {
16
21
  id?: string;
17
22
  isSkipIfPossible?: boolean;
@@ -26,6 +31,10 @@ export type AchievementLoadPayload = {
26
31
  priority?: number;
27
32
  };
28
33
 
34
+ export type AchievementLockedPayload = {
35
+ id?: string;
36
+ };
37
+
29
38
  export type AchievementUnlockedPayload = {
30
39
  id?: string;
31
40
  };