1
1
import { coalesceArray , isNil } from "@oliversalzburg/js-utils/data/nil.js" ;
2
2
import type { SupportedLocale } from "../Engine.js" ;
3
- import type { KittenScientists } from "../KittenScientists.js" ;
4
3
import { BonfireSettings } from "../settings/BonfireSettings.js" ;
5
4
import type { SettingOptions } from "../settings/Settings.js" ;
6
5
import type { Building , StagedBuilding } from "../types/index.js" ;
@@ -13,26 +12,27 @@ import { SettingListItem, type SettingListItemOptions } from "./components/Setti
13
12
import { SettingTriggerListItem } from "./components/SettingTriggerListItem.js" ;
14
13
import { SettingsList } from "./components/SettingsList.js" ;
15
14
import { SettingsPanel , type SettingsPanelOptions } from "./components/SettingsPanel.js" ;
15
+ import type { UiComponent } from "./components/UiComponent.js" ;
16
16
17
17
export class BonfireSettingsUi extends SettingsPanel < BonfireSettings , SettingTriggerListItem > {
18
18
constructor (
19
- host : KittenScientists ,
19
+ parent : UiComponent ,
20
20
settings : BonfireSettings ,
21
21
locale : SettingOptions < SupportedLocale > ,
22
22
options ?: SettingsPanelOptions < SettingTriggerListItem > & SettingListItemOptions ,
23
23
) {
24
- const label = host . engine . i18n ( "ui.build" ) ;
24
+ const label = parent . host . engine . i18n ( "ui.build" ) ;
25
25
super (
26
- host ,
26
+ parent ,
27
27
settings ,
28
- new SettingTriggerListItem ( host , settings , locale , label , {
28
+ new SettingTriggerListItem ( parent , settings , locale , label , {
29
29
onCheck : ( isBatchProcess ?: boolean ) => {
30
- host . engine . imessage ( "status.auto.enable" , [ label ] ) ;
30
+ parent . host . engine . imessage ( "status.auto.enable" , [ label ] ) ;
31
31
this . refreshUi ( ) ;
32
32
options ?. onCheck ?.( isBatchProcess ) ;
33
33
} ,
34
34
onUnCheck : ( isBatchProcess ?: boolean ) => {
35
- host . engine . imessage ( "status.auto.disable" , [ label ] ) ;
35
+ parent . host . engine . imessage ( "status.auto.disable" , [ label ] ) ;
36
36
this . refreshUi ( ) ;
37
37
options ?. onUnCheck ?.( isBatchProcess ) ;
38
38
} ,
@@ -57,24 +57,24 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
57
57
} ,
58
58
onRefreshTrigger : ( ) => {
59
59
const element = this . settingItem ;
60
- element . triggerButton . element [ 0 ] . title = host . engine . i18n ( "ui.trigger.section" , [
60
+ element . triggerButton . element [ 0 ] . title = parent . host . engine . i18n ( "ui.trigger.section" , [
61
61
settings . trigger < 0
62
- ? host . engine . i18n ( "ui.trigger.section.inactive" )
63
- : host . renderPercentage ( settings . trigger , locale . selected , true ) ,
62
+ ? parent . host . engine . i18n ( "ui.trigger.section.inactive" )
63
+ : parent . host . renderPercentage ( settings . trigger , locale . selected , true ) ,
64
64
] ) ;
65
65
} ,
66
66
onSetTrigger : async ( ) => {
67
67
const value = await Dialog . prompt (
68
- host ,
69
- host . engine . i18n ( "ui.trigger.prompt.percentage" ) ,
70
- host . engine . i18n ( "ui.trigger.section.prompt" , [
68
+ parent ,
69
+ parent . host . engine . i18n ( "ui.trigger.prompt.percentage" ) ,
70
+ parent . host . engine . i18n ( "ui.trigger.section.prompt" , [
71
71
label ,
72
72
settings . trigger !== - 1
73
- ? host . renderPercentage ( settings . trigger , locale . selected , true )
74
- : host . engine . i18n ( "ui.infinity" ) ,
73
+ ? parent . host . renderPercentage ( settings . trigger , locale . selected , true )
74
+ : parent . host . engine . i18n ( "ui.infinity" ) ,
75
75
] ) ,
76
- settings . trigger !== - 1 ? host . renderPercentage ( settings . trigger ) : "" ,
77
- host . engine . i18n ( "ui.trigger.section.promptExplainer" ) ,
76
+ settings . trigger !== - 1 ? parent . host . renderPercentage ( settings . trigger ) : "" ,
77
+ parent . host . engine . i18n ( "ui.trigger.section.promptExplainer" ) ,
78
78
) ;
79
79
80
80
if ( value === undefined ) {
@@ -86,7 +86,7 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
86
86
return ;
87
87
}
88
88
89
- settings . trigger = host . parsePercentage ( value ) ;
89
+ settings . trigger = parent . host . parsePercentage ( value ) ;
90
90
} ,
91
91
} ) ,
92
92
) ;
@@ -95,15 +95,16 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
95
95
// We want the ability to use `this` in our callbacks, to construct more complex
96
96
// usage scenarios where we need access to the entire UI section.
97
97
this . addChildren ( [
98
- new SettingsList ( host , {
98
+ new SettingsList ( parent , {
99
99
children : coalesceArray (
100
- host . game . bld . buildingGroups . flatMap ( buildingGroup => [
101
- new HeaderListItem ( host , buildingGroup . title ) ,
100
+ parent . host . game . bld . buildingGroups . flatMap ( buildingGroup => [
101
+ new HeaderListItem ( parent , buildingGroup . title ) ,
102
102
...buildingGroup . buildings . flatMap ( building =>
103
- this . _getBuildOptions ( host , settings , locale , label , building ) ,
103
+ this . _getBuildOptions ( parent , settings , locale , label , building ) ,
104
104
) ,
105
- buildingGroup !== host . game . bld . buildingGroups [ host . game . bld . buildingGroups . length - 1 ]
106
- ? new Delimiter ( host )
105
+ buildingGroup !==
106
+ parent . host . game . bld . buildingGroups [ parent . host . game . bld . buildingGroups . length - 1 ]
107
+ ? new Delimiter ( parent )
107
108
: undefined ,
108
109
] ) ,
109
110
) ,
@@ -112,47 +113,78 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
112
113
this . refreshUi ( ) ;
113
114
} ,
114
115
} ) ,
115
- new SettingsList ( host , {
116
+ new SettingsList ( parent , {
116
117
children : [
117
- new HeaderListItem ( host , host . engine . i18n ( "ui.additional" ) ) ,
118
- new SettingListItem ( host , settings . gatherCatnip , host . engine . i18n ( "option.catnip" ) , {
119
- onCheck : ( ) => {
120
- host . engine . imessage ( "status.sub.enable" , [ host . engine . i18n ( "option.catnip" ) ] ) ;
121
- } ,
122
- onUnCheck : ( ) => {
123
- host . engine . imessage ( "status.sub.disable" , [ host . engine . i18n ( "option.catnip" ) ] ) ;
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
+ } ,
124
134
} ,
125
- } ) ,
135
+ ) ,
126
136
new SettingListItem (
127
- host ,
137
+ parent ,
128
138
settings . turnOnSteamworks ,
129
- host . engine . i18n ( "option.steamworks" ) ,
139
+ parent . host . engine . i18n ( "option.steamworks" ) ,
130
140
{
131
141
onCheck : ( ) => {
132
- host . engine . imessage ( "status.sub.enable" , [ host . engine . i18n ( "option.steamworks" ) ] ) ;
142
+ parent . host . engine . imessage ( "status.sub.enable" , [
143
+ parent . host . engine . i18n ( "option.steamworks" ) ,
144
+ ] ) ;
133
145
} ,
134
146
onUnCheck : ( ) => {
135
- host . engine . imessage ( "status.sub.disable" , [ host . engine . i18n ( "option.steamworks" ) ] ) ;
147
+ parent . host . engine . imessage ( "status.sub.disable" , [
148
+ parent . host . engine . i18n ( "option.steamworks" ) ,
149
+ ] ) ;
136
150
} ,
137
151
} ,
138
152
) ,
139
- new SettingListItem ( host , settings . turnOnMagnetos , host . engine . i18n ( "option.magnetos" ) , {
140
- onCheck : ( ) => {
141
- host . engine . imessage ( "status.sub.enable" , [ host . engine . i18n ( "option.magnetos" ) ] ) ;
142
- } ,
143
- onUnCheck : ( ) => {
144
- host . engine . imessage ( "status.sub.disable" , [ host . engine . i18n ( "option.magnetos" ) ] ) ;
145
- } ,
146
- } ) ,
147
- new SettingListItem ( host , settings . turnOnReactors , host . engine . i18n ( "option.reactors" ) , {
148
- onCheck : ( ) => {
149
- host . engine . imessage ( "status.sub.enable" , [ host . engine . i18n ( "option.reactors" ) ] ) ;
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
+ } ,
150
168
} ,
151
- onUnCheck : ( ) => {
152
- host . engine . imessage ( "status.sub.disable" , [ host . engine . i18n ( "option.reactors" ) ] ) ;
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
+ } ,
153
185
} ,
154
- } ) ,
155
- new BuildingUpgradeSettingsUi ( host , settings . upgradeBuildings , locale , settings ) ,
186
+ ) ,
187
+ new BuildingUpgradeSettingsUi ( parent , settings . upgradeBuildings , locale , settings ) ,
156
188
] ,
157
189
hasDisableAll : false ,
158
190
hasEnableAll : false ,
@@ -161,7 +193,7 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
161
193
}
162
194
163
195
private _getBuildOptions (
164
- host : KittenScientists ,
196
+ parent : UiComponent ,
165
197
settings : BonfireSettings ,
166
198
locale : SettingOptions < SupportedLocale > ,
167
199
sectionLabel : string ,
@@ -171,13 +203,13 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
171
203
return [ ] ;
172
204
}
173
205
174
- const meta = host . game . bld . getBuildingExt ( building ) . meta ;
206
+ const meta = parent . host . game . bld . getBuildingExt ( building ) . meta ;
175
207
if ( ! isNil ( meta . stages ) ) {
176
208
const name = Object . values ( settings . buildings ) . find ( item => item . baseBuilding === building )
177
209
?. building as StagedBuilding ;
178
210
return [
179
211
BuildSectionTools . getBuildOption (
180
- host ,
212
+ parent ,
181
213
settings . buildings [ building ] ,
182
214
locale ,
183
215
settings ,
@@ -193,7 +225,7 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
193
225
} ,
194
226
) ,
195
227
BuildSectionTools . getBuildOption (
196
- host ,
228
+ parent ,
197
229
settings . buildings [ name ] ,
198
230
locale ,
199
231
settings ,
@@ -214,7 +246,7 @@ export class BonfireSettingsUi extends SettingsPanel<BonfireSettings, SettingTri
214
246
if ( ! isNil ( meta . label ) ) {
215
247
return [
216
248
BuildSectionTools . getBuildOption (
217
- host ,
249
+ parent ,
218
250
settings . buildings [ building ] ,
219
251
locale ,
220
252
settings ,
0 commit comments