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