Fixes
This commit is contained in:
parent
faed76df4d
commit
b99bbd94a6
@ -1,8 +1,8 @@
|
|||||||
import { ActionDefinition } from './TaskController';
|
import { ActionDefinition } from './TaskController';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../Helpers/Path';
|
||||||
|
import { Village } from '../Core/Village';
|
||||||
|
|
||||||
export function goToResourceViewPage(villageId: number): ActionDefinition {
|
export function goToResourceViewPage(villageId: number): ActionDefinition {
|
||||||
return [
|
return [
|
||||||
@ -40,9 +40,8 @@ export function goToGuildHallPage(villageId: number): ActionDefinition {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
export function scanAllVillagesBundle(villages: Array<Village>): Array<ActionDefinition> {
|
||||||
const actions: Array<ActionDefinition> = [];
|
const actions: Array<ActionDefinition> = [];
|
||||||
const villages = grabVillageList();
|
|
||||||
for (let village of villages) {
|
for (let village of villages) {
|
||||||
actions.push(goToResourceViewPage(village.id));
|
actions.push(goToResourceViewPage(village.id));
|
||||||
actions.push(goToMarketSendResourcesPage(village.id));
|
actions.push(goToMarketSendResourcesPage(village.id));
|
||||||
|
@ -6,6 +6,7 @@ import { registerTask } from './TaskMap';
|
|||||||
@registerTask()
|
@registerTask()
|
||||||
export class GrabVillageState extends TaskController {
|
export class GrabVillageState extends TaskController {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
return scanAllVillagesBundle();
|
const villages = this.factory.getAllVillages();
|
||||||
|
return scanAllVillagesBundle(villages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,11 @@ import { registerTask } from './TaskMap';
|
|||||||
@registerTask()
|
@registerTask()
|
||||||
export class UpdateResourceContracts extends TaskController {
|
export class UpdateResourceContracts extends TaskController {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const tasks = this.scheduler.getTaskItems();
|
const villages = this.factory.getAllVillages();
|
||||||
|
|
||||||
|
const tasks = villages
|
||||||
|
.map(v => this.factory.createTaskCollection(v.id).getTasks())
|
||||||
|
.reduce((acc, tasks) => acc.concat(tasks), []);
|
||||||
|
|
||||||
const paths = uniqPaths([...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)]);
|
const paths = uniqPaths([...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)]);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Village } from './Core/Village';
|
import { Coordinates, Village } from './Core/Village';
|
||||||
import { grabVillageList } from './Page/VillageBlock';
|
import { grabVillageList } from './Page/VillageBlock';
|
||||||
import { VillageNotFound } from './Errors';
|
import { VillageNotFound } from './Errors';
|
||||||
|
|
||||||
@ -20,6 +20,14 @@ export class VillageRepository implements VillageRepositoryInterface {
|
|||||||
return village;
|
return village;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getByCrd(crd: Coordinates): Village {
|
||||||
|
const village = this.all().find(vlg => vlg.crd.eq(crd));
|
||||||
|
if (!village) {
|
||||||
|
throw new VillageNotFound('Village not found');
|
||||||
|
}
|
||||||
|
return village;
|
||||||
|
}
|
||||||
|
|
||||||
getActive(): Village {
|
getActive(): Village {
|
||||||
const village = this.all().find(vlg => vlg.active);
|
const village = this.all().find(vlg => vlg.active);
|
||||||
if (!village) {
|
if (!village) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { VillageStorage } from './Storage/VillageStorage';
|
import { VillageStorage } from './Storage/VillageStorage';
|
||||||
import { Task, TaskId, TaskList, uniqTaskId, withResources, withTime } from './Queue/TaskProvider';
|
import { Task, TaskId, uniqTaskId, withResources, withTime } from './Queue/TaskProvider';
|
||||||
import { Args } from './Queue/Args';
|
import { Args } from './Queue/Args';
|
||||||
import { isProductionTask, ProductionQueue, ProductionQueueTypes } from './Core/ProductionQueue';
|
import { isProductionTask, ProductionQueue, ProductionQueueTypes } from './Core/ProductionQueue';
|
||||||
import { getProductionQueue } from './Task/TaskMap';
|
import { getProductionQueue } from './Task/TaskMap';
|
||||||
@ -22,32 +22,16 @@ export class VillageTaskCollection {
|
|||||||
return this.storage.getTasks();
|
return this.storage.getTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): number {
|
private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): void {
|
||||||
const [matched, other] = this.split(predicate);
|
const tasks = this.getTasks();
|
||||||
const modified = matched.map(modifier);
|
const modified = tasks.map(t => (predicate(t) ? modifier(t) : t));
|
||||||
const modifiedCount = modified.length;
|
this.storage.storeTaskList(modified);
|
||||||
this.storage.storeTaskList(modified.concat(other));
|
|
||||||
return modifiedCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeTasks(predicate: (t: Task) => boolean): number {
|
private removeTasks(predicate: (t: Task) => boolean): void {
|
||||||
const [_, other] = this.split(predicate);
|
const tasks = this.getTasks();
|
||||||
const result = other.length;
|
const remaining = tasks.filter(t => !predicate(t));
|
||||||
this.storage.storeTaskList(other);
|
this.storage.storeTaskList(remaining);
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private split(predicate: (t: Task) => boolean): [TaskList, TaskList] {
|
|
||||||
const matched: TaskList = [];
|
|
||||||
const other: TaskList = [];
|
|
||||||
this.getTasks().forEach(t => {
|
|
||||||
if (predicate(t)) {
|
|
||||||
matched.push(t);
|
|
||||||
} else {
|
|
||||||
other.push(t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return [matched, other];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addTask(name: string, args: Args) {
|
addTask(name: string, args: Args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user