Skip to content

Commit be8a77f

Browse files
authored
Merge pull request #352 from runejs/feature/server-module
Moving `engine/world/action` to `engine/action`, as the action pipeli…
2 parents 0441c82 + 46a8173 commit be8a77f

File tree

156 files changed

+369
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+369
-396
lines changed

src/engine/world/action/action-pipeline.ts renamed to src/engine/action/action-pipeline.ts

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { gameEngineDist } from '@engine/util/directories';
2-
import { getFiles } from '@engine/util/files';
3-
import { logger } from '@runejs/core';
4-
import { Actor } from '@engine/world/actor/actor';
5-
import { ActionHook, TaskExecutor } from '@engine/world/action/hooks';
6-
import { Position } from '@engine/world/position';
7-
import { Player } from '@engine/world/actor/player/player';
81
import { Subscription } from 'rxjs';
2+
3+
import { logger } from '@runejs/core';
94
import { LandscapeObject } from '@runejs/filestore';
105

6+
import { Actor, Player } from '@engine/world/actor';
7+
import { ActionHook, TaskExecutor } from '@engine/action';
8+
import { Position } from '@engine/world';
9+
1110

1211
/**
1312
* The priority of an queueable action within the pipeline.
@@ -44,7 +43,8 @@ export type ActionType =
4443
| 'player_command'
4544
| 'player_interaction'
4645
| 'region_change'
47-
| 'equipment_change';
46+
| 'equipment_change'
47+
| 'prayer';
4848

4949

5050
export const gentleActions: ActionType[] = [
@@ -223,39 +223,3 @@ export class ActionPipeline {
223223
}
224224

225225
}
226-
227-
228-
/**
229-
* Finds and loads all available action pipe files (`*.action.ts`).
230-
*/
231-
export async function loadActionFiles(): Promise<void> {
232-
const ACTION_DIRECTORY = `${gameEngineDist}/world/action`;
233-
const blacklist = [];
234-
const loadedActions: string[] = [];
235-
236-
for await(const path of getFiles(ACTION_DIRECTORY, blacklist)) {
237-
if(!path.endsWith('.action.ts') && !path.endsWith('.action.js')) {
238-
continue;
239-
}
240-
241-
const location = '.' + path.substring(ACTION_DIRECTORY.length).replace('.js', '');
242-
243-
try {
244-
const importedAction = (require(location)?.default || null) as ActionPipe | null;
245-
if(importedAction && Array.isArray(importedAction) && importedAction[0] && importedAction[1]) {
246-
ActionPipeline.register(importedAction[0], importedAction[1]);
247-
loadedActions.push(importedAction[0]);
248-
}
249-
} catch(error) {
250-
logger.error(`Error loading action file at ${location}:`);
251-
logger.error(error);
252-
}
253-
}
254-
255-
logger.info(`Loaded action pipes: ${loadedActions.join(', ')}.`);
256-
257-
return Promise.resolve();
258-
}
259-
260-
261-
export * from './hooks/index';
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { QuestKey } from '@engine/config/quest-config';
2-
import { ActionStrength, ActionType } from '@engine/world/action/action-pipeline';
3-
import { HookTask } from '@engine/world/action/hooks/task';
1+
import { QuestKey } from '@engine/config';
2+
import { ActionStrength, ActionType, HookTask } from '@engine/action';
43
import { actionHookMap } from '@engine/plugins';
54

65

@@ -58,7 +57,3 @@ export const getActionHooks = <T extends ActionHook>(actionType: ActionType, fil
5857
export function sortActionHooks<T = any>(actionHooks: ActionHook<T>[]): ActionHook<T>[] {
5958
return actionHooks.sort(actionHook => actionHook.questRequirement !== undefined ? -1 : 1);
6059
}
61-
62-
63-
export * from './hook-filters';
64-
export * from './task';

src/engine/world/action/hooks/hook-filters.ts renamed to src/engine/action/hook/hook-filters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Player } from '@engine/world/actor/player/player';
2-
import { ActionHook } from '@engine/world/action/hooks/index';
1+
import { ActionHook } from '@engine/action';
2+
import { Player } from '@engine/world/actor';
33

