Skip to content

Commit

Permalink
use Set.has instead of toModifier or arrayContains
Browse files Browse the repository at this point in the history
  • Loading branch information
horrible-little-slime committed Nov 14, 2024
1 parent 8cd45eb commit 33f3d68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
24 changes: 9 additions & 15 deletions src/modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,28 @@ import {
familiarWeight,
getProperty,
Item,
ModifierValueType,
myFamiliar,
numericModifier,
print,
Skill,
splitModifiers,
stringModifier,
toModifier,
} from "kolmafia";
import { have } from "./lib.js";

import {
BooleanModifier,
booleanModifiersSet,
ModifierType,
NumericModifier,
numericModifiersSet,
StringModifier,
stringModifiersSet,
} from "./modifierTypes.js";
import { $effect } from "./template-string.js";
import { sum } from "./utils.js";
import { StringProperty } from "./propertyTypes.js";

function testModifierType(
potentialModifier: string,
modifierType: ModifierValueType,
) {
const modifier = toModifier(potentialModifier);
return modifier.name === potentialModifier && modifier.type === modifierType;
}

/**
* Type guard that determines if a given string is a boolean modifier
* @param modifier The modifier in question
Expand All @@ -43,7 +36,7 @@ function testModifierType(
export function isBooleanModifier(
modifier: string,
): modifier is BooleanModifier {
return testModifierType(modifier, "boolean");
return (booleanModifiersSet as Set<string>).has(modifier);
}

/**
Expand All @@ -54,7 +47,7 @@ export function isBooleanModifier(
export function isNumericModifier(
modifier: string,
): modifier is NumericModifier {
return testModifierType(modifier, "numeric");
return (numericModifiersSet as Set<string>).has(modifier);
}

/**
Expand All @@ -63,7 +56,7 @@ export function isNumericModifier(
* @returns Whether the string in question is a valid string modifier
*/
export function isStringModifier(modifier: string): modifier is StringModifier {
return testModifierType(modifier, "string");
return (stringModifiersSet as Set<string>).has(modifier);
}

