@@ -9,23 +9,23 @@ import {
9
9
type BonfireItem ,
10
10
BonfireSettings ,
11
11
} from "./settings/BonfireSettings.js" ;
12
- import { cwarn } from "./tools/Log.js" ;
12
+ import { cdebug , cwarn } from "./tools/Log.js" ;
13
13
import type {
14
- BuildButton ,
15
- Building ,
16
- BuildingExt ,
17
14
BuildingMeta ,
18
- ButtonModernController ,
19
- ButtonModernModel ,
20
- GameTab ,
21
- } from "./types/index.js" ;
22
-
23
- export type BonfireTab = GameTab ;
15
+ BuildingsModern ,
16
+ GatherCatnipButton ,
17
+ GatherCatnipButtonController ,
18
+ RefineCatnipButton ,
19
+ UnsafeBuilding ,
20
+ UnsafeBuildingExt ,
21
+ } from "./types/buildings.js" ;
22
+ import type { ButtonModern , UnsafeButtonModernModel } from "./types/core.js" ;
23
+ import type { Building } from "./types/index.js" ;
24
24
25
25
export class BonfireManager implements Automation {
26
26
private readonly _host : KittenScientists ;
27
27
readonly settings : BonfireSettings ;
28
- readonly manager : TabManager ;
28
+ readonly manager : TabManager < BuildingsModern > ;
29
29
private readonly _bulkManager : BulkPurchaseHelper ;
30
30
private readonly _workshopManager : WorkshopManager ;
31
31
@@ -36,7 +36,7 @@ export class BonfireManager implements Automation {
36
36
) {
37
37
this . _host = host ;
38
38
this . settings = settings ;
39
- this . manager = new TabManager < BonfireTab > ( this . _host , "Bonfire" ) ;
39
+ this . manager = new TabManager < BuildingsModern > ( this . _host , "Bonfire" ) ;
40
40
41
41
this . _workshopManager = workshopManager ;
42
42
this . _bulkManager = new BulkPurchaseHelper ( this . _host , this . _workshopManager ) ;
@@ -69,7 +69,7 @@ export class BonfireManager implements Automation {
69
69
const bulkManager = this . _bulkManager ;
70
70
71
71
// Get the current metadata for all the referenced buildings.
72
- const metaData : Partial < Record < BonfireItem , BuildingMeta > > = { } ;
72
+ const metaData : Partial < Record < BonfireItem , Required < UnsafeBuilding > > > = { } ;
73
73
for ( const build of Object . values ( builds ) ) {
74
74
metaData [ build . building ] = this . getBuild (
75
75
( build . baseBuilding ?? build . building ) as Building ,
@@ -125,7 +125,7 @@ export class BonfireManager implements Automation {
125
125
this . _host . engine . iactivity ( "upgrade.building.pasture" , [ ] , "ks-upgrade" ) ;
126
126
127
127
// Upgrade the pasture.
128
- this . _host . game . ui . render ( ) ;
128
+ this . _host . game . ui ? .render ( ) ;
129
129
this . build ( "pasture" , 1 , 1 ) ;
130
130
context . requestGameUiRefresh = true ;
131
131
}
@@ -158,7 +158,7 @@ export class BonfireManager implements Automation {
158
158
159
159
this . _host . engine . iactivity ( "upgrade.building.aqueduct" , [ ] , "ks-upgrade" ) ;
160
160
161
- this . _host . game . ui . render ( ) ;
161
+ this . _host . game . ui ? .render ( ) ;
162
162
this . build ( "aqueduct" , 1 , 1 ) ;
163
163
context . requestGameUiRefresh = true ;
164
164
}
@@ -215,7 +215,7 @@ export class BonfireManager implements Automation {
215
215
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
216
216
libraryMeta . calculateEffects ?.( libraryMeta , this . _host . game ) ;
217
217
this . _host . engine . iactivity ( "upgrade.building.library" , [ ] , "ks-upgrade" ) ;
218
- this . _host . game . ui . render ( ) ;
218
+ this . _host . game . ui ? .render ( ) ;
219
219
this . build ( "library" , 1 , 1 ) ;
220
220
context . requestGameUiRefresh = true ;
221
221
return ;
@@ -241,7 +241,7 @@ export class BonfireManager implements Automation {
241
241
242
242
this . _host . engine . iactivity ( "upgrade.building.warehouse" , [ ] , "ks-upgrade" ) ;
243
243
244
- this . _host . game . ui . render ( ) ;
244
+ this . _host . game . ui ? .render ( ) ;
245
245
this . build ( "warehouse" , 1 , 1 ) ;
246
246
context . requestGameUiRefresh = true ;
247
247
@@ -272,7 +272,7 @@ export class BonfireManager implements Automation {
272
272
273
273
this . _host . engine . iactivity ( "upgrade.building.amphitheatre" , [ ] , "ks-upgrade" ) ;
274
274
275
- this . _host . game . ui . render ( ) ;
275
+ this . _host . game . ui ? .render ( ) ;
276
276
this . build ( "amphitheatre" , 1 , 1 ) ;
277
277
context . requestGameUiRefresh = true ;
278
278
}
@@ -333,7 +333,7 @@ export class BonfireManager implements Automation {
333
333
autoGather ( ) : void {
334
334
const controller = new classes . game . ui . GatherCatnipButtonController ( this . _host . game ) ;
335
335
for ( let clicks = 0 ; clicks < Math . floor ( this . _host . engine . settings . interval / 20 ) ; ++ clicks ) {
336
- controller . buyItem ( null , null ) ;
336
+ controller . buyItem ( undefined , null ) ;
337
337
}
338
338
}
339
339
@@ -352,7 +352,11 @@ export class BonfireManager implements Automation {
352
352
353
353
const amountTemp = amountCalculated ;
354
354
const label = this . _getBuildLabel ( build . meta , stage ) ;
355
- amountCalculated = this . _bulkManager . construct ( button . model , button , amountCalculated ) ;
355
+ amountCalculated = this . _bulkManager . construct (
356
+ button . model ,
357
+ button . controller ,
358
+ amountCalculated ,
359
+ ) ;
356
360
if ( amountCalculated !== amountTemp ) {
357
361
cwarn ( `${ label } Amount ordered: ${ amountTemp } Amount Constructed: ${ amountCalculated } ` ) ;
358
362
}
@@ -369,22 +373,32 @@ export class BonfireManager implements Automation {
369
373
}
370
374
}
371
375
372
- private _getBuildLabel ( meta : BuildingMeta , stage ?: number ) : string {
376
+ private _getBuildLabel ( meta : UnsafeBuilding , stage ?: number ) : string {
373
377
return meta . stages && ! isNil ( stage ) ? meta . stages [ stage ] . label : mustExist ( meta . label ) ;
374
378
}
375
379
376
- getBuild ( name : Building ) : BuildingExt {
377
- return this . _host . game . bld . getBuildingExt ( name ) ;
380
+ getBuild ( name : Building ) : BuildingMeta < Required < UnsafeBuilding > > {
381
+ return this . _host . game . bld . getBuildingExt ( name ) as BuildingMeta < Required < UnsafeBuilding > > ;
378
382
}
379
383
380
- getBuildButton (
381
- name : Building ,
382
- stage ?: number ,
383
- ) : BuildButton < string , ButtonModernModel , ButtonModernController > | null {
384
+ getBuildButton ( name : Building , stage ?: number ) {
384
385
const buttons = this . manager . tab . children ;
385
- const build = this . getBuild ( name ) ;
386
- const label = this . _getBuildLabel ( build . meta , stage ) ;
387
- return ( buttons . find ( button => ( button . model ?. options . name as string ) . startsWith ( label ) ) ??
388
- null ) as BuildButton < string , ButtonModernModel , ButtonModernController > | null ;
386
+
387
+ const button =
388
+ (
389
+ buttons . filter (
390
+ button =>
391
+ button instanceof com . nuclearunicorn . game . ui . ButtonModern === false &&
392
+ button instanceof classes . game . ui . RefineCatnipButton === false ,
393
+ ) as Array < Exclude < ( typeof buttons ) [ number ] , GatherCatnipButton | RefineCatnipButton > >
394
+ ) . find (
395
+ button => button . model ?. metadata . name === name && button . model ?. metadata . stage === stage ,
396
+ ) ?? null ;
397
+
398
+ if ( button === null ) {
399
+ cdebug ( `Couldn't find button for ${ name } ! This will likely create problems.` ) ;
400
+ }
401
+
402
+ return button ;
389
403
}
390
404
}
0 commit comments