Skip to content

Commit

Permalink
Merge pull request #89 from loathers/normalised-item
Browse files Browse the repository at this point in the history
toNormaliseItem
  • Loading branch information
horrible-little-slime committed Jun 18, 2024
2 parents 84ac917 + fdaf62c commit 64a5a4b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropBindlestocking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { toNormalisedItem } from "../utils";

export const DROP_BINDLESTOCKING: ExcavatorProject = {
name: "Bindlestocking",
Expand All @@ -15,10 +15,8 @@ export const DROP_BINDLESTOCKING: ExcavatorProject = {
/Something gets knocked loose from your bindlestocking!.*?You acquire an item: <b>(.*?)<\/b>/,
);
if (!result) return null;
const item = Item.get(result[1]);
return {
item: item !== Item.none ? toNormalisedString(item) : result[1],
};
const item = toNormalisedItem(result[1]);
return { item };
},
},
};
10 changes: 3 additions & 7 deletions packages/excavator-projects/projects/dropConSnowglobe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "core-js/modules/es.string.match-all";
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { toNormalisedItem } from "../utils";

export const DROP_CON_SNOWGLOBE: ExcavatorProject = {
name: "KoL Con 13 Snowglobe",
Expand Down Expand Up @@ -82,14 +82,10 @@ function spadeSnowglobe(
for (const indicator of INDICATORS) {
// Multiple results are possible if the time-twitching toolbelt is equipped
for (const match of page.matchAll(indicator.pattern)) {
let str = "";
if (indicator.type === "item") {
const item = Item.get(match[1]);
str = item !== Item.none ? toNormalisedString(item) : match[1];
}
const item = indicator.type === "item" ? toNormalisedItem(match[1]) : "";
data.push({
type: indicator.type,
item: str,
item,
});
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropMixedEverything.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { toNormalisedItem } from "../utils";

export const DROP_MIXED_EVERYTHING: ExcavatorProject = {
name: "Can Of Mixed Everything",
Expand All @@ -17,10 +17,8 @@ export const DROP_MIXED_EVERYTHING: ExcavatorProject = {
/Something falls out of your can of mixed everything.*?You acquire an item: <b>(.*?)<\/b>/,
);
if (!result) return null;
const item = Item.get(result[1]);
return {
item: item !== Item.none ? toNormalisedString(item) : result[1],
};
const item = toNormalisedItem(result[1]);
return { item };
},
},
};
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropMrCheengs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { toNormalisedItem } from "../utils";

export const DROP_MR_CHEENGS: ExcavatorProject = {
name: "Mr. Cheeng's Spectacles",
Expand All @@ -18,10 +18,8 @@ export const DROP_MR_CHEENGS: ExcavatorProject = {
/You see a weird thing out of the corner of your eye, and you grab it.\s+Far out, man!.*?You acquire an item: <b>(.*?)<\/b>/,
);
if (!result) return null;
const item = Item.get(result[1]);
return {
item: item !== Item.none ? toNormalisedString(item) : result[1],
};
const item = toNormalisedItem(result[1]);
return { item };
},
},
};
8 changes: 3 additions & 5 deletions packages/excavator-projects/projects/dropMrScreeges.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { currentRound, equippedAmount, Item } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { toNormalisedItem } from "../utils";

export const DROP_MR_SCREEGES: ExcavatorProject = {
name: "Mr. Screege's Spectacles",
Expand All @@ -18,10 +18,8 @@ export const DROP_MR_SCREEGES: ExcavatorProject = {
/You notice something valuable hidden .*?You acquire an item: <b>(.*?)<\/b>/,
);
if (!result) return null;
const item = Item.get(result[1]);
return {
item: item !== Item.none ? toNormalisedString(item) : result[1],
};
const item = toNormalisedItem(result[1]);
return { item };
},
},
};
6 changes: 6 additions & 0 deletions packages/excavator-projects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
myPath,
Path,
sessionStorage,
toItem,
} from "kolmafia";

const ALTERING_EFFECTS = Effect.get([
Expand Down Expand Up @@ -81,6 +82,11 @@ export function getDifficultySeed() {
};
}

export function toNormalisedItem(name: string) {
const item = toItem(name);
return item === Item.none ? name : toNormalisedString(item);
}

export function toNormalisedString(thing: Item | Monster | Location) {
return `[${thing.id}]${"name" in thing ? thing.name : thing.toString()}`;
}
Expand Down

0 comments on commit 64a5a4b

Please sign in to comment.