Add village repo to scheduler
This commit is contained in:
		| @@ -7,6 +7,7 @@ import { ControlPanel } from './ControlPanel'; | ||||
| import { DataStorageTaskProvider } from './Queue/DataStorageTaskProvider'; | ||||
| import { Statistics } from './Statistics'; | ||||
| import { StatisticsStorage } from './Storage/StatisticsStorage'; | ||||
| import { VillageRepository, VillageRepositoryInterface } from './VillageRepository'; | ||||
|  | ||||
| export class Container { | ||||
|     private readonly version: string; | ||||
| @@ -15,6 +16,17 @@ export class Container { | ||||
|         this.version = version; | ||||
|     } | ||||
|  | ||||
|     private _villageRepository: VillageRepositoryInterface | undefined; | ||||
|  | ||||
|     get villageRepository(): VillageRepository { | ||||
|         this._villageRepository = | ||||
|             this._villageRepository || | ||||
|             (() => { | ||||
|                 return new VillageRepository(); | ||||
|             })(); | ||||
|         return this._villageRepository; | ||||
|     } | ||||
|  | ||||
|     private _scheduler: Scheduler | undefined; | ||||
|  | ||||
|     get scheduler(): Scheduler { | ||||
| @@ -24,7 +36,7 @@ export class Container { | ||||
|                 const taskProvider = DataStorageTaskProvider.create(); | ||||
|                 const taskQueue = new TaskQueue(taskProvider, new ConsoleLogger(TaskQueue.name)); | ||||
|                 const actionQueue = new ActionQueue(); | ||||
|                 return new Scheduler(taskQueue, actionQueue, new ConsoleLogger(Scheduler.name)); | ||||
|                 return new Scheduler(taskQueue, actionQueue, this.villageRepository, new ConsoleLogger(Scheduler.name)); | ||||
|             })(); | ||||
|         return this._scheduler; | ||||
|     } | ||||
|   | ||||
| @@ -20,7 +20,6 @@ import { ExecutionStorage } from './Storage/ExecutionStorage'; | ||||
| import { createVillageStates, VillageState } from './VillageState'; | ||||
| import { Task } from './Queue/TaskProvider'; | ||||
| import { Action } from './Queue/ActionQueue'; | ||||
| import * as _ from 'underscore'; | ||||
|  | ||||
| interface QuickAction { | ||||
|     label: string; | ||||
|   | ||||
| @@ -14,7 +14,7 @@ import { ImmutableTaskList, Task, TaskId } from './Queue/TaskProvider'; | ||||
| import { ForgeImprovementTask } from './Task/ForgeImprovementTask'; | ||||
| import { getTaskType, TaskType } from './Task/TaskMap'; | ||||
| import { MARKET_ID } from './Core/Buildings'; | ||||
| import { grabVillageList } from './Page/VillageBlock'; | ||||
| import { VillageRepositoryInterface } from './VillageRepository'; | ||||
|  | ||||
| export enum ContractType { | ||||
|     UpgradeBuilding, | ||||
| @@ -31,11 +31,18 @@ interface ContractAttributes { | ||||
| export class Scheduler { | ||||
|     private taskQueue: TaskQueue; | ||||
|     private actionQueue: ActionQueue; | ||||
|     private villageRepository: VillageRepositoryInterface; | ||||
|     private logger: Logger; | ||||
|  | ||||
|     constructor(taskQueue: TaskQueue, actionQueue: ActionQueue, logger: Logger) { | ||||
|     constructor( | ||||
|         taskQueue: TaskQueue, | ||||
|         actionQueue: ActionQueue, | ||||
|         villageRepository: VillageRepositoryInterface, | ||||
|         logger: Logger | ||||
|     ) { | ||||
|         this.taskQueue = taskQueue; | ||||
|         this.actionQueue = actionQueue; | ||||
|         this.villageRepository = villageRepository; | ||||
|         this.logger = logger; | ||||
|  | ||||
|         // this.taskQueue.push(GrabVillageState.name, {}, timestamp()); | ||||
| @@ -185,7 +192,7 @@ export class Scheduler { | ||||
|  | ||||
|     scheduleResourceTransferTasks(fromVillageId: number, toVillageId: number): void { | ||||
|         this.dropResourceTransferTasks(fromVillageId, toVillageId); | ||||
|         const village = grabVillageList().find(v => v.id === toVillageId); | ||||
|         const village = this.villageRepository.all().find(v => v.id === toVillageId); | ||||
|         if (!village) { | ||||
|             throw new Error('No village'); | ||||
|         } | ||||
|   | ||||
							
								
								
									
										12
									
								
								src/VillageRepository.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/VillageRepository.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| import { Village } from './Core/Village'; | ||||
| import { grabVillageList } from './Page/VillageBlock'; | ||||
|  | ||||
| export interface VillageRepositoryInterface { | ||||
|     all(): Array<Village>; | ||||
| } | ||||
|  | ||||
| export class VillageRepository implements VillageRepositoryInterface { | ||||
|     all(): Array<Village> { | ||||
|         return grabVillageList(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user