Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
refactor(core): Align setting names
Browse files Browse the repository at this point in the history
Further unifying the keys in settings structures to reuse UI components.
  • Loading branch information
oliversalzburg committed Sep 25, 2022
1 parent 6e5048d commit dbf8fae
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 189 deletions.
4 changes: 2 additions & 2 deletions packages/userscript/source/options/BonfireSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { objectEntries } from "../tools/Entries";
import { Building } from "../types";
import { BuildingUpgradeSettings } from "./BuildingUpgradeSettings";
import { Requirement } from "./Options";
import { SettingLimit, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { SettingMax, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { KittenStorageType } from "./SettingsStorage";

/**
Expand All @@ -13,7 +13,7 @@ import { KittenStorageType } from "./SettingsStorage";
export type BonfireItem = Building | "broadcastTower" | "dataCenter" | "hydroPlant" | "solarFarm";

export type BonfireSettingsItem = SettingToggle &
SettingLimit & {
SettingMax & {
/**
* In case this is an upgrade of another building, this is the name of the
* base building.
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/source/options/ReligionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { objectEntries } from "../tools/Entries";
import { UnicornItemVariant } from "../types";
import { Requirement } from "./Options";
import { SettingLimit, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { SettingMax, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { KittenStorageType } from "./SettingsStorage";

export type FaithItem =
Expand Down Expand Up @@ -41,7 +41,7 @@ export type UnicornItem =
export type ReligionItem = FaithItem | UnicornItem;
export type ReligionAdditionItem = "adore" | "autoPraise" | "bestUnicornBuilding" | "transcend";
export type ReligionSettingsItem = SettingToggle &
SettingLimit & {
SettingMax & {
require: Requirement;

variant: UnicornItemVariant;
Expand Down
5 changes: 5 additions & 0 deletions packages/userscript/source/options/SettingsSection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export type SettingLimit = {
limited: boolean;
$limited?: JQuery<HTMLElement>;
};

export type SettingMax = {
max: number;
$max?: JQuery<HTMLElement>;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/source/options/SpaceSettings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { objectEntries } from "../tools/Entries";
import { GamePage, SpaceBuildings } from "../types";
import { MissionSettings } from "./MissionSettings";
import { SettingLimit, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { SettingMax, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { KittenStorageType } from "./SettingsStorage";

export type SpaceItem = SpaceBuildings;
export type SpaceSettingsItem = SettingToggle & SettingLimit;
export type SpaceSettingsItem = SettingToggle & SettingMax;

export type SpaceAdditionSettings = {
unlockMissions: MissionSettings;
Expand Down
13 changes: 2 additions & 11 deletions packages/userscript/source/options/TimeControlSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ import { TimeItem } from "./TimeSettings";
export type CycleIndices = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

export type TimeControlItem = "accelerateTime" | "reset" | "timeSkip";
export type TimeControlBuildSettingsItem = {
enabled: boolean;
$enabled?: JQuery<HTMLElement>;

trigger: number;
$trigger?: JQuery<HTMLElement>;
};
export type TimeControlResourcesSettingsItem = {
enabled: boolean;
$enabled?: JQuery<HTMLElement>;

export type TimeControlBuildSettingsItem = SettingToggle & SettingTrigger;
export type TimeControlResourcesSettingsItem = SettingToggle & {
stock: number;
$stock?: JQuery<HTMLElement>;
};
Expand Down
34 changes: 16 additions & 18 deletions packages/userscript/source/options/TradingSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@ import { objectEntries } from "../tools/Entries";
import { Race } from "../types";
import { Requirement } from "./Options";
import { OptionsSettingsItem } from "./OptionsSettings";
import { SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { SettingLimit, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { KittenStorageType } from "./SettingsStorage";

export type TradingSettingsItem = SettingToggle & {
limited: boolean;
$limited?: JQuery<HTMLElement>;
export type TradingSettingsItem = SettingLimit &
SettingToggle & {
summer: boolean;
$summer?: JQuery<HTMLElement>;

summer: boolean;
$summer?: JQuery<HTMLElement>;
autumn: boolean;
$autumn?: JQuery<HTMLElement>;

autumn: boolean;
$autumn?: JQuery<HTMLElement>;
winter: boolean;
$winter?: JQuery<HTMLElement>;

winter: boolean;
$winter?: JQuery<HTMLElement>;
spring: boolean;
$spring?: JQuery<HTMLElement>;

spring: boolean;
$spring?: JQuery<HTMLElement>;

/**
* A resource that is required to trade with the race.
*/
require: Requirement;
};
/**
* A resource that is required to trade with the race.
*/
require: Requirement;
};

