From 447e3ea0f94f04e4ae0e046705045d5a9a09dd2a Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Wed, 12 Oct 2022 20:40:11 +0200 Subject: [PATCH] fix(ui): Time skip max button missing Resolves #122 --- .../userscript/source/TimeControlManager.ts | 5 +--- .../userscript/source/options/Settings.ts | 28 ++++++++++++++----- .../source/options/SettingsStorage.ts | 2 +- .../source/options/TimeSkipSettings.ts | 8 +++--- .../source/ui/TimeSkipSettingsUi.ts | 24 ++++------------ 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/packages/userscript/source/TimeControlManager.ts b/packages/userscript/source/TimeControlManager.ts index d27dfaa6..7c65454f 100644 --- a/packages/userscript/source/TimeControlManager.ts +++ b/packages/userscript/source/TimeControlManager.ts @@ -375,10 +375,7 @@ export class TimeControlManager { const cyclesPerEra = this._host.gamePage.calendar.cyclesPerEra; const factor = this._host.gamePage.challenges.getChallenge("1000Years").researched ? 5 : 10; // How many times/years we can skip before we reach our max heat. - let canSkip = Math.min( - Math.floor((heatMax - heatNow) / factor), - this.settings.timeSkip.maximum - ); + let canSkip = Math.min(Math.floor((heatMax - heatNow) / factor), this.settings.timeSkip.max); // The amount of skips to perform. let willSkip = 0; // If the cycle has more years remaining than we can even skip, skip all of them. diff --git a/packages/userscript/source/options/Settings.ts b/packages/userscript/source/options/Settings.ts index 1cde6384..f3978b90 100644 --- a/packages/userscript/source/options/Settings.ts +++ b/packages/userscript/source/options/Settings.ts @@ -40,6 +40,20 @@ export class SettingLimited extends Setting { } } +export class SettingTrigger extends Setting { + trigger: number; + + constructor(enabled = false, trigger = 1) { + super(enabled); + this.trigger = trigger; + } + + load(setting: SettingTrigger) { + super.load(setting); + this.trigger = setting.trigger; + } +} + export class SettingMax extends Setting { max: number; @@ -68,16 +82,16 @@ export class SettingLimitedMax extends SettingLimited implements SettingMax { } } -export class SettingTrigger extends Setting { - trigger: number; +export class SettingTriggerMax extends SettingTrigger implements SettingMax { + max: number; - constructor(enabled = false, trigger = 1) { - super(enabled); - this.trigger = trigger; + constructor(enabled = false, trigger = 1, max = -1) { + super(enabled, trigger); + this.max = max; } - load(setting: SettingTrigger) { + load(setting: SettingTriggerMax) { super.load(setting); - this.trigger = setting.trigger; + this.max = setting.max; } } diff --git a/packages/userscript/source/options/SettingsStorage.ts b/packages/userscript/source/options/SettingsStorage.ts index 7aee66f7..5eda96ef 100644 --- a/packages/userscript/source/options/SettingsStorage.ts +++ b/packages/userscript/source/options/SettingsStorage.ts @@ -37,7 +37,7 @@ type SetMaxBuildingItem = `set-${AllItems}-max`; type SetMaxEmbassyItem = `set-build-${Race}-max`; type SetMaxJobItem = `set-${Job}-max`; type SetMaxResourceItem = `set-${Resource}-max`; -type SetMaxTimeSkip = `set-timeSkip-maximum`; +type SetMaxTimeSkip = `set-timeSkip-max`; type SetMinResetBuildingItem = `set-reset-build-${Exclude}-min`; type SetMinResetFaithItem = `set-reset-faith-${FaithItem | UnicornItem}-min`; type SetMinResetSpaceItem = `set-reset-space-${SpaceBuildings}-min`; diff --git a/packages/userscript/source/options/TimeSkipSettings.ts b/packages/userscript/source/options/TimeSkipSettings.ts index 851f0073..18230b3c 100644 --- a/packages/userscript/source/options/TimeSkipSettings.ts +++ b/packages/userscript/source/options/TimeSkipSettings.ts @@ -3,7 +3,7 @@ import { LegacyStorage } from "./SettingsStorage"; import { CycleIndices } from "./TimeControlSettings"; export class TimeSkipSettings extends SettingTrigger { - maximum = 50; + max = 50; spring = true; summer = false; @@ -27,7 +27,7 @@ export class TimeSkipSettings extends SettingTrigger { load(settings: TimeSkipSettings) { super.load(settings); - this.maximum = settings.maximum; + this.max = settings.max; this.autumn = settings.autumn; this.spring = settings.spring; @@ -42,7 +42,7 @@ export class TimeSkipSettings extends SettingTrigger { static toLegacyOptions(settings: TimeSkipSettings, subject: LegacyStorage) { subject.items["toggle-timeSkip"] = settings.enabled; subject.items["set-timeSkip-trigger"] = settings.trigger; - subject.items["set-timeSkip-maximum"] = settings.maximum; + subject.items["set-timeSkip-max"] = settings.max; subject.items["toggle-timeSkip-autumn"] = settings.autumn; subject.items["toggle-timeSkip-spring"] = settings.spring; subject.items["toggle-timeSkip-summer"] = settings.summer; @@ -59,7 +59,7 @@ export class TimeSkipSettings extends SettingTrigger { options.enabled = subject.items["toggle-timeSkip"] ?? options.enabled; options.trigger = subject.items["set-timeSkip-trigger"] ?? options.trigger; - options.maximum = subject.items["set-timeSkip-maximum"] ?? options.maximum; + options.max = subject.items["set-timeSkip-max"] ?? options.max; options.autumn = subject.items["toggle-timeSkip-autumn"] ?? options.autumn; options.spring = subject.items["toggle-timeSkip-spring"] ?? options.spring; options.summer = subject.items["toggle-timeSkip-summer"] ?? options.summer; diff --git a/packages/userscript/source/ui/TimeSkipSettingsUi.ts b/packages/userscript/source/ui/TimeSkipSettingsUi.ts index 754a2c68..7db89a18 100644 --- a/packages/userscript/source/ui/TimeSkipSettingsUi.ts +++ b/packages/userscript/source/ui/TimeSkipSettingsUi.ts @@ -2,26 +2,24 @@ import { TimeSkipSettings } from "../options/TimeSkipSettings"; import { ucfirst } from "../tools/Format"; import { UserScript } from "../UserScript"; import { CyclesList } from "./components/CyclesList"; +import { MaxButton } from "./components/MaxButton"; import { Panel } from "./components/Panel"; import { SeasonsList } from "./components/SeasonsList"; -import { SettingListItem } from "./components/SettingListItem"; import { SettingsPanel } from "./components/SettingsPanel"; export class TimeSkipSettingsUi extends SettingsPanel { - private readonly _items: Array; - private readonly _maximum: SettingListItem; + private readonly _maximum: MaxButton; private readonly _cycles: Panel; private readonly _seasons: Panel; constructor(host: UserScript, settings: TimeSkipSettings) { - super(host, host.engine.i18n("option.time.skip"), settings); + const label = host.engine.i18n("option.time.skip"); + super(host, label, settings); this._list.addEventListener("enableAll", () => { - this._items.forEach(item => (item.settings.enabled = true)); this.refreshUi(); }); this._list.addEventListener("disableAll", () => { - this._items.forEach(item => (item.settings.enabled = false)); this.refreshUi(); }); this._list.addEventListener("reset", () => { @@ -29,17 +27,7 @@ export class TimeSkipSettingsUi extends SettingsPanel { this.refreshUi(); }); - this._maximum = new SettingListItem( - this._host, - this._host.engine.i18n("ui.maximum"), - this.settings, - { - onCheck: () => - this._host.engine.imessage("status.auto.enable", [this._host.engine.i18n("ui.maximum")]), - onUnCheck: () => - this._host.engine.imessage("status.auto.disable", [this._host.engine.i18n("ui.maximum")]), - } - ); + this._maximum = new MaxButton(this._host, label, this.settings); this._cycles = new Panel( this._host, ucfirst(this._host.engine.i18n("ui.cycles")), @@ -53,7 +41,7 @@ export class TimeSkipSettingsUi extends SettingsPanel { "M15.3 28.3q-.85 0-1.425-.575-.575-.575-.575-1.425 0-.85.575-1.425.575-.575 1.425-.575.85 0 1.425.575.575.575.575 1.425 0 .85-.575 1.425-.575.575-1.425.575Zm8.85 0q-.85 0-1.425-.575-.575-.575-.575-1.425 0-.85.575-1.425.575-.575 1.425-.575.85 0 1.425.575.575.575.575 1.425 0 .85-.575 1.425-.575.575-1.425.575Zm8.5 0q-.85 0-1.425-.575-.575-.575-.575-1.425 0-.85.575-1.425.575-.575 1.425-.575.85 0 1.425.575.575.575.575 1.425 0 .85-.575 1.425-.575.575-1.425.575ZM9 44q-1.2 0-2.1-.9Q6 42.2 6 41V10q0-1.2.9-2.1Q7.8 7 9 7h3.25V4h3.25v3h17V4h3.25v3H39q1.2 0 2.1.9.9.9.9 2.1v31q0 1.2-.9 2.1-.9.9-2.1.9Zm0-3h30V19.5H9V41Zm0-24.5h30V10H9Zm0 0V10v6.5Z" ); - this._items = [this._maximum]; + this.element.append(this._maximum.element); this.addChildren([this._maximum, this._cycles, this._seasons]); }