Skip to content

Commit 7ad71ff

Browse files
committed
Provide a more type-correct overlay over BOOSTS
1 parent 2de9172 commit 7ad71ff

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

dist/index.d.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ declare const REACTION_TIME: {
625625
};
626626

627627
declare const BOOSTS: {
628-
[part: string]: { [boost: string]: { [action: string]: number } };
629628
work: {
630629
UO: {
631630
harvest: 3;
@@ -739,7 +738,7 @@ declare const BOOSTS: {
739738
damage: 0.3;
740739
};
741740
};
742-
};
741+
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;
743742

744743
declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];
745744

@@ -1746,7 +1745,7 @@ type BodyPartDefinition<T extends BodyPartConstant = BodyPartConstant> = T exten
17461745
*
17471746
* If the body part is boosted, this property specifies the mineral type which is used for boosting.
17481747
*/
1749-
boost?: keyof (typeof BOOSTS)[T];
1748+
boost?: keyof typeof BOOSTS[T];
17501749
/**
17511750
* One of the body part types constants.
17521751
*/
@@ -2777,6 +2776,21 @@ type EffectConstant = EFFECT_INVULNERABILITY | EFFECT_COLLAPSE_TIMER;
27772776

27782777
type EFFECT_INVULNERABILITY = 1001;
27792778
type EFFECT_COLLAPSE_TIMER = 1002;
2779+
2780+
type BoostModifier =
2781+
| "harvest"
2782+
| "build"
2783+
| "repair"
2784+
| "dismantle"
2785+
| "upgradeController"
2786+
| "attack"
2787+
| "rangedAttack"
2788+
| "rangedMassAttack"
2789+
| "heal"
2790+
| "rangedHeal"
2791+
| "capacity"
2792+
| "fatigue"
2793+
| "damage";
27802794
/**
27812795
* The options that can be accepted by `findRoute()` and friends.
27822796
*/

dist/screeps-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ function atackPower(creep: Creep) {
13421342
return creep.body
13431343
.map((part) => {
13441344
if (part.type === ATTACK) {
1345-
const multiplier = part.boost ? BOOSTS[part.type][part.boost].attack : 1;
1345+
const multiplier = part.boost ? BOOSTS[part.type][part.boost]?.attack ?? 0 : 1;
13461346
return multiplier * ATTACK_POWER;
13471347
}
13481348
return 0;

src/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ declare const REACTION_TIME: {
610610
};
611611

612612
declare const BOOSTS: {
613-
[part: string]: { [boost: string]: { [action: string]: number } };
614613
work: {
615614
UO: {
616615
harvest: 3;
@@ -724,7 +723,7 @@ declare const BOOSTS: {
724723
damage: 0.3;
725724
};
726725
};
727-
};
726+
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;
728727

729728
declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];
730729

src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type BodyPartDefinition<T extends BodyPartConstant = BodyPartConstant> = T exten
147147
*
148148
* If the body part is boosted, this property specifies the mineral type which is used for boosting.
149149
*/
150-
boost?: keyof (typeof BOOSTS)[T];
150+
boost?: keyof typeof BOOSTS[T];
151151
/**
152152
* One of the body part types constants.
153153
*/

src/literals.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,3 +700,18 @@ type EffectConstant = EFFECT_INVULNERABILITY | EFFECT_COLLAPSE_TIMER;
700700

701701
type EFFECT_INVULNERABILITY = 1001;
702702
type EFFECT_COLLAPSE_TIMER = 1002;
703+
704+
type BoostModifier =
705+
| "harvest"
706+
| "build"
707+
| "repair"
708+
| "dismantle"
709+
| "upgradeController"
710+
| "attack"
711+
| "rangedAttack"
712+
| "rangedMassAttack"
713+
| "heal"
714+
| "rangedHeal"
715+
| "capacity"
716+
| "fatigue"
717+
| "damage";

0 commit comments

Comments
 (0)