Refactoring
This commit is contained in:
@ -1,23 +1,15 @@
|
||||
import Scheduler from '../Scheduler';
|
||||
import { Args, Command } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import TaskController from './TaskController';
|
||||
import { TaskController, registerTask } from './TaskController';
|
||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||
import { GrabHeroAttributesAction } from '../Action/GrabHeroAttributesAction';
|
||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||
|
||||
export default class SendOnAdventureTask extends TaskController {
|
||||
static NAME = 'send_on_adventure';
|
||||
private scheduler: Scheduler;
|
||||
|
||||
constructor(scheduler: Scheduler) {
|
||||
super();
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
run(task: Task) {
|
||||
@registerTask
|
||||
export class SendOnAdventureTask extends TaskController {
|
||||
async run(task: Task) {
|
||||
const args: Args = { ...task.cmd.args, taskId: task.id };
|
||||
this.scheduler.scheduleActions([
|
||||
new Command(GoToPageAction.name, { ...args, path: 'hero.php' }),
|
||||
|
@ -1,5 +1,30 @@
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { Scheduler } from '../Scheduler';
|
||||
|
||||
export default abstract class TaskController {
|
||||
abstract run(task: Task);
|
||||
const taskMap: { [name: string]: Function | undefined } = {};
|
||||
|
||||
export function registerTask(constructor: Function) {
|
||||
taskMap[constructor.name] = constructor;
|
||||
}
|
||||
|
||||
export function createTask(
|
||||
name: string,
|
||||
scheduler: Scheduler
|
||||
): TaskController | undefined {
|
||||
const storedFunction = taskMap[name];
|
||||
if (storedFunction === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const constructor = (storedFunction as unknown) as typeof TaskController;
|
||||
return new constructor(scheduler);
|
||||
}
|
||||
|
||||
export class TaskController {
|
||||
protected scheduler: Scheduler;
|
||||
|
||||
constructor(scheduler: Scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
async run(task: Task) {}
|
||||
}
|
||||
|
@ -1,23 +1,14 @@
|
||||
import Scheduler from '../Scheduler';
|
||||
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
||||
import { Args, Command } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import TaskController from './TaskController';
|
||||
import { TaskController, registerTask } from './TaskController';
|
||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||
|
||||
export default class UpgradeBuildingTask extends TaskController {
|
||||
static NAME = 'upgrade_building';
|
||||
private scheduler: Scheduler;
|
||||
|
||||
constructor(scheduler: Scheduler) {
|
||||
super();
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
run(task: Task) {
|
||||
console.log('RUN', UpgradeBuildingTask.NAME, 'with', task);
|
||||
@registerTask
|
||||
export class UpgradeBuildingTask extends TaskController {
|
||||
async run(task: Task) {
|
||||
const args: Args = { ...task.cmd.args, taskId: task.id };
|
||||
this.scheduler.scheduleActions([
|
||||
new Command(GoToPageAction.name, { ...args, path: '/dorf1.php' }),
|
||||
|
Reference in New Issue
Block a user