From 6b8aad78797a62cbb3c59e5266fa2461c01d7eb2 Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Sun, 8 Jan 2023 18:46:25 +0100 Subject: [PATCH] refactor(core): Bypass manager to load settings --- .vscode/settings.json | 2 ++ packages/userscript/source/BonfireManager.ts | 6 +----- packages/userscript/source/Engine.ts | 18 +++++++++--------- packages/userscript/source/ReligionManager.ts | 6 +----- packages/userscript/source/ScienceManager.ts | 6 +----- packages/userscript/source/SpaceManager.ts | 6 +----- .../userscript/source/TimeControlManager.ts | 6 +----- packages/userscript/source/TimeManager.ts | 6 +----- packages/userscript/source/TradeManager.ts | 6 +----- packages/userscript/source/UserScript.ts | 4 ++-- packages/userscript/source/VillageManager.ts | 6 +----- packages/userscript/source/WorkshopManager.ts | 6 +----- 12 files changed, 22 insertions(+), 56 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bf5b87863..eb726d1ef 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,7 @@ "cSpell.words": [ "Astro", "autofeed", + "beforesave", "biolab", "Blackcoin", "blackcoins", @@ -30,6 +31,7 @@ "chronoforge", "chronofurnace", "chronosphere", + "cinfo", "Craftable", "Cryochamber", "Cryochambers", diff --git a/packages/userscript/source/BonfireManager.ts b/packages/userscript/source/BonfireManager.ts index 347a09877..bca8f29dc 100644 --- a/packages/userscript/source/BonfireManager.ts +++ b/packages/userscript/source/BonfireManager.ts @@ -20,7 +20,7 @@ export type BonfireTab = GameTab; export class BonfireManager implements Automation { private readonly _host: UserScript; - settings: BonfireSettings; + readonly settings: BonfireSettings; readonly manager: TabManager; private readonly _bulkManager: BulkPurchaseHelper; private readonly _workshopManager: WorkshopManager; @@ -47,10 +47,6 @@ export class BonfireManager implements Automation { this.autoMisc(); } - load(settings: BonfireSettings) { - this.settings.load(settings); - } - /** * Try to build as many of the passed buildings as possible. * Usually, this is called at each iteration of the automation engine to diff --git a/packages/userscript/source/Engine.ts b/packages/userscript/source/Engine.ts index 4b54b991e..47c3db2fa 100644 --- a/packages/userscript/source/Engine.ts +++ b/packages/userscript/source/Engine.ts @@ -133,15 +133,15 @@ export class Engine { }; attemptLoad(() => this.settings.load(settings.engine), "engine"); - attemptLoad(() => this.bonfireManager.load(settings.bonfire), "bonfire"); - attemptLoad(() => this.religionManager.load(settings.religion), "religion"); - attemptLoad(() => this.scienceManager.load(settings.science), "science"); - attemptLoad(() => this.spaceManager.load(settings.space), "space"); - attemptLoad(() => this.timeControlManager.load(settings.timeControl), "time control"); - attemptLoad(() => this.timeManager.load(settings.time), "time"); - attemptLoad(() => this.tradeManager.load(settings.trade), "trade"); - attemptLoad(() => this.villageManager.load(settings.village), "village"); - attemptLoad(() => this.workshopManager.load(settings.workshop), "workshop"); + attemptLoad(() => this.bonfireManager.settings.load(settings.bonfire), "bonfire"); + attemptLoad(() => this.religionManager.settings.load(settings.religion), "religion"); + attemptLoad(() => this.scienceManager.settings.load(settings.science), "science"); + attemptLoad(() => this.spaceManager.settings.load(settings.space), "space"); + attemptLoad(() => this.timeControlManager.settings.load(settings.timeControl), "time control"); + attemptLoad(() => this.timeManager.settings.load(settings.time), "time"); + attemptLoad(() => this.tradeManager.settings.load(settings.trade), "trade"); + attemptLoad(() => this.villageManager.settings.load(settings.village), "village"); + attemptLoad(() => this.workshopManager.settings.load(settings.workshop), "workshop"); } /** diff --git a/packages/userscript/source/ReligionManager.ts b/packages/userscript/source/ReligionManager.ts index 07b6b6a3b..832ab075b 100644 --- a/packages/userscript/source/ReligionManager.ts +++ b/packages/userscript/source/ReligionManager.ts @@ -30,7 +30,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class ReligionManager implements Automation { private readonly _host: UserScript; - settings: ReligionSettings; + readonly settings: ReligionSettings; readonly manager: TabManager; private readonly _bulkManager: BulkPurchaseHelper; private readonly _bonfireManager: BonfireManager; @@ -68,10 +68,6 @@ export class ReligionManager implements Automation { this._autoTAP(); } - load(settings: ReligionSettings) { - this.settings.load(settings); - } - private _autoBuild() { if (this.settings.bestUnicornBuilding.enabled) { this._buildBestUnicornBuilding(); diff --git a/packages/userscript/source/ScienceManager.ts b/packages/userscript/source/ScienceManager.ts index aca84faa0..132357646 100644 --- a/packages/userscript/source/ScienceManager.ts +++ b/packages/userscript/source/ScienceManager.ts @@ -10,7 +10,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class ScienceManager extends UpgradeManager { readonly manager: TabManager; - settings: ScienceSettings; + readonly settings: ScienceSettings; private readonly _workshopManager: WorkshopManager; constructor( @@ -44,10 +44,6 @@ export class ScienceManager extends UpgradeManager { } } - load(settings: ScienceSettings) { - this.settings.load(settings); - } - async autoUnlock() { this.manager.render(); diff --git a/packages/userscript/source/SpaceManager.ts b/packages/userscript/source/SpaceManager.ts index 89222e550..d04e2229c 100644 --- a/packages/userscript/source/SpaceManager.ts +++ b/packages/userscript/source/SpaceManager.ts @@ -17,7 +17,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class SpaceManager implements Automation { private readonly _host: UserScript; - settings: SpaceSettings; + readonly settings: SpaceSettings; readonly manager: TabManager; private readonly _bulkManager: BulkPurchaseHelper; private readonly _workshopManager: WorkshopManager; @@ -43,10 +43,6 @@ export class SpaceManager implements Automation { } } - load(settings: SpaceSettings) { - this.settings.load(settings); - } - /** * Try to build as many of the passed buildings as possible. * Usually, this is called at each iteration of the automation engine to diff --git a/packages/userscript/source/TimeControlManager.ts b/packages/userscript/source/TimeControlManager.ts index 31f76b690..8e8cc6741 100644 --- a/packages/userscript/source/TimeControlManager.ts +++ b/packages/userscript/source/TimeControlManager.ts @@ -23,7 +23,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class TimeControlManager { private readonly _host: UserScript; - settings: TimeControlSettings; + readonly settings: TimeControlSettings; readonly manager: TabManager; private readonly _bonfireManager: BonfireManager; private readonly _religionManager: ReligionManager; @@ -64,10 +64,6 @@ export class TimeControlManager { } } - load(settings: TimeControlSettings) { - this.settings.load(settings); - } - async autoReset(engine: Engine) { // Don't reset if there's a challenge running. if (this._host.gamePage.challenges.currentChallenge) { diff --git a/packages/userscript/source/TimeManager.ts b/packages/userscript/source/TimeManager.ts index 0fbffce2e..0bec4eac3 100644 --- a/packages/userscript/source/TimeManager.ts +++ b/packages/userscript/source/TimeManager.ts @@ -21,7 +21,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class TimeManager { private readonly _host: UserScript; - settings: TimeSettings; + readonly settings: TimeSettings; readonly manager: TabManager; private readonly _bulkManager: BulkPurchaseHelper; @@ -47,10 +47,6 @@ export class TimeManager { } } - load(settings: TimeSettings) { - this.settings.load(settings); - } - /** * Try to build as many of the passed buildings as possible. * Usually, this is called at each iteration of the automation engine to diff --git a/packages/userscript/source/TradeManager.ts b/packages/userscript/source/TradeManager.ts index 6f7af91df..fdb418d48 100644 --- a/packages/userscript/source/TradeManager.ts +++ b/packages/userscript/source/TradeManager.ts @@ -12,7 +12,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class TradeManager implements Automation { private readonly _host: UserScript; - settings: TradeSettings; + readonly settings: TradeSettings; readonly manager: TabManager; private readonly _workshopManager: WorkshopManager; @@ -44,10 +44,6 @@ export class TradeManager implements Automation { } } - load(settings: TradeSettings) { - this.settings.load(settings); - } - autoTrade(cacheManager?: MaterialsCache) { const catpower = this._workshopManager.getResource("manpower"); const gold = this._workshopManager.getResource("gold"); diff --git a/packages/userscript/source/UserScript.ts b/packages/userscript/source/UserScript.ts index cbcdab1df..a0a8405bd 100644 --- a/packages/userscript/source/UserScript.ts +++ b/packages/userscript/source/UserScript.ts @@ -196,7 +196,7 @@ export class UserScript { }, resetState: () => null, save: (saveData: Record) => { - // We ignore the manager invokation, because we already handle the + // We ignore the manager invocation, because we already handle the // `game/beforesave` event, which is intended for external consumers. }, }; @@ -275,7 +275,7 @@ export class UserScript { } /** - * Returns an instance of the userscript in our default confiuration. + * Returns an instance of the userscript in our default configuration. * * @returns The default userscript instance. */ diff --git a/packages/userscript/source/VillageManager.ts b/packages/userscript/source/VillageManager.ts index 4f45ff22f..db9ef9f27 100644 --- a/packages/userscript/source/VillageManager.ts +++ b/packages/userscript/source/VillageManager.ts @@ -12,7 +12,7 @@ import { WorkshopManager } from "./WorkshopManager"; export class VillageManager implements Automation { private readonly _host: UserScript; - settings: VillageSettings; + readonly settings: VillageSettings; readonly manager: TabManager; private readonly _cacheManager: MaterialsCache; private readonly _workshopManager: WorkshopManager; @@ -57,10 +57,6 @@ export class VillageManager implements Automation { } } - load(settings: VillageSettings) { - this.settings.load(settings); - } - autoDistributeKittens() { const freeKittens = this._host.gamePage.village.getFreeKittens(); if (!freeKittens) { diff --git a/packages/userscript/source/WorkshopManager.ts b/packages/userscript/source/WorkshopManager.ts index 87ff6924e..9feeee71f 100644 --- a/packages/userscript/source/WorkshopManager.ts +++ b/packages/userscript/source/WorkshopManager.ts @@ -12,7 +12,7 @@ import { UpgradeManager } from "./UpgradeManager"; import { UserScript } from "./UserScript"; export class WorkshopManager extends UpgradeManager implements Automation { - settings: WorkshopSettings; + readonly settings: WorkshopSettings; readonly manager: TabManager; static readonly DEFAULT_CONSUME_RATE = 1; @@ -36,10 +36,6 @@ export class WorkshopManager extends UpgradeManager implements Automation { } } - load(settings: WorkshopSettings) { - this.settings.load(settings); - } - async autoUnlock() { if (!this._host.gamePage.tabs[3].visible) { return;