Skip to content

Commit

Permalink
fix: Fixes 5e.tools AC import not including additional AC info (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Mar 27, 2024
1 parent a4ba38a commit 6116540
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Monster {
type: string;
subtype: string;
alignment: string;
ac: number;
ac: string | number;
hp: number;
hit_dice?: string;
speed: string;
Expand Down
28 changes: 16 additions & 12 deletions src/importers/5eToolsImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const abilityMap: { [key: string]: string } = {
function parseString(str: string) {
if (!str) return "";
return str
.replace(/{@condition (.+?)}/g, "$1")
.replace(/{@item (.+?)}/g, "$1")
.replace(/{@spell ([\s\S]+?)}/g, `$1`)
.replace(/{@recharge (.+?)}/g, `(Recharge $1-6)`)
.replace(/{@condition (.+?)(?:\|.+)}/g, "$1")
.replace(/{@item (.+?)(?:\|.+)}/g, "$1")
.replace(/{@spell ([\s\S]+?)(?:\|.+)}/g, `$1`)
.replace(/{@recharge (.+?)(?:\|.+)}/g, `(Recharge $1-6)`)
.replace(/{@recharge}/g, `(Recharge 6)`)
.replace(/{@h}/g, ``)
.replace(/{@damage (.+?)}/g, `$1`)
Expand All @@ -39,12 +39,12 @@ function parseString(str: string) {
.replace(/{@atk mw}/g, `Melee Weapon Attack`)
.replace(/{@atk rw}/g, `Ranged Weapon Attack`)
.replace(/{@atk mw,rw}/g, `Melee / Ranged Weapon Attack`)
.replace(/{@creature (.+?)}/g, `$1`)
.replace(/{@skill (.+?)}/g, `$1`)
.replace(/{@dice (.+?)}/g, `$1`)
.replace(/{@hit (\d+?)}/g, `+$1`)
.replace(/{@dc (\d+?)}/g, `$1`)
.replace(/{@quickref (.+?)\|\|.+?}/, `$1`);
.replace(/{@creature (.+?)(?:\|.+)}/g, `$1`)
.replace(/{@skill (.+?)(?:\|.+)}/g, `$1`)
.replace(/{@dice (.+?)(?:\|.+)}/g, `$1`)
.replace(/{@hit (\d+?)(?:\|.+)}/g, `+$1`)
.replace(/{@dc (\d+?)(?:\|.+)}/g, `$1`)
.replace(/{@quickref (.+?)\|\|.+?(?:\|.+)}/, `$1`);
}

export async function build5eMonsterFromFile(file: File): Promise<Monster[]> {
Expand Down Expand Up @@ -279,9 +279,13 @@ function getAc(acField: Creature5eTools["ac"] = []) {
}
if (typeof item !== "object") return;
if ("special" in item) {
return null;
return item.special;
}
return item.ac;
if (!("ac" in item)) return null;
if ("from" in item) {
return `${item.ac} (${parseString(item.from.join(", "))})`;
}
return `${item.ac}`;
}

const spellMap: { [K in keyof EntrySpellcasting["spells"]]: string } = {
Expand Down

0 comments on commit 6116540

Please sign in to comment.