Add task list view
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class CommandWithTime { | ||||
|     } | ||||
| } | ||||
|  | ||||
| class State { | ||||
| export class State { | ||||
|     current: CommandWithTime | null; | ||||
|     items: Array<CommandWithTime>; | ||||
|     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(); | ||||
|   | ||||
							
								
								
									
										34
									
								
								src/TaskQueueRenderer.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/TaskQueueRenderer.ts
									
									
									
									
									
										Normal 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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user