Skip to content

Commit

Permalink
refactor(core): Bypass manager to load settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Jan 8, 2023
1 parent cf2e4bc commit 6b8aad7
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cSpell.words": [
"Astro",
"autofeed",
"beforesave",
"biolab",
"Blackcoin",
"blackcoins",
Expand All @@ -30,6 +31,7 @@
"chronoforge",
"chronofurnace",
"chronosphere",
"cinfo",
"Craftable",
"Cryochamber",
"Cryochambers",
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/BonfireManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BonfireTab>;
private readonly _bulkManager: BulkPurchaseHelper;
private readonly _workshopManager: WorkshopManager;
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions packages/userscript/source/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/ReligionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReligionTab>;
private readonly _bulkManager: BulkPurchaseHelper;
private readonly _bonfireManager: BonfireManager;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/ScienceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { WorkshopManager } from "./WorkshopManager";

export class ScienceManager extends UpgradeManager {
readonly manager: TabManager<ScienceTab>;
settings: ScienceSettings;
readonly settings: ScienceSettings;
private readonly _workshopManager: WorkshopManager;

constructor(
Expand Down Expand Up @@ -44,10 +44,6 @@ export class ScienceManager extends UpgradeManager {
}
}

load(settings: ScienceSettings) {
this.settings.load(settings);
}

async autoUnlock() {
this.manager.render();

Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/SpaceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpaceTab>;
private readonly _bulkManager: BulkPurchaseHelper;
private readonly _workshopManager: WorkshopManager;
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/TimeControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { WorkshopManager } from "./WorkshopManager";

export class TimeControlManager {
private readonly _host: UserScript;
settings: TimeControlSettings;
readonly settings: TimeControlSettings;
readonly manager: TabManager<TimeTab>;
private readonly _bonfireManager: BonfireManager;
private readonly _religionManager: ReligionManager;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/TimeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { WorkshopManager } from "./WorkshopManager";

export class TimeManager {
private readonly _host: UserScript;
settings: TimeSettings;
readonly settings: TimeSettings;
readonly manager: TabManager<TimeTab>;
private readonly _bulkManager: BulkPurchaseHelper;

Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/TradeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TradeTab>;
private readonly _workshopManager: WorkshopManager;

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/source/UserScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class UserScript {
},
resetState: () => null,
save: (saveData: Record<string, unknown>) => {
// 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.
},
};
Expand Down Expand Up @@ -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.
*/
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/VillageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<VillageTab>;
private readonly _cacheManager: MaterialsCache;
private readonly _workshopManager: WorkshopManager;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions packages/userscript/source/WorkshopManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<VillageTab>;

static readonly DEFAULT_CONSUME_RATE = 1;
Expand All @@ -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;
Expand Down

0 comments on commit 6b8aad7

Please sign in to comment.