Rename state to storage
This commit is contained in:
parent
c1a63875a8
commit
3d54294043
@ -2,7 +2,7 @@ import { ActionController, registerAction } from './ActionController';
|
||||
import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock';
|
||||
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { HeroState } from '../State/HeroState';
|
||||
import { HeroStorage } from '../Storage/HeroStorage';
|
||||
import { calcHeroResource } from '../Core/HeroBalance';
|
||||
import { HeroAllResources } from '../Core/Hero';
|
||||
import { Args } from '../Queue/Args';
|
||||
@ -12,7 +12,7 @@ import { Task } from '../Queue/TaskProvider';
|
||||
export class BalanceHeroResourcesAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
const activeVillageId = grabActiveVillageId();
|
||||
const heroVillageId = new HeroState().getVillageId();
|
||||
const heroVillageId = new HeroStorage().getVillageId();
|
||||
|
||||
if (heroVillageId === undefined || activeVillageId !== heroVillageId) {
|
||||
changeHeroResource(HeroAllResources);
|
||||
|
@ -2,7 +2,7 @@ import { ActionController, registerAction } from './ActionController';
|
||||
import { grabVillageList } from '../Page/VillageBlock';
|
||||
import { grabHeroVillage } from '../Page/HeroPage';
|
||||
import { path } from '../utils';
|
||||
import { HeroState } from '../State/HeroState';
|
||||
import { HeroStorage } from '../Storage/HeroStorage';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
||||
@ -25,6 +25,6 @@ export class GoToHeroVillageAction extends ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
return new HeroState().getVillageId();
|
||||
return new HeroStorage().getVillageId();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import { grabVillageResources } from '../Page/ResourcesBlock';
|
||||
import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
|
||||
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
||||
import { aroundMinutes, timestamp } from '../utils';
|
||||
import { VillageState } from '../State/VillageState';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
||||
@ -83,7 +83,7 @@ export class SendResourcesAction extends ActionController {
|
||||
}
|
||||
|
||||
private getRecipientRequirements(villageId: number): Resources {
|
||||
const state = new VillageState(villageId);
|
||||
const state = new VillageStorage(villageId);
|
||||
const resources = state.getResources();
|
||||
const incoming = state.getIncomingMerchants().reduce((m, i) => m.add(i.resources), Resources.zero());
|
||||
const requirements = this.scheduler.getVillageRequiredResources(villageId);
|
||||
|
@ -13,14 +13,14 @@ import Vue from 'vue';
|
||||
import DashboardApp from './DashboardView/Dashboard.vue';
|
||||
import { ResourcesToLevel } from './Task/ResourcesToLevel';
|
||||
import { ConsoleLogger, Logger } from './Logger';
|
||||
import { VillageState } from './State/VillageState';
|
||||
import { VillageStorage } from './Storage/VillageStorage';
|
||||
import { Resources } from './Core/Resources';
|
||||
import { Coordinates, Village } from './Core/Village';
|
||||
import { calcGatheringTimings } from './Core/GatheringTimings';
|
||||
import { DataStorage } from './DataStorage';
|
||||
import { getBuildingPageAttributes, isBuildingPage } from './Page/PageDetectors';
|
||||
import { debounce } from 'debounce';
|
||||
import { ExecutionState } from './State/ExecutionState';
|
||||
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
||||
import { ResourceStorage } from './Core/ResourceStorage';
|
||||
|
||||
interface QuickAction {
|
||||
@ -50,7 +50,7 @@ export class ControlPanel {
|
||||
const scheduler = this.scheduler;
|
||||
const quickActions: QuickAction[] = [];
|
||||
|
||||
const executionState = new ExecutionState();
|
||||
const executionState = new ExecutionStorage();
|
||||
|
||||
const state: any = {
|
||||
name: 'Dashboard',
|
||||
@ -77,7 +77,7 @@ export class ControlPanel {
|
||||
|
||||
refreshVillages() {
|
||||
this.villages = grabVillageList().map(village => {
|
||||
return new VillageController(village, new VillageState(village.id), scheduler);
|
||||
return new VillageController(village, new VillageStorage(village.id), scheduler);
|
||||
});
|
||||
for (let village of this.villages) {
|
||||
if (village.active) {
|
||||
@ -183,7 +183,7 @@ class VillageController {
|
||||
public readonly granary: number;
|
||||
public readonly buildRemainingSeconds: number;
|
||||
|
||||
constructor(village: Village, state: VillageState, scheduler: Scheduler) {
|
||||
constructor(village: Village, state: VillageStorage, scheduler: Scheduler) {
|
||||
const resources = state.getResources();
|
||||
const storage = state.getResourceStorage();
|
||||
const performance = state.getResourcesPerformance();
|
||||
@ -228,7 +228,7 @@ class VillageController {
|
||||
return timings.hours * 3600;
|
||||
}
|
||||
|
||||
private calcIncomingResources(state: VillageState): Resources {
|
||||
private calcIncomingResources(state: VillageStorage): Resources {
|
||||
return state.getIncomingMerchants().reduce((m, i) => m.add(i.resources), new Resources(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ConsoleLogger, Logger, NullLogger } from './Logger';
|
||||
import { Logger, NullLogger } from './Logger';
|
||||
|
||||
const NAMESPACE = 'travian:v1';
|
||||
|
||||
@ -48,7 +48,6 @@ export class DataStorage {
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name;
|
||||
// this.logger = new ConsoleLogger(this.constructor.name);
|
||||
this.logger = new NullLogger();
|
||||
}
|
||||
|
||||
@ -89,11 +88,6 @@ export class DataStorage {
|
||||
return (plain as Array<any>).map(mapper);
|
||||
}
|
||||
|
||||
has(key: string): boolean {
|
||||
const fullKey = join(NAMESPACE, this.name, key);
|
||||
return storage.getItem(fullKey) !== null;
|
||||
}
|
||||
|
||||
set(key: string, value: any) {
|
||||
const fullKey = join(NAMESPACE, this.name, key);
|
||||
let serialized = JSON.stringify(value);
|
||||
|
@ -7,7 +7,7 @@ import { ConsoleLogger, Logger } from './Logger';
|
||||
import { GrabberManager } from './Grabber/GrabberManager';
|
||||
import { Scheduler } from './Scheduler';
|
||||
import { Statistics } from './Statistics';
|
||||
import { ExecutionState } from './State/ExecutionState';
|
||||
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
||||
import { Action } from './Queue/ActionQueue';
|
||||
import { Task } from './Queue/TaskProvider';
|
||||
|
||||
@ -20,7 +20,7 @@ export class Executor {
|
||||
private readonly scheduler: Scheduler;
|
||||
private grabbers: GrabberManager;
|
||||
private statistics: Statistics;
|
||||
private executionState: ExecutionState;
|
||||
private executionState: ExecutionStorage;
|
||||
private logger: Logger;
|
||||
|
||||
constructor(version: string, scheduler: Scheduler) {
|
||||
@ -28,7 +28,7 @@ export class Executor {
|
||||
this.scheduler = scheduler;
|
||||
this.grabbers = new GrabberManager();
|
||||
this.statistics = new Statistics();
|
||||
this.executionState = new ExecutionState();
|
||||
this.executionState = new ExecutionStorage();
|
||||
this.logger = new ConsoleLogger(this.constructor.name);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Grabber } from './Grabber';
|
||||
import { grabVillageList } from '../Page/VillageBlock';
|
||||
import { HeroState } from '../State/HeroState';
|
||||
import { HeroStorage } from '../Storage/HeroStorage';
|
||||
import { grabHeroAttributes, grabHeroVillage } from '../Page/HeroPage';
|
||||
import { isHeroPage } from '../Page/PageDetectors';
|
||||
|
||||
@ -10,7 +10,7 @@ export class HeroPageGrabber extends Grabber {
|
||||
return;
|
||||
}
|
||||
|
||||
const state = new HeroState();
|
||||
const state = new HeroStorage();
|
||||
|
||||
state.storeAttributes(grabHeroAttributes());
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Grabber } from './Grabber';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { VillageState } from '../State/VillageState';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
import { grabIncomingMerchants } from '../Page/BuildingPage';
|
||||
import { isMarketSendResourcesPage } from '../Page/PageDetectors';
|
||||
|
||||
@ -11,7 +11,7 @@ export class MarketPageGrabber extends Grabber {
|
||||
}
|
||||
|
||||
const villageId = grabActiveVillageId();
|
||||
const state = new VillageState(villageId);
|
||||
const state = new VillageStorage(villageId);
|
||||
state.storeIncomingMerchants(grabIncomingMerchants());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Grabber } from './Grabber';
|
||||
import { grabActiveVillageId, grabBuildingQueueInfo, grabResourcesPerformance } from '../Page/VillageBlock';
|
||||
import { VillageState } from '../State/VillageState';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
import { parseLocation } from '../utils';
|
||||
import { GrabError } from '../Errors';
|
||||
import { BuildingQueueInfo } from '../Game';
|
||||
@ -13,7 +13,7 @@ export class VillageOverviewPageGrabber extends Grabber {
|
||||
}
|
||||
|
||||
const villageId = grabActiveVillageId();
|
||||
const state = new VillageState(villageId);
|
||||
const state = new VillageStorage(villageId);
|
||||
state.storeResourcesPerformance(grabResourcesPerformance());
|
||||
state.storeBuildingQueueInfo(this.grabBuildingQueueInfoOrDefault());
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { Grabber } from './Grabber';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock';
|
||||
import { VillageState } from '../State/VillageState';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
|
||||
export class VillageResourceGrabber extends Grabber {
|
||||
grab(): void {
|
||||
const villageId = grabActiveVillageId();
|
||||
const state = new VillageState(villageId);
|
||||
const state = new VillageStorage(villageId);
|
||||
state.storeResources(grabVillageResources());
|
||||
state.storeResourceStorage(grabVillageResourceStorage());
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { StatisticsState } from './State/StatisticsState';
|
||||
import { StatisticsStorage } from './Storage/StatisticsStorage';
|
||||
import * as dateFormat from 'dateformat';
|
||||
|
||||
export interface ActionStatistics {
|
||||
@ -6,10 +6,10 @@ export interface ActionStatistics {
|
||||
}
|
||||
|
||||
export class Statistics {
|
||||
private state: StatisticsState;
|
||||
private state: StatisticsStorage;
|
||||
|
||||
constructor() {
|
||||
this.state = new StatisticsState();
|
||||
this.state = new StatisticsStorage();
|
||||
}
|
||||
|
||||
incrementAction(): void {
|
||||
|
@ -5,7 +5,7 @@ const NAMESPACE = 'execution.v1';
|
||||
|
||||
const SETTINGS_KEY = 'settings';
|
||||
|
||||
export class ExecutionState {
|
||||
export class ExecutionStorage {
|
||||
private storage: DataStorage;
|
||||
constructor() {
|
||||
this.storage = new DataStorage(NAMESPACE);
|
@ -4,7 +4,7 @@ import { HeroAttributes } from '../Core/Hero';
|
||||
const VILLAGE_ID_KEY = 'village_id';
|
||||
const ATTRIBUTES_KEY = 'attr';
|
||||
|
||||
export class HeroState {
|
||||
export class HeroStorage {
|
||||
private storage: DataStorage;
|
||||
constructor() {
|
||||
this.storage = new DataStorage('hero.v1');
|
@ -5,7 +5,7 @@ const NAMESPACE = 'statistics.v1';
|
||||
|
||||
const ACTION_STATISTICS_KEY = 'actions';
|
||||
|
||||
export class StatisticsState {
|
||||
export class StatisticsStorage {
|
||||
private storage: DataStorage;
|
||||
constructor() {
|
||||
this.storage = new DataStorage(NAMESPACE);
|
@ -14,7 +14,7 @@ const ResourceOptions = {
|
||||
factory: () => new Resources(0, 0, 0, 0),
|
||||
};
|
||||
|
||||
export class VillageState {
|
||||
export class VillageStorage {
|
||||
private storage: DataStorage;
|
||||
constructor(villageId: number) {
|
||||
this.storage = new DataStorage(`village.${villageId}`);
|
Loading…
Reference in New Issue
Block a user