44

55
export const stringHookFilter = (expected: string | string[], input: string): boolean => {

src/engine/action/hook/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './hook-filters';
2+
export * from './task';
3+
export * from './action-hook';
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import uuidv4 from 'uuid/v4';
22
import { lastValueFrom, Subscription, timer } from 'rxjs';
3-
import { Actor } from '@engine/world/actor/actor';
4-
import { ActionHook } from '@engine/world/action/action-pipeline';
5-
import { World } from '@engine/world/world';
3+
64
import { logger } from '@runejs/core';
7-
import { Player } from '@engine/world/actor/player/player';
8-
import { Npc } from '@engine/world/actor/npc';
9-
import { ActionStrength } from '@engine/world/action/action-pipeline';
5+
6+
import { ActionHook, ActionStrength } from '@engine/action';
7+
import { World } from '@engine/world';
8+
import { Actor, Player, Npc } from '@engine/world/actor';
109

1110

1211
export type TaskSessionData = { [key: string]: any };

src/engine/action/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './action-pipeline';
2+
export * from './hook';
3+
export * from './pipe';
4+
export * from './loader';

src/engine/action/loader.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { logger } from '@runejs/core';
2+
3+
import { ActionPipe, ActionPipeline } from '@engine/action';
4+
import { getFiles } from '@engine/util';
5+
import { BUILD_DIR } from '@engine/config';
6+
import { join } from 'path';
7+
8+
9+
/**
10+
* Finds and loads all available action pipe files (`*.action.ts`).
11+
*/
12+
export async function loadActionFiles(): Promise<void> {
13+
const ACTION_DIRECTORY = join(BUILD_DIR, 'action');
14+
const PIPE_DIRECTORY = join(ACTION_DIRECTORY, 'pipe');
15+
const blacklist = [];
16+
const loadedActions: string[] = [];
17+
18+
for await(const path of getFiles(PIPE_DIRECTORY, blacklist)) {
19+
if(!path.endsWith('.action.ts') && !path.endsWith('.action.js')) {
20+
continue;
21+
}
22+
23+
const location = '.' + path.substring(ACTION_DIRECTORY.length).replace('.js', '');
24+
25+
try {
26+
const importedAction = (require(location)?.default || null) as ActionPipe | null;
27+
if(importedAction && Array.isArray(importedAction) && importedAction[0] && importedAction[1]) {
28+
ActionPipeline.register(importedAction[0], importedAction[1]);
29+
loadedActions.push(importedAction[0]);
30+
}
31+
} catch(error) {
32+
logger.error(`Error loading action file at ${location}:`);
33+
logger.error(error);
34+
}
35+
}
36+
37+
logger.info(`Loaded action pipes: ${loadedActions.join(', ')}.`);
38+
39+
return Promise.resolve();
40+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Player } from '@engine/world/actor/player/player';
2-
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
3-
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
4-
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
1+
import { Player } from '@engine/world/actor';
2+
import {
3+
ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, ActionPipe, RunnableHooks
4+
} from '@engine/action';
55

66

77
/**

src/engine/world/action/equipment-change.action.ts renamed to src/engine/action/pipe/equipment-change.action.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Player } from '@engine/world/actor/player/player';
2-
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
3-
import { findItem } from '@engine/config/config-handler';
4-
import { EquipmentSlot, ItemDetails } from '@engine/config/item-config';
5-
import { numberHookFilter, stringHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
6-
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
1+
import { Player } from '@engine/world/actor';
2+
import { findItem, EquipmentSlot, ItemDetails } from '@engine/config';
3+
import {
4+
ActionHook, getActionHooks, numberHookFilter, stringHookFilter, questHookFilter, ActionPipe, RunnableHooks
5+
} from '@engine/action';
76

87

98
/**
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './action-pipeline';
21
export * from './button.action';
32
export * from './equipment-change.action';
43
export * from './item-interaction.action';

0 commit comments

Comments
 (0)