Skip to content

Commit

Permalink
refactor: Further clean up settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Oct 27, 2022
1 parent cf75cc4 commit e510324
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class BuildingUpgradeSetting extends Setting {
}
}

export type BuildingUpdateBuildingSettings = Record<StagedBuilding, BuildingUpgradeSetting>;

export class BuildingUpgradeSettings extends Setting {
buildings: {
[item in StagedBuilding]: BuildingUpgradeSetting;
};
buildings: BuildingUpdateBuildingSettings;

constructor(
enabled = false,
buildings = {
buildings: BuildingUpdateBuildingSettings = {
broadcasttower: new BuildingUpgradeSetting("broadcasttower", true),
dataCenter: new BuildingUpgradeSetting("dataCenter", true),
hydroplant: new BuildingUpgradeSetting("hydroplant", true),
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/EmbassySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class EmbassySetting extends SettingMax {
}
}

export type EmbassyRaceSettings = Record<Race, SettingMax>;

export class EmbassySettings extends SettingTrigger {
races: {
[item in Race]: SettingMax;
};
races: EmbassyRaceSettings;

constructor(
enabled = false,
races = {
races: EmbassyRaceSettings = {
dragons: new EmbassySetting("dragons", true),
griffins: new EmbassySetting("griffins", true),
leviathans: new EmbassySetting("leviathans", true),
Expand Down
58 changes: 37 additions & 21 deletions packages/userscript/source/settings/FilterSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ export type FilterItem =
export class FilterSettingsItem extends Setting {
variant: FilterItemVariant;

constructor(id: string, variant: FilterItemVariant) {
constructor(variant: FilterItemVariant) {
super(true);
this.variant = variant;
}
}

export type FilterSettingsItems = {
[item in FilterItem]: FilterSettingsItem;
build: FilterSettingsItem;
craft: FilterSettingsItem;
upgrade: FilterSettingsItem;
research: FilterSettingsItem;
trade: FilterSettingsItem;
hunt: FilterSettingsItem;
praise: FilterSettingsItem;
adore: FilterSettingsItem;
transcend: FilterSettingsItem;
faith: FilterSettingsItem;
accelerate: FilterSettingsItem;
timeSkip: FilterSettingsItem;
festival: FilterSettingsItem;
star: FilterSettingsItem;
distribute: FilterSettingsItem;
promote: FilterSettingsItem;
misc: FilterSettingsItem;
};

export class FilterSettings extends Setting {
Expand All @@ -60,23 +76,23 @@ export class FilterSettings extends Setting {
constructor(
enabled = false,
filters: FilterSettingsItems = {
buildFilter: new FilterSettingsItem("buildFilter", FilterItemVariant.Build),
craftFilter: new FilterSettingsItem("craftFilter", FilterItemVariant.Craft),
upgradeFilter: new FilterSettingsItem("upgradeFilter", FilterItemVariant.Upgrade),
researchFilter: new FilterSettingsItem("researchFilter", FilterItemVariant.Research),
tradeFilter: new FilterSettingsItem("tradeFilter", FilterItemVariant.Trade),
huntFilter: new FilterSettingsItem("huntFilter", FilterItemVariant.Hunt),
praiseFilter: new FilterSettingsItem("praiseFilter", FilterItemVariant.Praise),
adoreFilter: new FilterSettingsItem("adoreFilter", FilterItemVariant.Adore),
transcendFilter: new FilterSettingsItem("transcendFilter", FilterItemVariant.Transcend),
faithFilter: new FilterSettingsItem("faithFilter", FilterItemVariant.Faith),
accelerateFilter: new FilterSettingsItem("accelerateFilter", FilterItemVariant.Accelerate),
timeSkipFilter: new FilterSettingsItem("timeSkipFilter", FilterItemVariant.TimeSkip),
festivalFilter: new FilterSettingsItem("festivalFilter", FilterItemVariant.Festival),
starFilter: new FilterSettingsItem("starFilter", FilterItemVariant.Star),
distributeFilter: new FilterSettingsItem("distributeFilter", FilterItemVariant.Distribute),
promoteFilter: new FilterSettingsItem("promoteFilter", FilterItemVariant.Promote),
miscFilter: new FilterSettingsItem("miscFilter", FilterItemVariant.Misc),
build: new FilterSettingsItem(FilterItemVariant.Build),
craft: new FilterSettingsItem(FilterItemVariant.Craft),
upgrade: new FilterSettingsItem(FilterItemVariant.Upgrade),
research: new FilterSettingsItem(FilterItemVariant.Research),
trade: new FilterSettingsItem(FilterItemVariant.Trade),
hunt: new FilterSettingsItem(FilterItemVariant.Hunt),
praise: new FilterSettingsItem(FilterItemVariant.Praise),
adore: new FilterSettingsItem(FilterItemVariant.Adore),
transcend: new FilterSettingsItem(FilterItemVariant.Transcend),
faith: new FilterSettingsItem(FilterItemVariant.Faith),
accelerate: new FilterSettingsItem(FilterItemVariant.Accelerate),
timeSkip: new FilterSettingsItem(FilterItemVariant.TimeSkip),
festival: new FilterSettingsItem(FilterItemVariant.Festival),
star: new FilterSettingsItem(FilterItemVariant.Star),
distribute: new FilterSettingsItem(FilterItemVariant.Distribute),
promote: new FilterSettingsItem(FilterItemVariant.Promote),
misc: new FilterSettingsItem(FilterItemVariant.Misc),
}
) {
super(enabled);
Expand All @@ -95,7 +111,7 @@ export class FilterSettings extends Setting {
subject.toggles.filter = settings.enabled;

for (const [name, item] of objectEntries(settings.filters)) {
subject.items[`toggle-${name}` as const] = item.enabled;
subject.items[`toggle-${name}Filter` as const] = item.enabled;
}
}

Expand All @@ -104,7 +120,7 @@ export class FilterSettings extends Setting {
options.enabled = subject.toggles.filter;

for (const [name, item] of objectEntries(options.filters)) {
item.enabled = subject.items[`toggle-${name}` as const] ?? item.enabled;
item.enabled = subject.items[`toggle-${name}Filter` as const] ?? item.enabled;
}
return options;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/MissionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class MissionSetting extends Setting {
}
}

export type MissionMissionSettings = Record<Missions, MissionSetting>;

export class MissionSettings extends Setting {
missions: {
[item in Missions]: MissionSetting;
};
missions: MissionMissionSettings;

constructor(
enabled = false,
missions = {
missions: MissionMissionSettings = {
centaurusSystemMission: new MissionSetting("centaurusSystemMission", true),
charonMission: new MissionSetting("charonMission", true),
duneMission: new MissionSetting("duneMission", true),
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/PolicySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class PolicySetting extends Setting {
}
}

export type PolicyPolicySettings = Record<Policy, PolicySetting>;

export class PolicySettings extends Setting {
policies: {
[item in Policy]: PolicySetting;
};
policies: PolicyPolicySettings;

constructor(
enabled = false,
policies = {
policies: PolicyPolicySettings = {
authocracy: new PolicySetting("authocracy", false),
bigStickPolicy: new PolicySetting("bigStickPolicy", false),
carnivale: new PolicySetting("carnivale", false),
Expand Down
13 changes: 8 additions & 5 deletions packages/userscript/source/settings/ResetBonfireSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ export class ResetBonfireBuildingSetting extends SettingTrigger {
}
}

// unicornPasture is handled in the Religion section.
export type ResetBonfireBuildingSettings = Record<
Exclude<BonfireItem, "unicornPasture">,
ResetBonfireBuildingSetting
>;

export class ResetBonfireSettings extends Setting {
readonly buildings: {
// unicornPasture is handled in the Religion section.
[item in Exclude<BonfireItem, "unicornPasture">]: ResetBonfireBuildingSetting;
};
readonly buildings: ResetBonfireBuildingSettings;

constructor(
enabled = false,
buildings = {
buildings: ResetBonfireBuildingSettings = {
academy: new ResetBonfireBuildingSetting("academy", true, -1),
accelerator: new ResetBonfireBuildingSetting("accelerator", true, -1),
aiCore: new ResetBonfireBuildingSetting("aiCore", true, -1),
Expand Down
9 changes: 7 additions & 2 deletions packages/userscript/source/settings/ResetReligionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ export class ResetReligionBuildingSetting extends SettingTrigger {
}
}

export type ResetReligionBuildingSettings = Record<
FaithItem | UnicornItem,
ResetReligionBuildingSetting
>;

export class ResetReligionSettings extends Setting {
readonly buildings: { [item in FaithItem | UnicornItem]: ResetReligionBuildingSetting };
readonly buildings: ResetReligionBuildingSettings;

constructor(
enabled = false,
buildings = {
buildings: ResetReligionBuildingSettings = {
apocripha: new ResetReligionBuildingSetting(
"apocripha",
UnicornItemVariant.OrderOfTheSun,
Expand Down
6 changes: 4 additions & 2 deletions packages/userscript/source/settings/ResetResourcesSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ export class ResetResourcesSettingsItem extends Setting {
}
}

export type ResetResourcesResourceSettings = Record<Resource, ResetResourcesSettingsItem>;

export class ResetResourcesSettings extends Setting {
resources: { [item in Resource]: ResetResourcesSettingsItem };
resources: ResetResourcesResourceSettings;

constructor(
enabled = false,
resources = {
resources: ResetResourcesResourceSettings = {
alloy: new ResetResourcesSettingsItem("alloy", false, 0),
antimatter: new ResetResourcesSettingsItem("antimatter", false, 0),
beam: new ResetResourcesSettingsItem("beam", false, 0),
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/ResetSpaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export class ResetSpaceBuildingSetting extends SettingTrigger {
}
}

export type ResetSpaceBuildingSettings = Record<SpaceBuildings, SettingTrigger>;

export class ResetSpaceSettings extends Setting {
readonly buildings: {
[item in SpaceBuildings]: SettingTrigger;
};
readonly buildings: ResetSpaceBuildingSettings;

constructor(
enabled = false,
buildings = {
buildings: ResetSpaceBuildingSettings = {
containmentChamber: new ResetSpaceBuildingSetting("containmentChamber", true, -1),
cryostation: new ResetSpaceBuildingSetting("cryostation", true, -1),
entangler: new ResetSpaceBuildingSetting("entangler", true, -1),
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/ResetTimeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export class ResetTimeBuildingSetting extends SettingTrigger {
}
}

export type ResetTimeBuildingSettings = Record<TimeItem, ResetTimeBuildingSetting>;

export class ResetTimeSettings extends Setting {
readonly buildings: {
[item in TimeItem]: ResetTimeBuildingSetting;
};
readonly buildings: ResetTimeBuildingSettings;

constructor(
enabled = false,
buildings = {
buildings: ResetTimeBuildingSettings = {
blastFurnace: new ResetTimeBuildingSetting(
"blastFurnace",
TimeItemVariant.Chronoforge,
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/source/settings/ResourcesSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class ResourcesSettingsItem extends Setting {
}
}

export type ResourcesSettingsItems = { [item in Resource]: ResourcesSettingsItem };
export type ResourcesResourceSettings = { [item in Resource]: ResourcesSettingsItem };

export class ResourcesSettings extends Setting {
resources: ResourcesSettingsItems;
resources: ResourcesResourceSettings;

constructor(
resources = {
Expand Down
6 changes: 2 additions & 4 deletions packages/userscript/source/settings/SpaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ export class SpaceBuildingSetting extends SettingMax {
}
}

export type SpaceSettingsItems = {
[item in SpaceBuildings]: SpaceBuildingSetting;
};
export type SpaceBuildingSettings = Record<SpaceBuildings, SpaceBuildingSetting>;

export class SpaceSettings extends SettingTrigger {
buildings: SpaceSettingsItems;
buildings: SpaceBuildingSettings;

unlockMissions: MissionSettings;

Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/TechSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class TechSetting extends Setting {
}
}

export type TechTechSettings = Record<Technology, TechSetting>;

export class TechSettings extends Setting {
techs: {
[item in Technology]: TechSetting;
};
techs: TechTechSettings;

constructor(
enabled = false,
techs = {
techs: TechTechSettings = {
acoustics: new TechSetting("acoustics", true),
advExogeology: new TechSetting("advExogeology", true),
agriculture: new TechSetting("agriculture", true),
Expand Down
8 changes: 3 additions & 5 deletions packages/userscript/source/settings/TimeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ export class TimeSettingsItem extends SettingMax {
}
}

export type TimeSettingsItems = {
[item in TimeItem]: TimeSettingsItem;
};
export type TimeBuildingsSettings = Record<TimeItem, TimeSettingsItem>;

export class TimeSettings extends SettingTrigger {
buildings: TimeSettingsItems;
buildings: TimeBuildingsSettings;

fixCryochambers: SettingTrigger;

constructor(
enabled = false,
trigger = 1,
buildings: TimeSettingsItems = {
buildings: TimeBuildingsSettings = {
blastFurnace: new TimeSettingsItem("blastFurnace", TimeItemVariant.Chronoforge),
chronocontrol: new TimeSettingsItem(
"chronocontrol",
Expand Down
8 changes: 4 additions & 4 deletions packages/userscript/source/settings/UpgradeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export class UpgradeSetting extends Setting {
}
}

export type UpgradeUpgradeSettings = Record<Upgrade, UpgradeSetting>;

export class UpgradeSettings extends Setting {
upgrades: {
[item in Upgrade]: UpgradeSetting;
};
upgrades: UpgradeUpgradeSettings;

constructor(
enabled = false,
upgrades = {
upgrades: UpgradeUpgradeSettings = {
advancedAutomation: new UpgradeSetting("advancedAutomation", true),
advancedRefinement: new UpgradeSetting("advancedRefinement", true),
aiBases: new UpgradeSetting("aiBases", true),
Expand Down
8 changes: 3 additions & 5 deletions packages/userscript/source/settings/VillageSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import { Job } from "../types";
import { Setting, SettingMax, SettingTrigger } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";

export type VillageSettingsItems = {
[item in Job]: SettingMax;
};
export type VillageJobSettings = Record<Job, SettingMax>;

export class VillageSettings extends Setting {
jobs: VillageSettingsItems;
jobs: VillageJobSettings;

holdFestivals: Setting;
hunt: SettingTrigger;
promoteLeader: Setting;

constructor(
enabled = false,
jobs: VillageSettingsItems = {
jobs: VillageJobSettings = {
engineer: new SettingMax(true, 1),
farmer: new SettingMax(true, 1),
geologist: new SettingMax(true, 1),
Expand Down
Loading

0 comments on commit e510324

Please sign in to comment.