export type TradeAdditionSettings = {
buildEmbassies: OptionsSettingsItem;
Expand Down
34 changes: 16 additions & 18 deletions packages/userscript/source/options/WorkshopSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ import { objectEntries } from "../tools/Entries";
import { GamePage, ResourceCraftable } from "../types";
import { Requirement } from "./Options";
import { ResourceSettings } from "./ResourcesSettings";
import { SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { SettingLimit, SettingsSection, SettingToggle, SettingTrigger } from "./SettingsSection";
import { KittenStorageType } from "./SettingsStorage";
import { UpgradeSettings } from "./UpgradeSettings";

export type CraftSettingsItem = SettingToggle & {
limited: boolean;
$limited?: JQuery<HTMLElement>;

/**
* Meaning still unclear.
* This is hardcoded to `0.5` right now.
*/
limRat: 0.5;

/**
* The limit of how many items to craft.
* This is hardcoded to `0` right now.
*/
max: 0;
require: Requirement;
};
export type CraftSettingsItem = SettingLimit &
SettingToggle & {
/**
* Meaning still unclear.
* This is hardcoded to `0.5` right now.
*/
limRat: 0.5;

/**
* The limit of how many items to craft.
* This is hardcoded to `0` right now.
*/
max: 0;
require: Requirement;
};

export type CraftAdditionSettings = {
unlockUpgrades: UpgradeSettings;
Expand Down
4 changes: 3 additions & 1 deletion packages/userscript/source/ui/BonfireSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export class BonfireSettingsUi extends SettingsSectionUi<BonfireSettings> {
addition.upgradeBuildings,
this._host.i18n("ui.upgrade.buildings"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(() => (addition.upgradeBuildings.enabled = true));
Expand All @@ -311,7 +312,7 @@ export class BonfireSettingsUi extends SettingsSectionUi<BonfireSettings> {
this._options.addition.upgradeBuildings.items
)) {
const label = this._host.i18n(`$buildings.${upgradeName}.label`);
const button = this._getOption(`building-${upgradeName}`, upgrade, label, false, {
const button = this._getOption(`building-${upgradeName}`, upgrade, label, false, false, {
onCheck: () => {
this._host.updateOptions(() => (upgrade.enabled = true));
this._host.imessage("status.auto.enable", [label]);
Expand Down Expand Up @@ -349,6 +350,7 @@ export class BonfireSettingsUi extends SettingsSectionUi<BonfireSettings> {
addition.turnOnSteamworks,
this._host.i18n("option.steamworks"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(() => (addition.turnOnSteamworks.enabled = true));
Expand Down
2 changes: 1 addition & 1 deletion packages/userscript/source/ui/OptionsSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class OptionsSettingsUi extends SettingsSectionUi<OptionsSettings> {
iname: string
): JQuery<HTMLElement> {
return option.trigger
? this._getTriggeredOption(name, option as SettingTrigger & SettingToggle, iname)
? this._getOptionWithTrigger(name, option as SettingTrigger & SettingToggle, iname)
: this._getOption(name, option, iname);
}

Expand Down
8 changes: 6 additions & 2 deletions packages/userscript/source/ui/ReligionSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ export class ReligionSettingsUi extends SettingsSectionUi<ReligionSettings> {
getAdditionOptions(): Array<JQuery<HTMLElement>> {
const nodeHeader = this._getHeader("Additional options");

const nodeAdore = this._getTriggeredOption(
const nodeAdore = this._getOptionWithTrigger(
"adore",
this._options.addition.adore,
this._host.i18n("option.faith.adore"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(() => (this._options.addition.adore.enabled = true));
Expand All @@ -244,11 +245,12 @@ export class ReligionSettingsUi extends SettingsSectionUi<ReligionSettings> {
}
);

const nodeAutoPraise = this._getTriggeredOption(
const nodeAutoPraise = this._getOptionWithTrigger(
"autoPraise",
this._options.addition.autoPraise,
this._host.i18n("option.praise"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(() => (this._options.addition.autoPraise.enabled = true));
Expand All @@ -266,6 +268,7 @@ export class ReligionSettingsUi extends SettingsSectionUi<ReligionSettings> {
this._options.addition.bestUnicornBuilding,
this._host.i18n("option.faith.best.unicorn"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(
Expand Down Expand Up @@ -319,6 +322,7 @@ export class ReligionSettingsUi extends SettingsSectionUi<ReligionSettings> {
this._options.addition.transcend,
this._host.i18n("option.faith.transcend"),
false,
false,
{
onCheck: () => {
this._host.updateOptions(() => (this._options.addition.transcend.enabled = true));
Expand Down
Loading

0 comments on commit dbf8fae

Please sign in to comment.