/**
Expand All @@ -73,8 +66,9 @@ export function isStringModifier(modifier: string): modifier is StringModifier {
*/
export function isValidModifier(modifier: string): modifier is ModifierType {
return (
toModifier(modifier).type !== "none" &&
toModifier(modifier).name === modifier
isNumericModifier(modifier) ||
isBooleanModifier(modifier) ||
isStringModifier(modifier)
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/modifierTypes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// THIS FILE IS AUTOMATICALLY GENERATED. See tools/parseModifiers.ts for more information
export const stringModifiers = ["Class","Intrinsic Effect","Equalize","Wiki Name","Modifiers","Outfit","Stat Tuning","Effect","Equips On","Familiar Effect","Jiggle","Equalize Muscle","Equalize Mysticality","Equalize Moxie","Avatar","Rollover Effect","Skill","Floor Buffed Muscle","Floor Buffed Mysticality","Floor Buffed Moxie","Plumber Stat","Recipe","Evaluated Modifiers"] as const;
export type StringModifier = typeof stringModifiers[number];
export const stringModifiersSet = new Set(stringModifiers)export type StringModifier = typeof stringModifiers[number];

Check failure on line 3 in src/modifierTypes.ts

View workflow job for this annotation

GitHub Actions / testBuild

',' expected.
export const booleanModifiers = ["Softcore Only","Single Equip","Always Fumble","Never Fumble","Weakens Monster","Free Pull","Variable","Nonstackable Watch","Cold Immunity","Hot Immunity","Sleaze Immunity","Spooky Immunity","Stench Immunity","Cold Vulnerability","Hot Vulnerability","Sleaze Vulnerability","Spooky Vulnerability","Stench Vulnerability","Moxie Controls MP","Moxie May Control MP","Four Songs","Adventure Randomly","Adventure Underwater","Underwater Familiar","Generic","Unarmed","No Pull","Lasts Until Rollover","Alters Page Text","Attacks Can't Miss","Pirate","Blind","Breakable","Drops Items","Drops Meat","Volleyball or Sombrero","Extra Pickpocket","Negative Status Resist"] as const;
export type BooleanModifier = typeof booleanModifiers[number];
export const booleanModifiersSet = new Set(booleanModifiers)export type BooleanModifier = typeof booleanModifiers[number];

Check failure on line 5 in src/modifierTypes.ts

View workflow job for this annotation

GitHub Actions / testBuild

',' expected.
export const numericModifiers = ["Familiar Weight","Monster Level","Combat Rate","Initiative","Experience","Item Drop","Meat Drop","Damage Absorption","Damage Reduction","Cold Resistance","Hot Resistance","Sleaze Resistance","Spooky Resistance","Stench Resistance","Mana Cost","Moxie","Moxie Percent","Muscle","Muscle Percent","Mysticality","Mysticality Percent","Maximum HP","Maximum HP Percent","Maximum MP","Maximum MP Percent","Weapon Damage","Ranged Damage","Spell Damage","Spell Damage Percent","Cold Damage","Hot Damage","Sleaze Damage","Spooky Damage","Stench Damage","Cold Spell Damage","Hot Spell Damage","Sleaze Spell Damage","Spooky Spell Damage","Stench Spell Damage","Underwater Combat Rate","Fumble","HP Regen Min","HP Regen Max","MP Regen Min","MP Regen Max","Adventures","Familiar Weight Percent","Weapon Damage Percent","Ranged Damage Percent","Stackable Mana Cost","Hobo Power","Base Resting HP","Resting HP Percent","Bonus Resting HP","Base Resting MP","Resting MP Percent","Bonus Resting MP","Critical Hit Percent","PvP Fights","Volleyball","Sombrero","Leprechaun","Fairy","Meat Drop Penalty","Hidden Familiar Weight","Item Drop Penalty","Initiative Penalty","Food Drop","Booze Drop","Hat Drop","Weapon Drop","Offhand Drop","Shirt Drop","Pants Drop","Accessory Drop","Volleyball Effectiveness","Sombrero Effectiveness","Leprechaun Effectiveness","Fairy Effectiveness","Familiar Weight Cap","Slime Resistance","Slime Hates It","Spell Critical Percent","Muscle Experience","Mysticality Experience","Moxie Experience","Effect Duration","Candy Drop","DB Combat Damage","Sombrero Bonus","Familiar Experience","Sporadic Meat Drop","Sporadic Item Drop","Meat Bonus","Pickpocket Chance","Combat Mana Cost","Muscle Experience Percent","Mysticality Experience Percent","Moxie Experience Percent","Minstrel Level","Muscle Limit","Mysticality Limit","Moxie Limit","Song Duration","Prismatic Damage","Smithsness","Supercold Resistance","Reduce Enemy Defense","Pool Skill","Familiar Damage","Gear Drop","Maximum Hooch","Water Level","Crimbot Outfit Power","Familiar Tuning Muscle","Familiar Tuning Mysticality","Familiar Tuning Moxie","Random Monster Modifiers","Luck","Othello Skill","Disco Style","Rollover Effect Duration","Sixgun Damage","Fishing Skill","Additional Song","Sprinkle Drop","Absorb Adventures","Absorb Stats","Rubee Drop","Kruegerand Drop","WarBear Armor Penetration","Maximum PP","Plumber Power","Drippy Damage","Drippy Resistance","Energy","Scrap","Familiar Action Bonus","Water","Spleen Drop","Potion Drop","Sauce Spell Damage","Monster Level Percent","Food Fairy","Booze Fairy","Candy Fairy","Food Fairy Effectiveness","Booze Fairy Effectiveness","Candy Fairy Effectiveness","Damage Aura","Sporadic Damage Aura","Thorns","Sporadic Thorns","Stomach Capacity","Liver Capacity","Spleen Capacity","Free Rests","Leaves","Elf Warfare Effectiveness","Pirate Warfare Effectiveness","MPC Drop","Piece of Twelve Drop","Combat Item Damage Percent","Avoid Attack","Damage vs. Bugbears","Damage vs. Werewolves","Damage vs. Zombies","Damage vs. Ghosts","Damage vs. Vampires","Damage vs. Skeletons","Damage vs. Undead"] as const;
export type NumericModifier = typeof numericModifiers[number];
export const numericModifiersSet = new Set(numericModifiers)export type NumericModifier = typeof numericModifiers[number];

Check failure on line 7 in src/modifierTypes.ts

View workflow job for this annotation

GitHub Actions / testBuild

',' expected.
export type ModifierType = NumericModifier | StringModifier | BooleanModifier;
1 change: 1 addition & 0 deletions tools/parseModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async function main() {
contents += `export const ${typeName}Modifiers = ${JSON.stringify(
values,
)} as const;\n`;
contents += `export const ${typeName}ModifiersSet = new Set(${typeName}Modifiers)`
contents += `export type ${tc(
typeName,
)}Modifier = typeof ${typeName}Modifiers[number];\n`;
Expand Down

0 comments on commit 33f3d68

Please sign in to comment.