Skip to content

Commit 549f9ef

Browse files
committed
Provide a more type-correct overlay over BOOSTS
1 parent 2f6b331 commit 549f9ef

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
@@ -608,7 +608,6 @@ declare const REACTION_TIME: {
608608
};
609609

610610
declare const BOOSTS: {
611-
[part: string]: { [boost: string]: { [action: string]: number } };
612611
work: {
613612
UO: {
614613
harvest: 3;
@@ -722,7 +721,7 @@ declare const BOOSTS: {
722721
damage: 0.3;
723722
};
724723
};
725-
};
724+
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;
726725

727726
declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];
728727

@@ -1729,7 +1728,7 @@ type BodyPartDefinition<T extends BodyPartConstant = BodyPartConstant> = T exten
17291728
*
17301729
* If the body part is boosted, this property specifies the mineral type which is used for boosting.
17311730
*/
1732-
boost?: keyof (typeof BOOSTS)[T];
1731+
boost?: keyof typeof BOOSTS[T];
17331732
/**
17341733
* One of the body part types constants.
17351734
*/
@@ -2733,6 +2732,21 @@ type EffectConstant = EFFECT_INVULNERABILITY | EFFECT_COLLAPSE_TIMER;
27332732

27342733
type EFFECT_INVULNERABILITY = 1001;
27352734
type EFFECT_COLLAPSE_TIMER = 1002;
2735+
2736+
type BoostModifier =
2737+
| "harvest"
2738+
| "build"
2739+
| "repair"
2740+
| "dismantle"
2741+
| "upgradeController"
2742+
| "attack"
2743+
| "rangedAttack"
2744+
| "rangedMassAttack"
2745+
| "heal"
2746+
| "rangedHeal"
2747+
| "capacity"
2748+
| "fatigue"
2749+
| "damage";
27362750
/**
27372751
* The options that can be accepted by `findRoute()` and friends.
27382752
*/

dist/screeps-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ function atackPower(creep: Creep) {
13321332
return creep.body
13331333
.map((part) => {
13341334
if (part.type === ATTACK) {
1335-
const multiplier = part.boost ? BOOSTS[part.type][part.boost].attack : 1;
1335+
const multiplier = part.boost ? BOOSTS[part.type][part.boost]?.attack ?? 0 : 1;
13361336
return multiplier * ATTACK_POWER;
13371337
}
13381338
return 0;

src/constants.ts

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

610610
declare const BOOSTS: {
611-
[part: string]: { [boost: string]: { [action: string]: number } };
612611
work: {
613612
UO: {
614613
harvest: 3;
@@ -722,7 +721,7 @@ declare const BOOSTS: {
722721
damage: 0.3;
723722
};
724723
};
725-
};
724+
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;
726725

727726
declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];
728727

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
@@ -698,3 +698,18 @@ type EffectConstant = EFFECT_INVULNERABILITY | EFFECT_COLLAPSE_TIMER;
698698

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

0 commit comments

Comments
 (0)