Skip to content

Commit 0ab9afb

Browse files
feat(ui): Rebuild parent-child relationships
1 parent c0e5e55 commit 0ab9afb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1344
-1487
lines changed

source/TradeManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ export class TradeManager implements Automation {
364364
}
365365
cultureVal = this._workshopManager.getValueAvailable("culture");
366366
if (cultureVal < emBulk.priceSum) {
367-
console.warn(
368-
...cl<string | number>("Something has gone horribly wrong.", emBulk.priceSum, cultureVal),
369-
);
367+
console.warn(...cl("Something has gone horribly wrong.", emBulk.priceSum, cultureVal));
370368
}
371369
// We don't want to invoke the embassy build action multiple times, as
372370
// that would cause lots of log messages.

source/tools/Log.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export const cl = <T>(...args: Array<T>): Array<string | T> => ["👩‍🔬", ...args];
1+
export const cl = <T extends Array<unknown>>(...args: T): Array<string | T[number]> => [
2+
"👩‍🔬",
3+
...args,
4+
];

source/ui/BonfireSettingsUi.ts

Lines changed: 91 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import { BuildingUpgradeSettingsUi } from "./BuildingUpgradeSettingsUi.js";
88
import { Delimiter } from "./components/Delimiter.js";
99
import { Dialog } from "./components/Dialog.js";
1010
import { HeaderListItem } from "./components/HeaderListItem.js";
11-
import { SettingListItem, type SettingListItemOptions } from "./components/SettingListItem.js";
11+
import { SettingListItem } from "./components/SettingListItem.js";
1212
import { SettingTriggerListItem } from "./components/SettingTriggerListItem.js";
1313
import { SettingsList } from "./components/SettingsList.js";
14-
import { SettingsPanel, type SettingsPanelOptions } from "./components/SettingsPanel.js";
14+
import { SettingsPanel } from "./components/SettingsPanel.js";
1515
import type { UiComponent } from "./components/UiComponent.js";
1616

