Skip to content

Commit

Permalink
further merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokoeka committed Jan 29, 2024
1 parent c2f8e10 commit aa82c5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 51 deletions.
59 changes: 12 additions & 47 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { cliExecute, isAccessible, isDarkMode, print, sellPrice } from "kolmafia";
import { ALL_TAB_TITLES, isTabTitle, Tab, TabId, TabTitle } from "./types";
import {
cliExecute,
isAccessible,
isDarkMode,
Item,
print,
sellPrice,
toInt,
toItem,
visitUrl,
} from "kolmafia";
import { ALL_TAB_TITLES, InventoryType, isTabTitle, Tab, TabId, TabTitle } from "./types";
import { Options } from "./options";
import { actions, filters } from "./actions";
import { favoriteTabs, parseItems, parseNotes } from "./parse";
Expand Down Expand Up @@ -53,51 +63,6 @@ function tabCollections(): Map<string, Item[]> {
return new Map(values);
}

function favoriteTabs(): Tab[] {
// visit the consumables tab to ensure that you get clickable links for
// all favorite tabs
const inventory = visitUrl(`inventory.php?which=1`);
const tabRegex =
/<a href="inventory.php\?which=f(\d+)">([A-Za-z0-9;&]+)(:[A-Za-z0-9;&\-#,<>=]+)?<\/a>/g;
const aliasRegex = /([A-Za-z0-9;&]+)(:[A-Za-z0-9;&\-#,<>=]+)?/g;

const tabs: Tab[] = [];
const aliases = tabAliases();

let match;
let aliasMatch;

while ((match = tabRegex.exec(inventory)) !== null) {
const title = match[2];
const options = match[3];
const alias = aliases.get(title);
const id = parseInt(match[1]);

if (isTabTitle(title)) {
tabs.push({
title,
id,
options: (options ?? ":").substring(1).split(","),
type: "inventory",
});
} else if (alias && (aliasMatch = aliasRegex.exec(alias))) {
const aliasTitle = aliasMatch[1];
const options = aliasMatch[2];
if (isTabTitle(aliasTitle)) {
tabs.push({
title: aliasTitle,
id: parseInt(match[1]),
options: (options ?? ":").substring(1).split(","),
type: "inventory",
alias: title,
});
}
}
}

return tabs;
}

function tabString(tab: Tab): string {
const options = Options.parse(tab.options);
const title = tab.alias ? `${tab.title} (alias ${tab.alias})` : tab.title;
Expand Down
13 changes: 9 additions & 4 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ function parseCoinmasters(): Map<Item, [Coinmaster, Item]> {
const coin = toItem(toInt(r[1]));
const item = toItem(toInt(r[2]));
const coinmaster = Coinmaster.all().find((c) => c.item === coin && sellsItem(c, item));
if (isCoinmasterItem(item) && coinmaster) {
return [coin, [coinmaster, item]];
} else {
warn(`${item} is not a coinmaster item`);
if (!isCoinmasterItem(item)) {
warn(
`KoLmafia doesn't believe it can purchase ${item} (${r[2]}) with currency. Maybe you need to update?`
);
return [Item.none, [Coinmaster.none, Item.none]];
} else if (!coinmaster) {
warn(`${item} (${r[2]}) can't be bought with ${coin} (${r[1]})`);
return [Item.none, [Coinmaster.none, Item.none]];
} else {
return [coin, [coinmaster, item]];
}
});

Expand Down

0 comments on commit aa82c5e

Please sign in to comment.