Skip to content

Commit

Permalink
Merge pull request #352 from runejs/feature/server-module
Browse files Browse the repository at this point in the history
Moving `engine/world/action` to `engine/action`, as the action pipeli…
  • Loading branch information
Tynarus authored Oct 5, 2021
2 parents 0441c82 + 46a8173 commit be8a77f
Show file tree
Hide file tree
Showing 156 changed files with 369 additions and 396 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { gameEngineDist } from '@engine/util/directories';
import { getFiles } from '@engine/util/files';
import { logger } from '@runejs/core';
import { Actor } from '@engine/world/actor/actor';
import { ActionHook, TaskExecutor } from '@engine/world/action/hooks';
import { Position } from '@engine/world/position';
import { Player } from '@engine/world/actor/player/player';
import { Subscription } from 'rxjs';

import { logger } from '@runejs/core';
import { LandscapeObject } from '@runejs/filestore';

import { Actor, Player } from '@engine/world/actor';
import { ActionHook, TaskExecutor } from '@engine/action';
import { Position } from '@engine/world';


/**
* The priority of an queueable action within the pipeline.
Expand Down Expand Up @@ -44,7 +43,8 @@ export type ActionType =
| 'player_command'
| 'player_interaction'
| 'region_change'
| 'equipment_change';
| 'equipment_change'
| 'prayer';


export const gentleActions: ActionType[] = [
Expand Down Expand Up @@ -223,39 +223,3 @@ export class ActionPipeline {
}

}


/**
* Finds and loads all available action pipe files (`*.action.ts`).
*/
export async function loadActionFiles(): Promise<void> {
const ACTION_DIRECTORY = `${gameEngineDist}/world/action`;
const blacklist = [];
const loadedActions: string[] = [];

for await(const path of getFiles(ACTION_DIRECTORY, blacklist)) {
if(!path.endsWith('.action.ts') && !path.endsWith('.action.js')) {
continue;
}

const location = '.' + path.substring(ACTION_DIRECTORY.length).replace('.js', '');

try {
const importedAction = (require(location)?.default || null) as ActionPipe | null;
if(importedAction && Array.isArray(importedAction) && importedAction[0] && importedAction[1]) {
ActionPipeline.register(importedAction[0], importedAction[1]);
loadedActions.push(importedAction[0]);
}
} catch(error) {
logger.error(`Error loading action file at ${location}:`);
logger.error(error);
}
}

logger.info(`Loaded action pipes: ${loadedActions.join(', ')}.`);

return Promise.resolve();
}


export * from './hooks/index';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { QuestKey } from '@engine/config/quest-config';
import { ActionStrength, ActionType } from '@engine/world/action/action-pipeline';
import { HookTask } from '@engine/world/action/hooks/task';
import { QuestKey } from '@engine/config';
import { ActionStrength, ActionType, HookTask } from '@engine/action';
import { actionHookMap } from '@engine/plugins';


Expand Down Expand Up @@ -58,7 +57,3 @@ export const getActionHooks = <T extends ActionHook>(actionType: ActionType, fil
export function sortActionHooks<T = any>(actionHooks: ActionHook<T>[]): ActionHook<T>[] {
return actionHooks.sort(actionHook => actionHook.questRequirement !== undefined ? -1 : 1);
}


export * from './hook-filters';
export * from './task';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook } from '@engine/world/action/hooks/index';
import { ActionHook } from '@engine/action';
import { Player } from '@engine/world/actor';


