Skip to content

Commit

Permalink
Provide a more type-correct overlay over BOOSTS
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Feb 26, 2024
1 parent 3885aa1 commit 8b699b4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
20 changes: 17 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ declare const REACTION_TIME: {
};

declare const BOOSTS: {
[part: string]: { [boost: string]: { [action: string]: number } };
work: {
UO: {
harvest: 3;
Expand Down Expand Up @@ -739,7 +738,7 @@ declare const BOOSTS: {
damage: 0.3;
};
};
};
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;

declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];

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

type EFFECT_INVULNERABILITY = 1001;
type EFFECT_COLLAPSE_TIMER = 1002;

type BoostModifier =
| "harvest"
| "build"
| "repair"
| "dismantle"
| "upgradeController"
| "attack"
| "rangedAttack"
| "rangedMassAttack"
| "heal"
| "rangedHeal"
| "capacity"
| "fatigue"
| "damage";
/**
* The options that can be accepted by `findRoute()` and friends.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ function atackPower(creep: Creep) {
return creep.body
.map((part) => {
if (part.type === ATTACK) {
const multiplier = part.boost ? BOOSTS[part.type][part.boost].attack : 1;
const multiplier = part.boost ? BOOSTS[part.type][part.boost]?.attack ?? 0 : 1;
return multiplier * ATTACK_POWER;
}
return 0;
Expand Down
3 changes: 1 addition & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ declare const REACTION_TIME: {
};

declare const BOOSTS: {
[part: string]: { [boost: string]: { [action: string]: number } };
work: {
UO: {
harvest: 3;
Expand Down Expand Up @@ -724,7 +723,7 @@ declare const BOOSTS: {
damage: 0.3;
};
};
};
} & Record<BodyPartConstant, Record<MineralBoostConstant, Record<BoostModifier, number>>>;

declare const INTERSHARD_RESOURCES: InterShardResourceConstant[];

Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type BodyPartDefinition<T extends BodyPartConstant = BodyPartConstant> = T exten
*
* If the body part is boosted, this property specifies the mineral type which is used for boosting.
*/
boost?: keyof (typeof BOOSTS)[T];
boost?: keyof typeof BOOSTS[T];
/**
* One of the body part types constants.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,18 @@ type EffectConstant = EFFECT_INVULNERABILITY | EFFECT_COLLAPSE_TIMER;

type EFFECT_INVULNERABILITY = 1001;
type EFFECT_COLLAPSE_TIMER = 1002;

type BoostModifier =
| "harvest"
| "build"
| "repair"
| "dismantle"
| "upgradeController"
| "attack"
| "rangedAttack"
| "rangedMassAttack"
| "heal"
| "rangedHeal"
| "capacity"
| "fatigue"
| "damage";

0 comments on commit 8b699b4

Please sign in to comment.