From 3599232f6a84e0d4980b38fef4cb1e48f5c4a0e9 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sun, 29 Mar 2020 17:16:03 +0300 Subject: [PATCH] Add task list view --- src/Scheduler.ts | 4 +++- src/Storage/TaskQueue.ts | 4 ++-- src/TaskQueueRenderer.ts | 34 ++++++++++++++++++++++++++++++++++ src/utils.ts | 2 +- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/TaskQueueRenderer.ts diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 5ecc4ec..c211ac9 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -3,9 +3,10 @@ import UpgradeBuildingTask from './Task/UpgradeBuildingTask'; import GoToBuildingAction from './Action/GoToBuildingAction'; import UpgradeBuildingAction from './Action/UpgradeBuildingAction'; import { TryLaterError } from './Errors'; -import TaskQueue from './Storage/TaskQueue'; +import { TaskQueue, State } from './Storage/TaskQueue'; import ActionQueue from './Storage/ActionQueue'; import { Args, Command } from './Common'; +import TaskQueueRenderer from './TaskQueueRenderer'; export default class Scheduler { taskQueue: TaskQueue; @@ -19,6 +20,7 @@ export default class Scheduler { async run() { await sleepShort(); markPage('Executor'); + new TaskQueueRenderer().render(this.taskQueue.state()); while (true) { await sleepLong(); const actionItem = this.popAction(); diff --git a/src/Storage/TaskQueue.ts b/src/Storage/TaskQueue.ts index 3dae52d..8bc3c3b 100644 --- a/src/Storage/TaskQueue.ts +++ b/src/Storage/TaskQueue.ts @@ -11,7 +11,7 @@ class CommandWithTime { } } -class State { +export class State { current: CommandWithTime | null; items: Array; constructor( @@ -49,7 +49,7 @@ class State { } } -export default class TaskQueue { +export class TaskQueue { push(cmd: Command, ts: number | null = null) { this.log('PUSH TASK', cmd, ts); const state = this.getState(); diff --git a/src/TaskQueueRenderer.ts b/src/TaskQueueRenderer.ts new file mode 100644 index 0000000..0d8e7a2 --- /dev/null +++ b/src/TaskQueueRenderer.ts @@ -0,0 +1,34 @@ +import { State } from './Storage/TaskQueue'; + +const ID = 'id-832654376836436939356'; + +export default class TaskQueueRenderer { + render(state: State) { + const ul = jQuery('') + .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('
  • ').text('Current: ' + state.current.cmd.name) + ); + } + state.items.forEach(c => { + ul.append(jQuery('
  • ').text(c.cmd.name)); + }); + + const el = jQuery(`#${ID}`); + if (el.length > 0) { + el.replaceWith(ul); + } else { + jQuery('body').append(ul); + } + } +} diff --git a/src/utils.ts b/src/utils.ts index b18e964..2b3ebb5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,7 +9,7 @@ export async function sleepShort() { } export async function sleepLong() { - let ms = 10000 + Math.random() * 10000; + let ms = 30000 + Math.random() * 30000; console.log('SLEEP LONG', Math.round(ms)); return await sleep(ms); }