Add building queue time grabber
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { StateGrabber } from './StateGrabber';
|
||||
import { ResourceGrabber } from './ResourceGrabber';
|
||||
import { ResourcePerformanceGrabber } from './ResourcePerformanceGrabber';
|
||||
import { VillageOverviewPageGrabber } from './VillageOverviewPageGrabber';
|
||||
|
||||
export class StateGrabberManager {
|
||||
private readonly grabbers: Array<StateGrabber> = [];
|
||||
@ -8,7 +8,7 @@ export class StateGrabberManager {
|
||||
constructor() {
|
||||
this.grabbers = [];
|
||||
this.grabbers.push(new ResourceGrabber());
|
||||
this.grabbers.push(new ResourcePerformanceGrabber());
|
||||
this.grabbers.push(new VillageOverviewPageGrabber());
|
||||
}
|
||||
|
||||
grab() {
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { StateGrabber } from './StateGrabber';
|
||||
import { grabActiveVillageId, grabResourcesPerformance } from '../Page/VillageBlock';
|
||||
import { grabActiveVillageId, grabBuildingQueueInfo, grabResourcesPerformance } from '../Page/VillageBlock';
|
||||
import { VillageState } from './VillageState';
|
||||
import { parseLocation } from '../utils';
|
||||
|
||||
export class ResourcePerformanceGrabber extends StateGrabber {
|
||||
export class VillageOverviewPageGrabber extends StateGrabber {
|
||||
grab(): void {
|
||||
const p = parseLocation();
|
||||
if (p.pathname !== '/dorf1.php') {
|
||||
@ -13,5 +13,6 @@ export class ResourcePerformanceGrabber extends StateGrabber {
|
||||
const villageId = grabActiveVillageId();
|
||||
const state = new VillageState(villageId);
|
||||
state.storeResourcesPerformance(grabResourcesPerformance());
|
||||
state.storeBuildingQueueInfo(grabBuildingQueueInfo());
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import { DataStorage } from '../Storage/DataStorage';
|
||||
import { Resources, ResourceStorage } from '../Game';
|
||||
import { BuildingQueueInfo, Resources, ResourceStorage } from '../Game';
|
||||
|
||||
const RESOURCES_KEY = 'res';
|
||||
const CAPACITY_KEY = 'cap';
|
||||
const PERFORMANCE_KEY = 'perf';
|
||||
const BUILDING_QUEUE_KEY = 'bq';
|
||||
|
||||
export class VillageState {
|
||||
private storage: DataStorage;
|
||||
@ -40,4 +41,14 @@ export class VillageState {
|
||||
let res = new Resources(0, 0, 0, 0);
|
||||
return Object.assign(res, plain) as Resources;
|
||||
}
|
||||
|
||||
storeBuildingQueueInfo(info: BuildingQueueInfo): void {
|
||||
this.storage.set(BUILDING_QUEUE_KEY, info);
|
||||
}
|
||||
|
||||
getBuildingQueueInfo(): BuildingQueueInfo {
|
||||
let plain = this.storage.get(BUILDING_QUEUE_KEY);
|
||||
let res = new BuildingQueueInfo(0);
|
||||
return Object.assign(res, plain) as BuildingQueueInfo;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user