Refactoring again

This commit is contained in:
Anton Vakhrushev 2020-04-03 12:32:50 +03:00
parent f45f9c88ae
commit a5b82459c9
7 changed files with 15 additions and 12 deletions

View File

@ -3,9 +3,9 @@ import { markPage, uniqId, waitForLoad } from './utils';
import { Scheduler } from './Scheduler';
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
import { Command } from './Common';
import TaskQueueRenderer from './TaskQueueRenderer';
import { TaskQueueRenderer } from './TaskQueueRenderer';
export default class Dashboard {
export class Dashboard {
private readonly version: string;
private scheduler: Scheduler;

View File

@ -3,7 +3,7 @@ import * as URLParse from 'url-parse';
const SESSION_KEY = 'travian_automation_mode';
const SESSION_VALUE = 'command_execution';
export default class ModeDetector {
export class ModeDetector {
isAuto(): boolean {
return this.isAutoByLocation() || this.isAutoBySession();
}

View File

@ -6,9 +6,9 @@ import {
TryLaterError,
} from './Errors';
import { Task, TaskId, TaskList, TaskQueue } from './Storage/TaskQueue';
import ActionQueue from './Storage/ActionQueue';
import { ActionQueue } from './Storage/ActionQueue';
import { Command } from './Common';
import TaskQueueRenderer from './TaskQueueRenderer';
import { TaskQueueRenderer } from './TaskQueueRenderer';
import { createAction } from './Action/ActionController';
import { createTask } from './Task/TaskController';
import { SendOnAdventureTask } from './Task/SendOnAdventureTask';
@ -95,7 +95,7 @@ export class Scheduler {
if (actionController) {
await actionController.run(cmd.args, task);
} else {
this.logError('ACTION NOT FOUND', cmd.name);
this.logWarn('ACTION NOT FOUND', cmd.name);
}
}
@ -105,7 +105,8 @@ export class Scheduler {
if (taskController) {
await taskController.run(task);
} else {
this.logError('TASK NOT FOUND', task.cmd.name);
this.logWarn('TASK NOT FOUND', task.cmd.name);
this.taskQueue.complete(task.id);
}
}
@ -134,6 +135,7 @@ export class Scheduler {
return;
}
this.logError(err.message);
throw err;
}

View File

@ -17,7 +17,7 @@ class State {
}
}
export default class ActionQueue {
export class ActionQueue {
pop(): Command | undefined {
const state = this.getState();
const first = state.pop();

View File

@ -4,6 +4,7 @@ import { Scheduler } from '../Scheduler';
const taskMap: { [name: string]: Function | undefined } = {};
export function registerTask(constructor: Function) {
console.log('REGISTER TASK', constructor.name);
taskMap[constructor.name] = constructor;
}

View File

@ -9,7 +9,7 @@ function formatDate(ts: number) {
return dateFormat(d, 'HH:MM:ss');
}
export default class TaskQueueRenderer {
export class TaskQueueRenderer {
render(tasks: TaskList) {
const ul = jQuery('<ul></ul>')
.attr({ id: ID })

View File

@ -1,6 +1,6 @@
import ModeDetector from './ModeDetector';
import Scheduler from './Scheduler';
import Dashboard from './Dashboard';
import { ModeDetector } from './ModeDetector';
import { Scheduler } from './Scheduler';
import { Dashboard } from './Dashboard';
import TxtVersion from '!!raw-loader!./version.txt';
console.log('TRAVIAN AUTOMATION', TxtVersion);