Refactoring again
This commit is contained in:
parent
f45f9c88ae
commit
a5b82459c9
@ -3,9 +3,9 @@ import { markPage, uniqId, waitForLoad } from './utils';
|
|||||||
import { Scheduler } from './Scheduler';
|
import { Scheduler } from './Scheduler';
|
||||||
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
||||||
import { Command } from './Common';
|
import { Command } from './Common';
|
||||||
import TaskQueueRenderer from './TaskQueueRenderer';
|
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||||
|
|
||||||
export default class Dashboard {
|
export class Dashboard {
|
||||||
private readonly version: string;
|
private readonly version: string;
|
||||||
private scheduler: Scheduler;
|
private scheduler: Scheduler;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import * as URLParse from 'url-parse';
|
|||||||
const SESSION_KEY = 'travian_automation_mode';
|
const SESSION_KEY = 'travian_automation_mode';
|
||||||
const SESSION_VALUE = 'command_execution';
|
const SESSION_VALUE = 'command_execution';
|
||||||
|
|
||||||
export default class ModeDetector {
|
export class ModeDetector {
|
||||||
isAuto(): boolean {
|
isAuto(): boolean {
|
||||||
return this.isAutoByLocation() || this.isAutoBySession();
|
return this.isAutoByLocation() || this.isAutoBySession();
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import {
|
|||||||
TryLaterError,
|
TryLaterError,
|
||||||
} from './Errors';
|
} from './Errors';
|
||||||
import { Task, TaskId, TaskList, TaskQueue } from './Storage/TaskQueue';
|
import { Task, TaskId, TaskList, TaskQueue } from './Storage/TaskQueue';
|
||||||
import ActionQueue from './Storage/ActionQueue';
|
import { ActionQueue } from './Storage/ActionQueue';
|
||||||
import { Command } from './Common';
|
import { Command } from './Common';
|
||||||
import TaskQueueRenderer from './TaskQueueRenderer';
|
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||||
import { createAction } from './Action/ActionController';
|
import { createAction } from './Action/ActionController';
|
||||||
import { createTask } from './Task/TaskController';
|
import { createTask } from './Task/TaskController';
|
||||||
import { SendOnAdventureTask } from './Task/SendOnAdventureTask';
|
import { SendOnAdventureTask } from './Task/SendOnAdventureTask';
|
||||||
@ -95,7 +95,7 @@ export class Scheduler {
|
|||||||
if (actionController) {
|
if (actionController) {
|
||||||
await actionController.run(cmd.args, task);
|
await actionController.run(cmd.args, task);
|
||||||
} else {
|
} else {
|
||||||
this.logError('ACTION NOT FOUND', cmd.name);
|
this.logWarn('ACTION NOT FOUND', cmd.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,8 @@ export class Scheduler {
|
|||||||
if (taskController) {
|
if (taskController) {
|
||||||
await taskController.run(task);
|
await taskController.run(task);
|
||||||
} else {
|
} 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logError(err.message);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ActionQueue {
|
export class ActionQueue {
|
||||||
pop(): Command | undefined {
|
pop(): Command | undefined {
|
||||||
const state = this.getState();
|
const state = this.getState();
|
||||||
const first = state.pop();
|
const first = state.pop();
|
||||||
|
@ -4,6 +4,7 @@ import { Scheduler } from '../Scheduler';
|
|||||||
const taskMap: { [name: string]: Function | undefined } = {};
|
const taskMap: { [name: string]: Function | undefined } = {};
|
||||||
|
|
||||||
export function registerTask(constructor: Function) {
|
export function registerTask(constructor: Function) {
|
||||||
|
console.log('REGISTER TASK', constructor.name);
|
||||||
taskMap[constructor.name] = constructor;
|
taskMap[constructor.name] = constructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ function formatDate(ts: number) {
|
|||||||
return dateFormat(d, 'HH:MM:ss');
|
return dateFormat(d, 'HH:MM:ss');
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class TaskQueueRenderer {
|
export class TaskQueueRenderer {
|
||||||
render(tasks: TaskList) {
|
render(tasks: TaskList) {
|
||||||
const ul = jQuery('<ul></ul>')
|
const ul = jQuery('<ul></ul>')
|
||||||
.attr({ id: ID })
|
.attr({ id: ID })
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import ModeDetector from './ModeDetector';
|
import { ModeDetector } from './ModeDetector';
|
||||||
import Scheduler from './Scheduler';
|
import { Scheduler } from './Scheduler';
|
||||||
import Dashboard from './Dashboard';
|
import { Dashboard } from './Dashboard';
|
||||||
import TxtVersion from '!!raw-loader!./version.txt';
|
import TxtVersion from '!!raw-loader!./version.txt';
|
||||||
|
|
||||||
console.log('TRAVIAN AUTOMATION', TxtVersion);
|
console.log('TRAVIAN AUTOMATION', TxtVersion);
|
||||||
|
Loading…
Reference in New Issue
Block a user