1717
export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTriggerListItem> {
1818
constructor(
1919
parent: UiComponent,
2020
settings: BonfireSettings,
2121
locale: SettingOptions<SupportedLocale>,
22-
options?: SettingsPanelOptions<SettingTriggerListItem> & SettingListItemOptions,
2322
) {
2423
const label = parent.host.engine.i18n("ui.build");
2524
super(
@@ -28,18 +27,13 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
2827
new SettingTriggerListItem(parent, settings, locale, label, {
2928
onCheck: (isBatchProcess?: boolean) => {
3029
parent.host.engine.imessage("status.auto.enable", [label]);
31-
this.refreshUi();
32-
options?.onCheck?.(isBatchProcess);
3330
},
3431
onUnCheck: (isBatchProcess?: boolean) => {
3532
parent.host.engine.imessage("status.auto.disable", [label]);
36-
this.refreshUi();
37-
options?.onUnCheck?.(isBatchProcess);
3833
},
3934
onRefresh: () => {
40-
const element = this.settingItem;
41-
element.triggerButton.inactive = !settings.enabled || settings.trigger < 0;
42-
element.triggerButton.ineffective =
35+
this.settingItem.triggerButton.inactive = !settings.enabled || settings.trigger < 0;
36+
this.settingItem.triggerButton.ineffective =
4337
settings.enabled &&
4438
settings.trigger < 0 &&
4539
!Object.values(settings.buildings).some(_ => _.enabled && 0 < _.max && 0 <= _.trigger);
@@ -56,12 +50,14 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
5650
!settings.upgradeBuildings.enabled;
5751
},
5852
onRefreshTrigger: () => {
59-
const element = this.settingItem;
60-
element.triggerButton.element[0].title = parent.host.engine.i18n("ui.trigger.section", [
61-
settings.trigger < 0
62-
? parent.host.engine.i18n("ui.trigger.section.inactive")
63-
: parent.host.renderPercentage(settings.trigger, locale.selected, true),
64-
]);
53+
this.settingItem.triggerButton.element[0].title = parent.host.engine.i18n(
54+
"ui.trigger.section",
55+
[
56+
settings.trigger < 0
57+
? parent.host.engine.i18n("ui.trigger.section.inactive")
58+
: parent.host.renderPercentage(settings.trigger, locale.selected, true),
59+
],
60+
);
6561
},
6662
onSetTrigger: async () => {
6763
const value = await Dialog.prompt(
@@ -95,100 +91,95 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
9591
// We want the ability to use `this` in our callbacks, to construct more complex
9692
// usage scenarios where we need access to the entire UI section.
9793
this.addChildren([
98-
new SettingsList(parent, {
99-
children: coalesceArray(
100-
parent.host.game.bld.buildingGroups.flatMap(buildingGroup => [
101-
new HeaderListItem(parent, buildingGroup.title),
94+
new SettingsList(this, {
95+
onReset: () => {
96+
this.setting.load({ buildings: new BonfireSettings().buildings });
97+
this.refreshUi();
98+
},
99+
}).addChildren(
100+
coalesceArray(
101+
this.host.game.bld.buildingGroups.flatMap(buildingGroup => [
102+
new HeaderListItem(this, buildingGroup.title),
102103
...buildingGroup.buildings.flatMap(building =>
103-
this._getBuildOptions(parent, settings, locale, label, building),
104+
this._getBuildOptions(this, settings, locale, label, building),
104105
),
105106
buildingGroup !==
106-
parent.host.game.bld.buildingGroups[parent.host.game.bld.buildingGroups.length - 1]
107-
? new Delimiter(parent)
107+
this.host.game.bld.buildingGroups[this.host.game.bld.buildingGroups.length - 1]
108+
? new Delimiter(this)
108109
: undefined,
109110
]),
110111
),
111-
onReset: () => {
112-
this.setting.load({ buildings: new BonfireSettings().buildings });
113-
this.refreshUi();
114-
},
115-
}),
116-
new SettingsList(parent, {
117-
children: [
118-
new HeaderListItem(parent, parent.host.engine.i18n("ui.additional")),
119-
new SettingListItem(
120-
parent,
121-
settings.gatherCatnip,
122-
parent.host.engine.i18n("option.catnip"),
123-
{
124-
onCheck: () => {
125-
parent.host.engine.imessage("status.sub.enable", [
126-
parent.host.engine.i18n("option.catnip"),
127-
]);
128-
},
129-
onUnCheck: () => {
130-
parent.host.engine.imessage("status.sub.disable", [
131-
parent.host.engine.i18n("option.catnip"),
132-
]);
133-
},
112+
),
113+
new SettingsList(this, {
114+
hasDisableAll: false,
115+
hasEnableAll: false,
116+
}).addChildren([
117+
new HeaderListItem(this, this.host.engine.i18n("ui.additional")),
118+
new SettingListItem(this, settings.gatherCatnip, this.host.engine.i18n("option.catnip"), {
119+
onCheck: () => {
120+
this.host.engine.imessage("status.sub.enable", [
121+
this.host.engine.i18n("option.catnip"),
122+
]);
123+
},
124+
onUnCheck: () => {
125+
this.host.engine.imessage("status.sub.disable", [
126+
this.host.engine.i18n("option.catnip"),
127+
]);
128+
},
129+
}),
130+
new SettingListItem(
131+
this,
132+
settings.turnOnSteamworks,
133+
this.host.engine.i18n("option.steamworks"),
134+
{
135+
onCheck: () => {
136+
this.host.engine.imessage("status.sub.enable", [
137+
this.host.engine.i18n("option.steamworks"),
138+
]);
134139
},
135-
),
136-
new SettingListItem(
137-
parent,
138-
settings.turnOnSteamworks,
139-
parent.host.engine.i18n("option.steamworks"),
140-
{
141-
onCheck: () => {
142-
parent.host.engine.imessage("status.sub.enable", [
143-
parent.host.engine.i18n("option.steamworks"),
144-
]);
145-
},
146-
onUnCheck: () => {
147-
parent.host.engine.imessage("status.sub.disable", [
148-
parent.host.engine.i18n("option.steamworks"),
149-
]);
150-
},
140+
onUnCheck: () => {
141+
this.host.engine.imessage("status.sub.disable", [
142+
this.host.engine.i18n("option.steamworks"),
143+
]);
151144
},
152-
),
153-
new SettingListItem(
154-
parent,
155-
settings.turnOnMagnetos,
156-
parent.host.engine.i18n("option.magnetos"),
157-
{
158-
onCheck: () => {
159-
parent.host.engine.imessage("status.sub.enable", [
160-
parent.host.engine.i18n("option.magnetos"),
161-
]);
162-
},
163-
onUnCheck: () => {
164-
parent.host.engine.imessage("status.sub.disable", [
165-
parent.host.engine.i18n("option.magnetos"),
166-
]);
167-
},
145+
},
146+
),
147+
new SettingListItem(
148+
this,
149+
settings.turnOnMagnetos,
150+
this.host.engine.i18n("option.magnetos"),
151+
{
152+
onCheck: () => {
153+
this.host.engine.imessage("status.sub.enable", [
154+
this.host.engine.i18n("option.magnetos"),
155+
]);
168156
},
169-
),
170-
new SettingListItem(
171-
parent,
172-
settings.turnOnReactors,
173-
parent.host.engine.i18n("option.reactors"),
174-
{
175-
onCheck: () => {
176-
parent.host.engine.imessage("status.sub.enable", [
177-
parent.host.engine.i18n("option.reactors"),
178-
]);
179-
},
180-
onUnCheck: () => {
181-
parent.host.engine.imessage("status.sub.disable", [
182-
parent.host.engine.i18n("option.reactors"),
183-
]);
184-
},
157+
onUnCheck: () => {
158+
this.host.engine.imessage("status.sub.disable", [
159+
this.host.engine.i18n("option.magnetos"),
160+
]);
185161
},
186-
),
187-
new BuildingUpgradeSettingsUi(parent, settings.upgradeBuildings, locale, settings),
188-
],
189-
hasDisableAll: false,
190-
hasEnableAll: false,
191-
}),
162+
},
163+
),
164+
new SettingListItem(
165+
this,
166+
settings.turnOnReactors,
167+
this.host.engine.i18n("option.reactors"),
168+
{
169+
onCheck: () => {
170+
this.host.engine.imessage("status.sub.enable", [
171+
this.host.engine.i18n("option.reactors"),
172+
]);
173+
},
174+
onUnCheck: () => {
175+
this.host.engine.imessage("status.sub.disable", [
176+
this.host.engine.i18n("option.reactors"),
177+
]);
178+
},
179+
},
180+
),
181+
new BuildingUpgradeSettingsUi(this, settings.upgradeBuildings, locale, settings),
182+
]),
192183
]);
193184
}
194185

@@ -215,14 +206,6 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
215206
settings,
216207
meta.stages[0].label,
217208
sectionLabel,
218-
{
219-
onCheck: () => {
220-
this.refreshUi();
221-
},
222-
onUnCheck: () => {
223-
this.refreshUi();
224-
},
225-
},
226209
),
227210
BuildSectionTools.getBuildOption(
228211
parent,
@@ -233,12 +216,6 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
233216
sectionLabel,
234217
{
235218
upgradeIndicator: true,
236-
onCheck: () => {
237-
this.refreshUi();
238-
},
239-
onUnCheck: () => {
240-
this.refreshUi();
241-
},
242219
},
243220
),
244221
];
@@ -252,14 +229,6 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
252229
settings,
253230
meta.label,
254231
sectionLabel,
255-
{
256-
onCheck: () => {
257-
this.refreshUi();
258-
},
259-
onUnCheck: () => {
260-
this.refreshUi();
261-
},
262-
},
263232
),
264233
];
265234
}

source/ui/BuildingUpgradeSettingsUi.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import type { BuildingUpgradeSettings } from "../settings/BuildingUpgradeSetting
44
import type { SettingOptions } from "../settings/Settings.js";
55
import { Container } from "./components/Container.js";
66
import stylesLabelListItem from "./components/LabelListItem.module.css";
7-
import { SettingListItem, type SettingListItemOptions } from "./components/SettingListItem.js";
7+
import { SettingListItem } from "./components/SettingListItem.js";
88
import { SettingsList } from "./components/SettingsList.js";
9-
import { SettingsPanel, type SettingsPanelOptions } from "./components/SettingsPanel.js";
9+
import { SettingsPanel } from "./components/SettingsPanel.js";
1010
import type { UiComponent } from "./components/UiComponent.js";
1111

1212
export class BuildingUpgradeSettingsUi extends SettingsPanel<BuildingUpgradeSettings> {
@@ -15,53 +15,44 @@ export class BuildingUpgradeSettingsUi extends SettingsPanel<BuildingUpgradeSett
1515
settings: BuildingUpgradeSettings,
1616
locale: SettingOptions<SupportedLocale>,
1717
sectionSetting: BonfireSettings,
18-
options?: SettingsPanelOptions<SettingListItem> & SettingListItemOptions,
1918
) {
2019
const label = parent.host.engine.i18n("ui.upgrade.buildings");
2120
super(
2221
parent,
2322
settings,
2423
new SettingListItem(parent, settings, label, {
25-
childrenHead: [new Container(parent, { classes: [stylesLabelListItem.fillSpace] })],
2624
onCheck: (isBatchProcess?: boolean) => {
2725
parent.host.engine.imessage("status.auto.enable", [label]);
28-
this.refreshUi();
29-
options?.onCheck?.(isBatchProcess);
3026
},
3127
onUnCheck: (isBatchProcess?: boolean) => {
3228
parent.host.engine.imessage("status.auto.disable", [label]);
33-
this.refreshUi();
34-
options?.onUnCheck?.(isBatchProcess);
3529
},
3630
onRefresh: () => {
3731
this.expando.ineffective =
3832
sectionSetting.enabled &&
3933
settings.enabled &&
4034
!Object.values(settings.buildings).some(building => building.enabled);
4135
},
42-
}),
43-
options,
36+
}).addChildrenHead([new Container(parent, { classes: [stylesLabelListItem.fillSpace] })]),
4437
);
4538

4639
const items = [];
4740
for (const setting of Object.values(this.setting.buildings)) {
48-
const label = parent.host.engine.i18n(`$buildings.${setting.upgrade}.label`);
49-
const button = new SettingListItem(parent, setting, label, {
41+
const label = this.host.engine.i18n(`$buildings.${setting.upgrade}.label`);
42+
const button = new SettingListItem(this, setting, label, {
5043
onCheck: () => {
51-
parent.host.engine.imessage("status.sub.enable", [label]);
52-
this.refreshUi();
44+
this.host.engine.imessage("status.sub.enable", [label]);
5345
},
5446
onUnCheck: () => {
55-
parent.host.engine.imessage("status.sub.disable", [label]);
56-
this.refreshUi();
47+
this.host.engine.imessage("status.sub.disable", [label]);
5748
},
5849
});
5950

6051
items.push({ label: label, button: button });
6152
}
6253
// Ensure buttons are added into UI with their labels alphabetized.
6354
items.sort((a, b) => a.label.localeCompare(b.label));
64-
const itemsList = new SettingsList(parent);
55+
const itemsList = new SettingsList(this);
6556
for (const button of items) {
6657
itemsList.addChild(button.button);
6758
}

0 commit comments

Comments
 (0)