export const stringHookFilter = (expected: string | string[], input: string): boolean => {
Expand Down
3 changes: 3 additions & 0 deletions src/engine/action/hook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './hook-filters';
export * from './task';
export * from './action-hook';
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import uuidv4 from 'uuid/v4';
import { lastValueFrom, Subscription, timer } from 'rxjs';
import { Actor } from '@engine/world/actor/actor';
import { ActionHook } from '@engine/world/action/action-pipeline';
import { World } from '@engine/world/world';

import { logger } from '@runejs/core';
import { Player } from '@engine/world/actor/player/player';
import { Npc } from '@engine/world/actor/npc';
import { ActionStrength } from '@engine/world/action/action-pipeline';

import { ActionHook, ActionStrength } from '@engine/action';
import { World } from '@engine/world';
import { Actor, Player, Npc } from '@engine/world/actor';


export type TaskSessionData = { [key: string]: any };
Expand Down
4 changes: 4 additions & 0 deletions src/engine/action/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './action-pipeline';
export * from './hook';
export * from './pipe';
export * from './loader';
40 changes: 40 additions & 0 deletions src/engine/action/loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { logger } from '@runejs/core';

import { ActionPipe, ActionPipeline } from '@engine/action';
import { getFiles } from '@engine/util';
import { BUILD_DIR } from '@engine/config';
import { join } from 'path';


/**
* Finds and loads all available action pipe files (`*.action.ts`).
*/
export async function loadActionFiles(): Promise<void> {
const ACTION_DIRECTORY = join(BUILD_DIR, 'action');
const PIPE_DIRECTORY = join(ACTION_DIRECTORY, 'pipe');
const blacklist = [];
const loadedActions: string[] = [];

for await(const path of getFiles(PIPE_DIRECTORY, blacklist)) {
if(!path.endsWith('.action.ts') && !path.endsWith('.action.js')) {
continue;
}

const location = '.' + path.substring(ACTION_DIRECTORY.length).replace('.js', '');

try {
const importedAction = (require(location)?.default || null) as ActionPipe | null;
if(importedAction && Array.isArray(importedAction) && importedAction[0] && importedAction[1]) {
ActionPipeline.register(importedAction[0], importedAction[1]);
loadedActions.push(importedAction[0]);
}
} catch(error) {
logger.error(`Error loading action file at ${location}:`);
logger.error(error);
}
}

logger.info(`Loaded action pipes: ${loadedActions.join(', ')}.`);

return Promise.resolve();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import {
ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { findItem } from '@engine/config/config-handler';
import { EquipmentSlot, ItemDetails } from '@engine/config/item-config';
import { numberHookFilter, stringHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { findItem, EquipmentSlot, ItemDetails } from '@engine/config';
import {
ActionHook, getActionHooks, numberHookFilter, stringHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './action-pipeline';
export * from './button.action';
export * from './equipment-change.action';
export * from './item-interaction.action';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { ItemDetails } from '@engine/config/item-config';
import { findItem } from '@engine/config/config-handler';
import { numberHookFilter, stringHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { findItem, ItemDetails } from '@engine/config';
import {
ActionHook, getActionHooks, numberHookFilter, stringHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Player } from '@engine/world/actor/player/player';
import { Item } from '@engine/world/items/item';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { Item } from '@engine/world';
import { ActionHook, getActionHooks, questHookFilter, ActionPipe, RunnableHooks } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { Item } from '@engine/world/items/item';
import { Npc } from '@engine/world/actor/npc';
import { advancedNumberHookFilter, questHookFilter, stringHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player, Npc } from '@engine/world/actor';
import { Position, Item } from '@engine/world';
import {
ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, stringHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { Item } from '@engine/world/items/item';
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { LandscapeObject, ObjectConfig } from '@runejs/filestore';
import { playerWalkTo } from '@engine/plugins';
import { Position, Item } from '@engine/world';
import { Player } from '@engine/world/actor';
import {
ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { logger } from '@runejs/core';
import { Item } from '@engine/world/items/item';
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe } from '@engine/world/action/action-pipeline';

import { Player } from '@engine/world/actor';
import { Position, Item } from '@engine/world';
import { ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, ActionPipe } from '@engine/action';
import { playerWalkTo } from '@engine/plugins';


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Player } from '../actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { numberHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { ActionHook, getActionHooks, numberHookFilter, ActionPipe, RunnableHooks } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Npc } from '../actor/npc';
import { Player, Npc } from '@engine/world/actor';
import { ActionHook, getActionHooks, ActionPipe, RunnableHooks } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Player } from '@engine/world/actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { logger } from '@runejs/core';
import { numberHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { ActionHook, getActionHooks, numberHookFilter, ActionPipe, RunnableHooks } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Npc } from '@engine/world/actor/npc';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { stringHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe } from '@engine/world/action/action-pipeline';
import { Npc } from '@engine/world/actor';
import { ActionHook, getActionHooks, stringHookFilter, ActionPipe } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Player } from '@engine/world/actor/player/player';
import { Npc } from '@engine/world/actor/npc';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { stringHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { playerWalkTo } from '@engine/plugins';
import { Player, Npc } from '@engine/world/actor';
import { Position } from '@engine/world';
import {
ActionHook, getActionHooks, stringHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { LandscapeObject, ObjectConfig } from '@runejs/filestore';
import { playerWalkTo } from '@engine/plugins';
import { Position } from '@engine/world';
import { Player } from '@engine/world/actor';
import {
ActionHook, getActionHooks, advancedNumberHookFilter, questHookFilter, ActionPipe, RunnableHooks
} from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Player } from '../actor/player/player';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { ActionPipe, RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { ActionHook, getActionHooks, ActionPipe, RunnableHooks } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { Player } from '@engine/world/actor/player/player';
import { ActionPipe } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { ActionHook, getActionHooks, ActionPipe } from '@engine/action';


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import { ActionHook, getActionHooks } from '@engine/world/action/hooks';
import { logger } from '@runejs/core';
import { stringHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters';
import { RunnableHooks } from '@engine/world/action/action-pipeline';
import { Player } from '@engine/world/actor';
import { Position } from '@engine/world';
import { ActionHook, getActionHooks, stringHookFilter, questHookFilter, RunnableHooks } from '@engine/action';
import { playerWalkTo } from '@engine/plugins';


Expand Down
Loading

0 comments on commit be8a77f

Please sign in to comment.