-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathloader.ts
More file actions
74 lines (63 loc) · 2.21 KB
/
loader.ts
File metadata and controls
74 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import type { ActionType } from '@engine/action/action-pipeline';
import { type ActionHook, sortActionHooks } from '@engine/action/hook/action-hook';
import { loadPluginFiles } from '@engine/plugins/content-plugin';
import { Quest } from '@engine/world/actor/player/quest';
import { logger } from '@runejs/common';
/**
* A type for describing the plugin action hook map.
*/
type PluginActionHookMap = { quest?: ActionHook[] } & {
[key in ActionType]?: ActionHook[];
};
/**
* A type for describing the plugin action hook map.
*/
interface PluginQuestMap {
[key: string]: Quest;
}
/**
* A list of action hooks imported from content plugins.
*/
export let actionHookMap: PluginActionHookMap = {};
/**
* A list of quests imported from content plugins.
*/
export let questMap: PluginQuestMap = {};
/**
* Searches for and loads all plugin files and their associated action hooks.
*/
export async function loadPlugins(): Promise<void> {
actionHookMap = {};
questMap = {};
const plugins = await loadPluginFiles();
const pluginActionHookList = plugins?.filter(plugin => !!plugin?.hooks)?.map(plugin => plugin.hooks);
if (pluginActionHookList && pluginActionHookList.length !== 0) {
pluginActionHookList
.reduce((a, b) => (a || []).concat(b || []))
?.forEach(action => {
if (!(action instanceof Quest)) {
if (!actionHookMap[action.type]) {
actionHookMap[action.type] = [];
}
actionHookMap[action.type]!.push(action);
} else {
if (!actionHookMap['quest']) {
actionHookMap['quest'] = [];
}
actionHookMap['quest'].push(action);
}
});
} else {
logger.warn('No action hooks detected - update plugins.');
}
for (const plugin of plugins) {
if (!plugin.quests) {
continue;
}
for (const quest of plugin.quests) {
questMap[quest.id] = quest;
}
}
// @TODO implement proper sorting rules
Object.keys(actionHookMap).forEach(key => (actionHookMap[key] = sortActionHooks(actionHookMap[key])));
}