Add task list view

This commit is contained in:
Anton Vakhrushev 2020-03-29 17:16:03 +03:00
parent 6e5b8f5ebf
commit 3599232f6a
4 changed files with 40 additions and 4 deletions

View File

@ -3,9 +3,10 @@ import UpgradeBuildingTask from './Task/UpgradeBuildingTask';
import GoToBuildingAction from './Action/GoToBuildingAction'; import GoToBuildingAction from './Action/GoToBuildingAction';
import UpgradeBuildingAction from './Action/UpgradeBuildingAction'; import UpgradeBuildingAction from './Action/UpgradeBuildingAction';
import { TryLaterError } from './Errors'; import { TryLaterError } from './Errors';
import TaskQueue from './Storage/TaskQueue'; import { TaskQueue, State } from './Storage/TaskQueue';
import ActionQueue from './Storage/ActionQueue'; import ActionQueue from './Storage/ActionQueue';
import { Args, Command } from './Common'; import { Args, Command } from './Common';
import TaskQueueRenderer from './TaskQueueRenderer';
export default class Scheduler { export default class Scheduler {
taskQueue: TaskQueue; taskQueue: TaskQueue;
@ -19,6 +20,7 @@ export default class Scheduler {
async run() { async run() {
await sleepShort(); await sleepShort();
markPage('Executor'); markPage('Executor');
new TaskQueueRenderer().render(this.taskQueue.state());
while (true) { while (true) {
await sleepLong(); await sleepLong();
const actionItem = this.popAction(); const actionItem = this.popAction();

View File

@ -11,7 +11,7 @@ class CommandWithTime {
} }
} }
class State { export class State {
current: CommandWithTime | null; current: CommandWithTime | null;
items: Array<CommandWithTime>; items: Array<CommandWithTime>;
constructor( constructor(
@ -49,7 +49,7 @@ class State {
} }
} }
export default class TaskQueue { export class TaskQueue {
push(cmd: Command, ts: number | null = null) { push(cmd: Command, ts: number | null = null) {
this.log('PUSH TASK', cmd, ts); this.log('PUSH TASK', cmd, ts);
const state = this.getState(); const state = this.getState();

34
src/TaskQueueRenderer.ts Normal file
View File

@ -0,0 +1,34 @@
import { State } from './Storage/TaskQueue';
const ID = 'id-832654376836436939356';
export default class TaskQueueRenderer {
render(state: State) {
const ul = jQuery('<ul></ul>')
.attr({ id: ID })
.css({
position: 'absolute',
'background-color': 'white',
left: 0,
top: '40px',
color: 'black',
'z-index': '9999',
padding: '8px 6px',
});
if (state.current) {
ul.append(
jQuery('<li></li>').text('Current: ' + state.current.cmd.name)
);
}
state.items.forEach(c => {
ul.append(jQuery('<li></li>').text(c.cmd.name));
});
const el = jQuery(`#${ID}`);
if (el.length > 0) {
el.replaceWith(ul);
} else {
jQuery('body').append(ul);
}
}
}

View File

@ -9,7 +9,7 @@ export async function sleepShort() {
} }
export async function sleepLong() { export async function sleepLong() {
let ms = 10000 + Math.random() * 10000; let ms = 30000 + Math.random() * 30000;
console.log('SLEEP LONG', Math.round(ms)); console.log('SLEEP LONG', Math.round(ms));
return await sleep(ms); return await sleep(ms);
} }