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

Commit

Permalink
refactor(core): Replace factories with components
Browse files Browse the repository at this point in the history
The factories were a good step towards normalizing the constructions of all common parts. We now gradually move all the factory-build parts into component instances.
  • Loading branch information
oliversalzburg committed Oct 8, 2022
1 parent 9ec905d commit 790c316
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 304 deletions.
12 changes: 5 additions & 7 deletions packages/userscript/source/ui/BonfireSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { objectEntries } from "../tools/Entries";
import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { TriggerButton } from "./components/TriggerButton";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingUi } from "./SettingUi";

export class BonfireSettingsUi extends SettingsSectionUi {
private readonly _trigger: TriggerButton;
Expand Down Expand Up @@ -292,12 +292,11 @@ export class BonfireSettingsUi extends SettingsSectionUi {
const upgradeBuildingsButtons = [];
for (const [upgradeName, upgrade] of objectEntries(this._settings.upgradeBuildings.items)) {
const label = this._host.engine.i18n(`$buildings.${upgradeName}.label`);
const button = SettingUi.make(
const button = new SettingListItem(
this._host,
`building-${upgradeName}`,
upgrade,
label,

upgrade,
{
onCheck: () => this._host.engine.imessage("status.auto.enable", [label]),
onUnCheck: () => this._host.engine.imessage("status.auto.disable", [label]),
Expand All @@ -313,12 +312,11 @@ export class BonfireSettingsUi extends SettingsSectionUi {
upgradeBuildingsButtons.sort((a, b) => a.label.localeCompare(b.label));
upgradeBuildingsButtons.forEach(button => upgradeBuildingsList.append(button.button.element));

const nodeTurnOnSteamworks = SettingUi.make(
const nodeTurnOnSteamworks = new SettingListItem(
this._host,
"_steamworks",
this._settings.turnOnSteamworks,
this._host.engine.i18n("option.steamworks"),

this._settings.turnOnSteamworks,
{
onCheck: () =>
this._host.engine.imessage("status.auto.enable", [
Expand Down
6 changes: 3 additions & 3 deletions packages/userscript/source/ui/FilterSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { objectEntries } from "../tools/Entries";
import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingUi } from "./SettingUi";

export class FiltersSettingsUi extends SettingsSectionUi {
private readonly _settings: FilterSettings;
Expand Down Expand Up @@ -109,11 +109,11 @@ export class FiltersSettingsUi extends SettingsSectionUi {
];

const makeButton = (name: FilterItem, option: FilterSettingsItem, label: string) =>
SettingUi.make(
new SettingListItem(
this._host,
name,
option,
label,
option,
{
onCheck: () => this._host.engine.imessage("filter.enable", [label]),
onUnCheck: () => this._host.engine.imessage("filter.disable", [label]),
Expand Down
9 changes: 5 additions & 4 deletions packages/userscript/source/ui/OptionsSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { objectEntries } from "../tools/Entries";
import { ucfirst } from "../tools/Format";
import { isNil, mustExist } from "../tools/Maybe";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { SettingTriggerListItem } from "./components/SettingTriggerListItem";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingTriggerUi } from "./SettingTriggerUi";
import { SettingUi } from "./SettingUi";

export class OptionsSettingsUi extends SettingsSectionUi {
private readonly _settings: OptionsSettings;
Expand Down Expand Up @@ -60,8 +60,9 @@ export class OptionsSettingsUi extends SettingsSectionUi {
onUnCheck: () => this._host.engine.imessage("status.sub.disable", [iname]),
};
return option.trigger
? SettingTriggerUi.make(this._host, name, option as SettingTrigger, iname, handler).element
: SettingUi.make(this._host, name, option, iname, handler).element;
? new SettingTriggerListItem(this._host, name, iname, option as SettingTrigger, handler)
.element
: new SettingListItem(this._host, name, iname, option, handler).element;
}

setState(state: OptionsSettings): void {
Expand Down
21 changes: 10 additions & 11 deletions packages/userscript/source/ui/ReligionSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { UnicornItemVariant } from "../types";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { SettingTriggerListItem } from "./components/SettingTriggerListItem";
import { TriggerButton } from "./components/TriggerButton";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingTriggerUi } from "./SettingTriggerUi";
import { SettingUi } from "./SettingUi";

export class ReligionSettingsUi extends SettingsSectionUi {
private readonly _trigger: TriggerButton;
Expand Down Expand Up @@ -222,11 +222,11 @@ export class ReligionSettingsUi extends SettingsSectionUi {
getAdditionOptions(): Array<JQuery<HTMLElement>> {
const nodeHeader = this._getHeader("Additional options");

const nodeAdore = SettingTriggerUi.make(
const nodeAdore = new SettingTriggerListItem(
this._host,
"adore",
this._settings.adore,
this._host.engine.i18n("option.faith.adore"),
this._settings.adore,
{
onCheck: () =>
this._host.engine.imessage("status.sub.enable", [
Expand All @@ -239,11 +239,11 @@ export class ReligionSettingsUi extends SettingsSectionUi {
}
);

const nodeAutoPraise = SettingTriggerUi.make(
const nodeAutoPraise = new SettingTriggerListItem(
this._host,
"autoPraise",
this._settings.autoPraise,
this._host.engine.i18n("option.praise"),
this._settings.autoPraise,
{
onCheck: () =>
this._host.engine.imessage("status.sub.enable", [
Expand All @@ -256,12 +256,11 @@ export class ReligionSettingsUi extends SettingsSectionUi {
}
);

const nodeBestUnicornBuilding = SettingUi.make(
const nodeBestUnicornBuilding = new SettingListItem(
this._host,
"bestUnicornBuilding",
this._settings.bestUnicornBuilding,
this._host.engine.i18n("option.faith.best.unicorn"),

this._settings.bestUnicornBuilding,
{
onCheck: () =>
this._host.engine.imessage("status.sub.enable", [
Expand Down Expand Up @@ -310,11 +309,11 @@ export class ReligionSettingsUi extends SettingsSectionUi {
//this._host.saveToKittenStorage();
});

const nodeTranscend = SettingUi.make(
const nodeTranscend = new SettingListItem(
this._host,
"transcend",
this._settings.transcend,
this._host.engine.i18n("option.faith.transcend"),
this._settings.transcend,
{
onCheck: () =>
this._host.engine.imessage("status.sub.enable", [
Expand Down
4 changes: 2 additions & 2 deletions packages/userscript/source/ui/ResourcesSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { Resource } from "../types";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingUi } from "./SettingUi";

export class ResourcesSettingsUi extends SettingsSectionUi {
private readonly _settings: ResourcesSettings;
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ResourcesSettingsUi extends SettingsSectionUi {
const stock = setting.stock;

// The overall container for this resource item.
const container = SettingUi.make(this._host, `resource-${name}`, setting, title, {
const container = new SettingListItem(this._host, `resource-${name}`, title, setting, {
onCheck: () => this._host.engine.imessage("status.resource.enable", [title]),
onUnCheck: () => this._host.engine.imessage("status.resource.disable", [title]),
});
Expand Down
18 changes: 12 additions & 6 deletions packages/userscript/source/ui/ScienceSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { objectEntries } from "../tools/Entries";
import { ucfirst } from "../tools/Format";
import { mustExist } from "../tools/Maybe";
import { UserScript } from "../UserScript";
import { SettingListItem } from "./components/SettingListItem";
import { SettingsListUi } from "./SettingsListUi";
import { SettingsPanelUi } from "./SettingsPanelUi";
import { SettingsSectionUi } from "./SettingsSectionUi";
import { SettingUi } from "./SettingUi";

export class ScienceSettingsUi extends SettingsSectionUi {
private readonly _settings: ScienceSettings;
Expand All @@ -33,7 +33,7 @@ export class ScienceSettingsUi extends SettingsSectionUi {
const techButtons = [];
for (const [techName, tech] of objectEntries(this._settings.techs.items)) {
const label = this._host.engine.i18n(`$science.${techName}.label`);
const button = SettingUi.make(this._host, `tech-${techName}`, tech, label, {
const button = new SettingListItem(this._host, `tech-${techName}`, label, tech, {
onCheck: () => this._host.engine.imessage("status.auto.enable", [label]),
onUnCheck: () => this._host.engine.imessage("status.auto.disable", [label]),
});
Expand All @@ -59,10 +59,16 @@ export class ScienceSettingsUi extends SettingsSectionUi {
const policyLabel = this._host.engine.i18n(
`$policy.${policyName === "authocracy" ? "autocracy" : policyName}.label`
);
const policyButton = SettingUi.make(this._host, `policy-${policyName}`, policy, policyLabel, {
onCheck: () => this._host.engine.imessage("status.auto.enable", [policyLabel]),
onUnCheck: () => this._host.engine.imessage("status.auto.disable", [policyLabel]),
});
const policyButton = new SettingListItem(
this._host,
`policy-${policyName}`,
policyLabel,
policy,
{
onCheck: () => this._host.engine.imessage("status.auto.enable", [policyLabel]),
onUnCheck: () => this._host.engine.imessage("status.auto.disable", [policyLabel]),
}
);

policyButtons.push({ label: policyLabel, button: policyButton });
}
Expand Down
51 changes: 0 additions & 51 deletions packages/userscript/source/ui/SettingLimitedMaxUi.ts

This file was deleted.

48 changes: 0 additions & 48 deletions packages/userscript/source/ui/SettingLimitedUi.ts

This file was deleted.

37 changes: 0 additions & 37 deletions packages/userscript/source/ui/SettingMaxUi.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/userscript/source/ui/SettingTriggerUi.ts

This file was deleted.

0 comments on commit 790c316

Please sign in to comment.