Skip to content

Commit

Permalink
feat(ui): Remove "Options" section
Browse files Browse the repository at this point in the history
The last remaining option "Observe astro events" is now hosted in the "Science" section.

We might have an "Options" section again at a later time to control the meta behavior of KS. Everything relating to controlling the game should be hosted in a settings section relating to a tab in the game.
  • Loading branch information
oliversalzburg committed Nov 18, 2022
1 parent 543744a commit b287eed
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 129 deletions.
18 changes: 0 additions & 18 deletions packages/userscript/source/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,8 @@ export class Engine {
private async _iterate(): Promise<void> {
const context = { tick: new Date().getTime() };

const subOptions = this._host.engine.settings.options;

// The order in which these actions are performed is probably
// semi-intentional and should be preserved or improved.

// Observe astronomical events.
if (subOptions.enabled && subOptions.items.observe.enabled) {
this.observeStars();
}
await this.scienceManager.tick(context);
this.bonfireManager.tick(context);
this.spaceManager.tick(context);
Expand All @@ -240,17 +233,6 @@ export class Engine {
await this.timeControlManager.tick(context);
}

/**
* If there is currently an astronomical event, observe it.
*/
observeStars(): void {
if (this._host.gamePage.calendar.observeBtn !== null) {
this._host.gamePage.calendar.observeHandler();
this._host.engine.iactivity("act.observe", [], "ks-star");
this._host.engine.storeForSummary("stars", 1);
}
}

/**
* Retrieve an internationalized string literal.
*
Expand Down
16 changes: 16 additions & 0 deletions packages/userscript/source/ScienceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class ScienceManager extends UpgradeManager {
if (this.settings.policies.enabled && this._host.gamePage.tabs[2].visible) {
await this.autoPolicy();
}

// Observe astronomical events.
if (this.settings.observe.enabled) {
this.observeStars();
}
}

load(settings: ScienceSettings) {
Expand Down Expand Up @@ -112,4 +117,15 @@ export class ScienceManager extends UpgradeManager {
await this.upgrade(item, "policy");
}
}

/**
* If there is currently an astronomical event, observe it.
*/
observeStars(): void {
if (this._host.gamePage.calendar.observeBtn !== null) {
this._host.gamePage.calendar.observeHandler();
this._host.engine.iactivity("act.observe", [], "ks-star");
this._host.engine.storeForSummary("stars", 1);
}
}
}
7 changes: 0 additions & 7 deletions packages/userscript/source/settings/EngineSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FilterSettings } from "./FilterSettings";
import { OptionsSettings } from "./OptionsSettings";
import { ResourcesSettings } from "./ResourcesSettings";
import { Setting } from "./Settings";
import { LegacyStorage } from "./SettingsStorage";
Expand All @@ -11,18 +10,15 @@ export class EngineSettings extends Setting {
interval = 2000;

filters: FilterSettings;
options: OptionsSettings;
resources: ResourcesSettings;

constructor(
enabled = false,
filters = new FilterSettings(),
options = new OptionsSettings(),
resources = new ResourcesSettings()
) {
super(enabled);
this.filters = filters;
this.options = options;
this.resources = resources;
}

Expand All @@ -31,7 +27,6 @@ export class EngineSettings extends Setting {
this.interval = settings.interval;

this.filters.load(settings.filters);
this.options.load(settings.options);
this.resources.load(settings.resources);
}

Expand All @@ -40,7 +35,6 @@ export class EngineSettings extends Setting {
subject.toggles.engine = settings.enabled;

FilterSettings.toLegacyOptions(settings.filters, subject);
OptionsSettings.toLegacyOptions(settings.options, subject);
ResourcesSettings.toLegacyOptions(settings.resources, subject);
}

Expand All @@ -51,7 +45,6 @@ export class EngineSettings extends Setting {
options.enabled = subject.toggles.engine ?? options.enabled;

options.filters = FilterSettings.fromLegacyOptions(subject);
options.options = OptionsSettings.fromLegacyOptions(subject);
options.resources = ResourcesSettings.fromLegacyOptions(subject);

return options;
Expand Down
2 changes: 1 addition & 1 deletion packages/userscript/source/settings/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Options {
time: settings.time.enabled,
timeCtrl: settings.timeControl.enabled,
distribute: settings.village.enabled,
options: settings.engine.options.enabled,
options: true,
filter: settings.engine.filters.enabled,
};

Expand Down
44 changes: 0 additions & 44 deletions packages/userscript/source/settings/OptionsSettings.ts

This file was deleted.

17 changes: 15 additions & 2 deletions packages/userscript/source/settings/ScienceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ export type ScienceSettingsItem = TechSettings | PolicySettings;
export class ScienceSettings extends Setting {
policies: PolicySettings;
techs: TechSettings;

constructor(enabled = false, policies = new PolicySettings(), techs = new TechSettings()) {
observe: Setting;

constructor(
enabled = false,
policies = new PolicySettings(),
techs = new TechSettings(),
observe = new Setting(true)
) {
super(enabled);
this.policies = policies;
this.techs = techs;
this.observe = observe;
}

static validateGame(game: GamePage, settings: ScienceSettings) {
Expand All @@ -27,13 +34,17 @@ export class ScienceSettings extends Setting {

this.policies.load(settings.policies);
this.techs.load(settings.techs);

this.observe.enabled = settings.observe.enabled;
}

static toLegacyOptions(settings: ScienceSettings, subject: LegacyStorage) {
subject.toggles.upgrade = settings.enabled;

PolicySettings.toLegacyOptions(settings.policies, subject);
TechSettings.toLegacyOptions(settings.techs, subject);

subject.items["toggle-observe"] = settings.observe.enabled;
}

static fromLegacyOptions(subject: LegacyStorage) {
Expand All @@ -43,6 +54,8 @@ export class ScienceSettings extends Setting {
options.policies = PolicySettings.fromLegacyOptions(subject);
options.techs = TechSettings.fromLegacyOptions(subject);

options.observe.enabled = subject.items["toggle-observe"] ?? options.observe.enabled;

return options;
}
}
7 changes: 2 additions & 5 deletions packages/userscript/source/settings/SettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from "../types";
import { BonfireItem } from "./BonfireSettings";
import { FilterItem } from "./FilterSettings";
import { OptionsItem } from "./OptionsSettings";
import { FaithItem, ReligionAdditionItem, UnicornItem } from "./ReligionSettings";
import { ScienceItem } from "./ScienceSettings";
import { AllItems } from "./Settings";
Expand Down Expand Up @@ -45,7 +44,6 @@ type SetMinResetFaithItem = `set-reset-faith-${FaithItem | UnicornItem}-min`;
type SetMinResetSpaceItem = `set-reset-space-${SpaceBuildings}-min`;
type SetMinResetTimeItem = `set-reset-time-${TimeItem}-min`;
type SetMinResetUnicornItem = `set-reset-unicorn-${UnicornItem}-min`;
type SetSubtriggerOptionItem = `set-${OptionsItem}-trigger`;
type SetSubtriggerReligionItem = `set-${ReligionAdditionItem}-trigger`;
type SetSubtriggerTimeCtrlItem = `set-${"accelerateTime" | "timeSkip"}-trigger`;
type ToggleBuildEmbassies = "toggle-buildEmbassies";
Expand All @@ -62,7 +60,7 @@ type ToggleLimitedJobItem = `toggle-limited-${Job}`;
type ToggleLimitedRaceItem = `toggle-limited-${Race}`;
type ToggleLimitedResourceItem = `toggle-limited-${Resource}`;
type ToggleMissionItem = `toggle-mission-${Missions}`;
type ToggleOptionsItem = `toggle-${OptionsItem}`;
type ToggleObserve = `toggle-observe`;
type TogglePolicyItem = `toggle-policy-${Policy}`;
type TogglePromoteLeader = `toggle-promote`;
type ToggleRaceItem = `toggle-${Race}`;
Expand Down Expand Up @@ -105,7 +103,6 @@ export type LegacyStorage = {
Partial<Record<SetMinResetSpaceItem, number>> &
Partial<Record<SetMinResetTimeItem, number>> &
Partial<Record<SetMinResetUnicornItem, number>> &
Partial<Record<SetSubtriggerOptionItem, number>> &
Partial<Record<SetSubtriggerReligionItem, number>> &
Partial<Record<SetSubtriggerTimeCtrlItem, number>> &
Partial<Record<ToggleBuildEmbassies, boolean>> &
Expand All @@ -122,7 +119,7 @@ export type LegacyStorage = {
Partial<Record<ToggleLimitedRaceItem, boolean>> &
Partial<Record<ToggleLimitedResourceItem, boolean>> &
Partial<Record<ToggleMissionItem, boolean>> &
Partial<Record<ToggleOptionsItem, boolean>> &
Partial<Record<ToggleObserve, boolean>> &
Partial<Record<TogglePolicyItem, boolean>> &
Partial<Record<TogglePromoteLeader, boolean>> &
Partial<Record<ToggleRaceItem, boolean>> &
Expand Down
44 changes: 0 additions & 44 deletions packages/userscript/source/ui/OptionsSettingsUi.ts

This file was deleted.

22 changes: 20 additions & 2 deletions packages/userscript/source/ui/ScienceSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class ScienceSettingsUi extends SettingsSectionUi<ScienceSettings> {
private readonly _items: Array<SettingListItem>;
private readonly _policiesUi: PolicySettingsUi;
private readonly _techsUi: TechSettingsUi;
protected readonly _observeStars: SettingListItem;

constructor(host: UserScript, settings: ScienceSettings) {
super(host, host.engine.i18n("ui.upgrade"), settings);
Expand All @@ -29,8 +30,25 @@ export class ScienceSettingsUi extends SettingsSectionUi<ScienceSettings> {
this._policiesUi = new PolicySettingsUi(this._host, this.setting.policies);
this._techsUi = new TechSettingsUi(this._host, this.setting.techs);

this._items = [this._policiesUi, this._techsUi];
this._observeStars = new SettingListItem(
this._host,
this._host.engine.i18n("option.observe"),
this.setting.observe,
{
onCheck: () =>
this._host.engine.imessage("status.sub.enable", [
this._host.engine.i18n("option.observe"),
]),
onUnCheck: () =>
this._host.engine.imessage("status.sub.disable", [
this._host.engine.i18n("option.observe"),
]),
}
);
this.addChild(this._observeStars);

this.addChildren([this._techsUi, this._policiesUi]);
this._items = [this._policiesUi, this._techsUi, this._observeStars];

this.addChildren([this._techsUi, this._policiesUi, this._observeStars]);
}
}
6 changes: 0 additions & 6 deletions packages/userscript/source/ui/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { UserScript } from "../UserScript";
import { BonfireSettingsUi } from "./BonfireSettingsUi";
import { EngineSettingsUi } from "./EngineSettingsUi";
import { FiltersSettingsUi } from "./FilterSettingsUi";
import { OptionsSettingsUi } from "./OptionsSettingsUi";
import { ReligionSettingsUi } from "./ReligionSettingsUi";
import { ResourcesSettingsUi } from "./ResourcesSettingsUi";
import { ScienceSettingsUi } from "./ScienceSettingsUi";
Expand All @@ -29,7 +28,6 @@ export class UserInterface {
private _timeUi: TimeSettingsUi;
private _timeCtrlUi: TimeControlSettingsUi;
private _distributeUi: VillageSettingsUi;
private _optionsUi: OptionsSettingsUi;
private _filterUi: FiltersSettingsUi;

constructor(host: UserScript) {
Expand All @@ -47,7 +45,6 @@ export class UserInterface {
this._timeUi = new TimeSettingsUi(this._host, engine.timeManager.settings);
this._timeCtrlUi = new TimeControlSettingsUi(this._host, engine.timeControlManager.settings);
this._distributeUi = new VillageSettingsUi(this._host, engine.villageManager.settings);
this._optionsUi = new OptionsSettingsUi(this._host, engine.settings.options);
this._filterUi = new FiltersSettingsUi(this._host, engine.settings.filters);
}

Expand Down Expand Up @@ -75,7 +72,6 @@ export class UserInterface {
optionsListElement.append(this._spaceUi.element);
optionsListElement.append(this._timeUi.element);
optionsListElement.append(this._timeCtrlUi.element);
optionsListElement.append(this._optionsUi.element);
optionsListElement.append(this._filterUi.element);

// Make _engineUI's expando button hide/show the other option groups
Expand All @@ -99,7 +95,6 @@ export class UserInterface {
this._timeUi.toggle(sectionsVisible);
this._timeCtrlUi.toggle(sectionsVisible);
this._distributeUi.toggle(sectionsVisible);
this._optionsUi.toggle(sectionsVisible);
this._filterUi.toggle(sectionsVisible);
});

Expand Down Expand Up @@ -144,7 +139,6 @@ export class UserInterface {
this._timeUi.refreshUi();
this._timeCtrlUi.refreshUi();
this._distributeUi.refreshUi();
this._optionsUi.refreshUi();
this._filterUi.refreshUi();
}

Expand Down

0 comments on commit b287eed

Please sign in to comment.