diff --git a/src/Action/BalanceHeroResourcesAction.ts b/src/Action/BalanceHeroResourcesAction.ts index 23e12a5..3247f7f 100644 --- a/src/Action/BalanceHeroResourcesAction.ts +++ b/src/Action/BalanceHeroResourcesAction.ts @@ -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 { const activeVillageId = grabActiveVillageId(); - const heroVillageId = new HeroState().getVillageId(); + const heroVillageId = new HeroStorage().getVillageId(); if (heroVillageId === undefined || activeVillageId !== heroVillageId) { changeHeroResource(HeroAllResources); diff --git a/src/Action/GoToHeroVillageAction.ts b/src/Action/GoToHeroVillageAction.ts index 8c990e7..d1af798 100644 --- a/src/Action/GoToHeroVillageAction.ts +++ b/src/Action/GoToHeroVillageAction.ts @@ -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(); } } diff --git a/src/Action/SendResourcesAction.ts b/src/Action/SendResourcesAction.ts index a0fd71e..65f0048 100644 --- a/src/Action/SendResourcesAction.ts +++ b/src/Action/SendResourcesAction.ts @@ -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); diff --git a/src/ControlPanel.ts b/src/ControlPanel.ts index dadb996..928c6fc 100644 --- a/src/ControlPanel.ts +++ b/src/ControlPanel.ts @@ -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)); } } diff --git a/src/DataStorage.ts b/src/DataStorage.ts index 6aad0bc..65929f5 100644 --- a/src/DataStorage.ts +++ b/src/DataStorage.ts @@ -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).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); diff --git a/src/Executor.ts b/src/Executor.ts index ddda5ac..6a67dfd 100644 --- a/src/Executor.ts +++ b/src/Executor.ts @@ -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); } diff --git a/src/Grabber/HeroPageGrabber.ts b/src/Grabber/HeroPageGrabber.ts index b7f9f9d..36236ed 100644 --- a/src/Grabber/HeroPageGrabber.ts +++ b/src/Grabber/HeroPageGrabber.ts @@ -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()); diff --git a/src/Grabber/MarketPageGrabber.ts b/src/Grabber/MarketPageGrabber.ts index 4eeaa87..74aa7dd 100644 --- a/src/Grabber/MarketPageGrabber.ts +++ b/src/Grabber/MarketPageGrabber.ts @@ -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()); } } diff --git a/src/Grabber/VillageOverviewPageGrabber.ts b/src/Grabber/VillageOverviewPageGrabber.ts index 8771995..7d5cde7 100644 --- a/src/Grabber/VillageOverviewPageGrabber.ts +++ b/src/Grabber/VillageOverviewPageGrabber.ts @@ -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()); } diff --git a/src/Grabber/VillageResourceGrabber.ts b/src/Grabber/VillageResourceGrabber.ts index 5e12bf4..8d12736 100644 --- a/src/Grabber/VillageResourceGrabber.ts +++ b/src/Grabber/VillageResourceGrabber.ts @@ -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()); } diff --git a/src/Statistics.ts b/src/Statistics.ts index 28d62cd..8ac8eca 100644 --- a/src/Statistics.ts +++ b/src/Statistics.ts @@ -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 { diff --git a/src/State/ExecutionState.ts b/src/Storage/ExecutionStorage.ts similarity index 94% rename from src/State/ExecutionState.ts rename to src/Storage/ExecutionStorage.ts index 98e5508..961f495 100644 --- a/src/State/ExecutionState.ts +++ b/src/Storage/ExecutionStorage.ts @@ -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); diff --git a/src/State/HeroState.ts b/src/Storage/HeroStorage.ts similarity index 96% rename from src/State/HeroState.ts rename to src/Storage/HeroStorage.ts index 2a9ea67..6a94885 100644 --- a/src/State/HeroState.ts +++ b/src/Storage/HeroStorage.ts @@ -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'); diff --git a/src/State/StatisticsState.ts b/src/Storage/StatisticsStorage.ts similarity index 94% rename from src/State/StatisticsState.ts rename to src/Storage/StatisticsStorage.ts index f83b591..8b89a52 100644 --- a/src/State/StatisticsState.ts +++ b/src/Storage/StatisticsStorage.ts @@ -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); diff --git a/src/State/VillageState.ts b/src/Storage/VillageStorage.ts similarity index 98% rename from src/State/VillageState.ts rename to src/Storage/VillageStorage.ts index 04ae939..468f918 100644 --- a/src/State/VillageState.ts +++ b/src/Storage/VillageStorage.ts @@ -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}`);