Skip to content

Commit

Permalink
1.5.2
Browse files Browse the repository at this point in the history
- Added try/catch handlers to imports to handle errors
  • Loading branch information
valentine195 committed Aug 3, 2021
1 parent b47fb09 commit 9fe1af7
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 176 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-5e-statblocks",
"name": "5e Statblocks",
"version": "1.5.1",
"version": "1.5.2",
"description": "Create 5e styled statblocks in Obsidian.md",
"minAppVersion": "0.12.0",
"author": "Jeremy Valentine",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-5e-statblocks",
"version": "1.5.1",
"version": "1.5.2",
"description": "Create 5e styled statblocks in Obsidian.md",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/importers/5eToolsImport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Monster } from "@types";
import { Notice } from "obsidian";

export const ImportFrom5eTools = async (
...files: File[]
Expand All @@ -8,7 +9,10 @@ export const ImportFrom5eTools = async (
try {
const monster = await buildMonsterFromFile(file);
importedMonsters.set(monster.name, monster);
} catch (e) {}
} catch (e) {
new Notice("There was an issue importing the monster.");
console.error(e);
}
}
return importedMonsters;
};
Expand Down
280 changes: 146 additions & 134 deletions src/importers/CritterDBImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,142 +28,154 @@ async function buildMonsterFromFile(file: File): Promise<Map<string, Monster>> {
monsters = [parsed];
}
for (let monster of monsters) {
const importedMonster: Monster = {
name: monster.name,
source: "CritterDB",
type: monster.stats.race,
subtype: "",
size: monster.stats.size,
alignment: monster.stats.alignment,
hp: monster.stats.hitPoints,
hit_dice: `${Math.floor(
monster.stats.extraHealthFromConstitution /
monster.stats.abilityScoreModifiers.constitution
)}d${monster.stats.hitDieSize} + ${
monster.stats.extraHealthFromConstitution
}`,
ac: monster.stats.armorClass,
speed: monster.stats.speed,
stats: [
monster.stats.abilityScores.strength,
monster.stats.abilityScores.dexterity,
monster.stats.abilityScores.constitution,
monster.stats.abilityScores.intelligence,
monster.stats.abilityScores.wisdom,
monster.stats.abilityScores.charisma
],
damage_immunities:
monster.stats.damageImmunities
?.join("; ")
.toLowerCase()
.trim() ?? "",
damage_resistances:
monster.stats.damageResistances
?.join(", ")
.toLowerCase()
.trim() ?? "",
damage_vulnerabilities:
monster.stats.damageVulnerabilities
?.join(", ")
.toLowerCase()
.trim() ?? "",
condition_immunities:
monster.stats.conditionImmunities
?.join(", ")
.toLowerCase()
.trim() ?? "",
saves:
monster.stats.savingThrows
?.map((thr: any) => {
if (
!("value" in thr) &&
!("modifier" in thr)
)
return;
return {
[thr.ability]: thr.value ?? thr.modifier
};
})
.filter((x: any) => x) ?? [],
skillsaves:
monster.stats.skills
?.map((thr: any) => {
if (
!("value" in thr) &&
!("modifier" in thr)
)
return;
return {
[thr.name]: thr.value ?? thr.modifier
};
})
.filter((x: any) => x) ?? [],
senses: monster.stats.senses?.join(", ").trim() ?? "",
languages:
monster.stats.languages?.join(", ").trim() ?? "",
cr: monster.stats.challengeRating ?? "",
traits:
monster.stats.additionalAbilities?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
try {
const importedMonster: Monster = {
name: monster.name,
source: "CritterDB",
type: monster.stats.race,
subtype: "",
size: monster.stats.size,
alignment: monster.stats.alignment,
hp: monster.stats.hitPoints,
hit_dice: `${Math.floor(
monster.stats.extraHealthFromConstitution /
monster.stats.abilityScoreModifiers
.constitution
)}d${monster.stats.hitDieSize} + ${
monster.stats.extraHealthFromConstitution
}`,
ac: monster.stats.armorClass,
speed: monster.stats.speed,
stats: [
monster.stats.abilityScores.strength,
monster.stats.abilityScores.dexterity,
monster.stats.abilityScores.constitution,
monster.stats.abilityScores.intelligence,
monster.stats.abilityScores.wisdom,
monster.stats.abilityScores.charisma
],
damage_immunities:
monster.stats.damageImmunities
?.join("; ")
.toLowerCase()
.trim() ?? "",
damage_resistances:
monster.stats.damageResistances
?.join(", ")
.toLowerCase()
.trim() ?? "",
damage_vulnerabilities:
monster.stats.damageVulnerabilities
?.join(", ")
.toLowerCase()
.trim() ?? "",
condition_immunities:
monster.stats.conditionImmunities
?.join(", ")
.toLowerCase()
.trim() ?? "",
saves:
monster.stats.savingThrows
?.map((thr: any) => {
if (
!("value" in thr) &&
!("modifier" in thr)
)
};
}
) ?? [],
actions:
monster.stats.actions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
return;
return {
[thr.ability]:
thr.value ?? thr.modifier
};
})
.filter((x: any) => x) ?? [],
skillsaves:
monster.stats.skills
?.map((thr: any) => {
if (
!("value" in thr) &&
!("modifier" in thr)
)
};
}
) ?? [],
reactions:
monster.stats.reactions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? [],
legendary_actions:
monster.stats.legendaryActions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? []
};
importedMonsters.set(importedMonster.name, importedMonster);
return;
return {
[thr.name]:
thr.value ?? thr.modifier
};
})
.filter((x: any) => x) ?? [],
senses:
monster.stats.senses?.join(", ").trim() ?? "",
languages:
monster.stats.languages?.join(", ").trim() ??
"",
cr: monster.stats.challengeRating ?? "",
traits:
monster.stats.additionalAbilities?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? [],
actions:
monster.stats.actions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? [],
reactions:
monster.stats.reactions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? [],
legendary_actions:
monster.stats.legendaryActions?.map(
(trait: {
name: string;
description: string;
}) => {
return {
name: trait.name,
desc: trait.description.replace(
/<[^>]*>/g,
""
)
};
}
) ?? []
};
importedMonsters.set(
importedMonster.name,
importedMonster
);
} catch (e) {
continue;
}
}

resolve(importedMonsters);
Expand Down
Loading

0 comments on commit 9fe1af7

Please sign in to comment.