Rewrite task queue
This commit is contained in:
@ -1,3 +0,0 @@
|
||||
export default abstract class Action {
|
||||
abstract async run(args);
|
||||
}
|
6
src/Action/ActionController.ts
Normal file
6
src/Action/ActionController.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
|
||||
export default abstract class ActionController {
|
||||
abstract async run(args: Args, task: Task);
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
import Action from './Action';
|
||||
import ActionController from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
|
||||
export default class GoToBuildingAction extends Action {
|
||||
export default class GoToBuildingAction extends ActionController {
|
||||
static NAME = 'go_to_building';
|
||||
|
||||
async run(args): Promise<any> {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
window.location.assign('/build.php?id=' + args.id);
|
||||
return null;
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import Action from './Action';
|
||||
import ActionController from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
|
||||
export default class GoToResourceFieldsAction extends Action {
|
||||
export default class GoToResourceFieldsAction extends ActionController {
|
||||
static NAME = 'go_to_resource_fields';
|
||||
async run(): Promise<any> {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
window.location.assign('/dorf1.php');
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import Action from './Action';
|
||||
import ActionController from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
|
||||
export default class StoreRemainingBuildTimeAction extends Action {
|
||||
export default class StoreRemainingBuildTimeAction extends ActionController {
|
||||
static NAME = 'store_remaining_build_time';
|
||||
|
||||
async run(args: Args): Promise<any> {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
const timer = jQuery('.buildDuration .timer');
|
||||
// if (timer.length === 1) {
|
||||
// const remainingSeconds = +timer.val();
|
||||
|
@ -1,9 +1,10 @@
|
||||
import Action from './Action';
|
||||
import ActionController from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { TryLaterError } from '../Errors';
|
||||
import Scheduler from '../Scheduler';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
|
||||
export default class UpgradeBuildingAction extends Action {
|
||||
export default class UpgradeBuildingAction extends ActionController {
|
||||
static NAME = 'upgrade_building';
|
||||
private scheduler: Scheduler;
|
||||
|
||||
@ -12,12 +13,12 @@ export default class UpgradeBuildingAction extends Action {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
async run(args: Args): Promise<any> {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
const btn = jQuery(
|
||||
'.upgradeButtonsContainer .section1 button.green.build'
|
||||
);
|
||||
if (btn.length === 1) {
|
||||
this.scheduler.completeCurrentTask();
|
||||
this.scheduler.completeTask(task.id);
|
||||
btn.trigger('click');
|
||||
} else {
|
||||
throw new TryLaterError(60, 'No upgrade button, try later');
|
||||
|
Reference in New Issue
Block a user