Skip to content

Commit

Permalink
feat(settings): Safeguard all loader loops
Browse files Browse the repository at this point in the history
This completes fed72a7 and might already make the modern settings storage a feasible solution now.
  • Loading branch information
oliversalzburg committed Nov 18, 2022
1 parent 9ab11b5 commit 543744a
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 90 deletions.
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/MissionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { difference } from "../tools/Array";
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { cwarn } from "../tools/Log";
import { GamePage, Missions } from "../types";
import { Setting } from "./Settings";
Expand Down Expand Up @@ -78,9 +78,9 @@ export class MissionSettings extends Setting {
load(settings: MissionSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.missions)) {
this.missions[name].enabled = item.enabled;
}
consumeEntriesPedantic(this.missions, settings.missions, (mission, item) => {
mission.enabled = item?.enabled ?? mission.enabled;
});
}

static toLegacyOptions(settings: MissionSettings, subject: LegacyStorage) {
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/PolicySettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { difference } from "../tools/Array";
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { cwarn } from "../tools/Log";
import { GamePage, Policy } from "../types";
import { Setting } from "./Settings";
Expand Down Expand Up @@ -86,9 +86,9 @@ export class PolicySettings extends Setting {
load(settings: PolicySettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.policies)) {
this.policies[name].enabled = item.enabled;
}
consumeEntriesPedantic(this.policies, settings.policies, (policy, item) => {
policy.enabled = item?.enabled ?? policy.enabled;
});
}

static toLegacyOptions(settings: PolicySettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ReligionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { UnicornItemVariant } from "../types";
import { Requirement, Setting, SettingMax, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -318,10 +318,10 @@ export class ReligionSettings extends SettingTrigger {
this.enabled = settings.enabled;
this.trigger = settings.trigger;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].max = item.max;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
});

this.adore.enabled = settings.adore.enabled;
this.autoPraise.enabled = settings.autoPraise.enabled;
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ResetBonfireSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { BonfireItem } from "./BonfireSettings";
import { Setting, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -74,10 +74,10 @@ export class ResetBonfireSettings extends Setting {
load(settings: ResetBonfireSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].trigger = item.trigger;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.trigger = item?.trigger ?? building.trigger;
});
}

static toLegacyOptions(settings: ResetBonfireSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ResetReligionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { UnicornItemVariant } from "../types";
import { FaithItem, UnicornItem } from "./ReligionSettings";
import { Setting, SettingTrigger } from "./Settings";
Expand Down Expand Up @@ -215,10 +215,10 @@ export class ResetReligionSettings extends Setting {
load(settings: ResetReligionSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].trigger = item.trigger;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.trigger = item?.trigger ?? building.trigger;
});
}

static toLegacyOptions(settings: ResetReligionSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ResetResourcesSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { isNil, mustExist } from "../tools/Maybe";
import { Resource } from "../types";
import { Setting } from "./Settings";
Expand Down Expand Up @@ -81,10 +81,10 @@ export class ResetResourcesSettings extends Setting {
load(settings: ResetResourcesSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.resources)) {
this.resources[name].enabled = item.enabled;
this.resources[name].stock = item.stock;
}
consumeEntriesPedantic(this.resources, settings.resources, (resource, item) => {
resource.enabled = item?.enabled ?? resource.enabled;
resource.stock = item?.stock ?? resource.stock;
});
}

static toLegacyOptions(settings: ResetResourcesSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ResetSpaceSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { SpaceBuildings } from "../types";
import { Setting, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -51,10 +51,10 @@ export class ResetSpaceSettings extends Setting {
load(settings: ResetSpaceSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].trigger = item.trigger;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.trigger = item?.trigger ?? building.trigger;
});
}

static toLegacyOptions(settings: ResetSpaceSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/ResetTimeSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { TimeItemVariant } from "../types";
import { Setting, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -83,10 +83,10 @@ export class ResetTimeSettings extends Setting {
load(settings: ResetTimeSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].trigger = item.trigger;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.trigger = item?.trigger ?? building.trigger;
});
}

static toLegacyOptions(settings: ResetTimeSettings, subject: LegacyStorage) {
Expand Down
12 changes: 6 additions & 6 deletions packages/userscript/source/settings/ResourcesSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { isNil, mustExist } from "../tools/Maybe";
import { Resource } from "../types";
import { WorkshopManager } from "../WorkshopManager";
Expand Down Expand Up @@ -88,11 +88,11 @@ export class ResourcesSettings extends Setting {
load(settings: ResourcesSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.resources)) {
this.resources[name].enabled = item.enabled;
this.resources[name].consume = item.consume;
this.resources[name].stock = item.stock;
}
consumeEntriesPedantic(this.resources, settings.resources, (resource, item) => {
resource.enabled = item?.enabled ?? resource.enabled;
resource.consume = item?.consume ?? resource.consume;
resource.stock = item?.stock ?? resource.stock;
});
}

static toLegacyOptions(settings: ResourcesSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/SpaceSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { GamePage, SpaceBuildings } from "../types";
import { MissionSettings } from "./MissionSettings";
import { SettingMax, SettingTrigger } from "./Settings";
Expand Down Expand Up @@ -61,10 +61,10 @@ export class SpaceSettings extends SettingTrigger {
this.enabled = settings.enabled;
this.trigger = settings.trigger;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].max = item.max;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
});

this.unlockMissions.load(settings.unlockMissions);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/TechSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { difference } from "../tools/Array";
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { cwarn } from "../tools/Log";
import { GamePage, Technology } from "../types";
import { Setting } from "./Settings";
Expand Down Expand Up @@ -108,9 +108,9 @@ export class TechSettings extends Setting {
load(settings: TechSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.techs)) {
this.techs[name].enabled = item.enabled;
}
consumeEntriesPedantic(this.techs, settings.techs, (tech, item) => {
tech.enabled = item?.enabled ?? tech.enabled;
});
}

static toLegacyOptions(settings: TechSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/TimeSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { ChronoForgeUpgrades, TimeItemVariant, VoidSpaceUpgrades } from "../types";
import { Requirement, SettingMax, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -64,10 +64,10 @@ export class TimeSettings extends SettingTrigger {
this.enabled = settings.enabled;
this.trigger = settings.trigger;

for (const [name, item] of objectEntries(settings.buildings)) {
this.buildings[name].enabled = item.enabled;
this.buildings[name].max = item.max;
}
consumeEntriesPedantic(this.buildings, settings.buildings, (building, item) => {
building.enabled = item?.enabled ?? building.enabled;
building.max = item?.max ?? building.max;
});
}

static toLegacyOptions(settings: TimeSettings, subject: LegacyStorage) {
Expand Down
15 changes: 7 additions & 8 deletions packages/userscript/source/settings/TimeSkipSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { Cycle, Season } from "../types";
import { Setting, SettingTriggerMax } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -52,13 +52,12 @@ export class TimeSkipSettings extends SettingTriggerMax {
super.load(settings);
this.max = settings.max;

for (const [name, item] of objectEntries(settings.seasons)) {
this.seasons[name].enabled = item.enabled;
}

for (const [name, item] of objectEntries(settings.cycles)) {
this.cycles[name].enabled = item.enabled;
}
consumeEntriesPedantic(this.seasons, settings.seasons, (season, item) => {
season.enabled = item?.enabled ?? season.enabled;
});
consumeEntriesPedantic(this.cycles, settings.cycles, (cycle, item) => {
cycle.enabled = item?.enabled ?? cycle.enabled;
});
}

static toLegacyOptions(settings: TimeSkipSettings, subject: LegacyStorage) {
Expand Down
18 changes: 9 additions & 9 deletions packages/userscript/source/settings/TradeSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { Race, Season } from "../types";
import { EmbassySettings } from "./EmbassySettings";
import { Requirement, Setting, SettingLimited, SettingTrigger } from "./Settings";
Expand Down Expand Up @@ -87,14 +87,14 @@ export class TradeSettings extends SettingTrigger {
this.enabled = settings.enabled;
this.trigger = settings.trigger;

for (const [name, item] of objectEntries(settings.races)) {
this.races[name].enabled = item.enabled;
this.races[name].limited = item.limited;
this.races[name].seasons.autumn = item.seasons.autumn;
this.races[name].seasons.spring = item.seasons.spring;
this.races[name].seasons.summer = item.seasons.summer;
this.races[name].seasons.winter = item.seasons.winter;
}
consumeEntriesPedantic(this.races, settings.races, (race, item) => {
race.enabled = item?.enabled ?? race.enabled;
race.limited = item?.limited ?? race.limited;
race.seasons.autumn = item?.seasons.autumn ?? race.seasons.autumn;
race.seasons.spring = item?.seasons.spring ?? race.seasons.spring;
race.seasons.summer = item?.seasons.summer ?? race.seasons.summer;
race.seasons.winter = item?.seasons.winter ?? race.seasons.winter;
});

this.buildEmbassies.load(settings.buildEmbassies);
this.feedLeviathans.load(settings.feedLeviathans);
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/UpgradeSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { difference } from "../tools/Array";
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { cwarn } from "../tools/Log";
import { GamePage, Upgrade } from "../types";
import { Setting } from "./Settings";
Expand Down Expand Up @@ -183,9 +183,9 @@ export class UpgradeSettings extends Setting {
load(settings: UpgradeSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.upgrades)) {
this.upgrades[name].enabled = item.enabled;
}
consumeEntriesPedantic(this.upgrades, settings.upgrades, (upgrade, item) => {
upgrade.enabled = item?.enabled ?? upgrade.enabled;
});
}

static toLegacyOptions(settings: UpgradeSettings, subject: LegacyStorage) {
Expand Down
10 changes: 5 additions & 5 deletions packages/userscript/source/settings/VillageSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { Job } from "../types";
import { Setting, SettingMax, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -38,10 +38,10 @@ export class VillageSettings extends Setting {
load(settings: VillageSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.jobs)) {
this.jobs[name].enabled = item.enabled;
this.jobs[name].max = item.max;
}
consumeEntriesPedantic(this.jobs, settings.jobs, (job, item) => {
job.enabled = item?.enabled ?? job.enabled;
job.max = item?.max ?? job.max;
});

this.holdFestivals.enabled = settings.holdFestivals.enabled;
this.hunt.enabled = settings.hunt.enabled;
Expand Down
12 changes: 6 additions & 6 deletions packages/userscript/source/settings/WorkshopSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectEntries } from "../tools/Entries";
import { consumeEntriesPedantic, objectEntries } from "../tools/Entries";
import { GamePage, ResourceCraftable } from "../types";
import { Requirement, Setting, SettingLimitedMax, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand Down Expand Up @@ -68,11 +68,11 @@ export class WorkshopSettings extends SettingTrigger {
load(settings: WorkshopSettings) {
this.enabled = settings.enabled;

for (const [name, item] of objectEntries(settings.resources)) {
this.resources[name].enabled = item.enabled;
this.resources[name].limited = item.limited;
this.resources[name].max = item.max;
}
consumeEntriesPedantic(this.resources, settings.resources, (resource, item) => {
resource.enabled = item?.enabled ?? resource.enabled;
resource.limited = item?.limited ?? resource.limited;
resource.max = item?.max ?? resource.max;
});

this.unlockUpgrades.load(settings.unlockUpgrades);

Expand Down

0 comments on commit 543744a

Please sign in to comment.