Skip to content

Commit

Permalink
Merge branch 'master' into 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Nov 24, 2021
2 parents 5723b38 + d1849ad commit 2534ed1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
14 changes: 7 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import typescript from "@rollup/plugin-typescript";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import css from "rollup-plugin-css-only";
const typescript = require( "@rollup/plugin-typescript");
const { nodeResolve } = require( "@rollup/plugin-node-resolve");
const commonjs = require( "@rollup/plugin-commonjs");
const css = require( "rollup-plugin-css-only");

import svelte from "rollup-plugin-svelte";
import process from "svelte-preprocess";
const svelte = require( "rollup-plugin-svelte");
const process = require( "svelte-preprocess");

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP
if you want to view the source visit the plugins github repository
*/
`;

export default {
module.exports = {
input: "./src/main.ts",
output: {
dir: ".",
Expand Down
69 changes: 56 additions & 13 deletions src/importers/5eToolsImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ async function buildMonsterFromFile(file: File): Promise<Monster> {

resolve(importedMonster);
} catch (e) {
reject();
console.error(e);
reject(e);
}
};

Expand Down Expand Up @@ -156,20 +157,62 @@ const spellMap: { [key: string]: string } = {
function getSpells(monster: any): any[] {
if (!monster.spellcasting || !monster.spellcasting.length) return [];

return [
monster.spellcasting[0].headerEntries.join("\n"),
...Object.entries(monster.spellcasting[0].spells).map(
([level, { slots, spells }]) => {
let name = `${spellMap[level]}`;
name += slots != undefined ? ` (${slots} slots)` : "";
const spells = monster.spellcasting[0].spells ?? {};
const will = monster.spellcasting[0].will ?? [];
const daily = monster.spellcasting[0].daily ?? {};

const sp = spells
const ret = [(monster.spellcasting[0].headerEntries ?? []).join("\n")];

if (spells) {
try {
ret.push(
...Object.entries(spells).map(
([level, { slots, spells }]) => {
let name = `${spellMap[level]}`;
name += slots != undefined ? ` (${slots} slots)` : "";

const sp = spells
.join(", ")
.replace(/\{@spell ([\s\S]+?)\}/g, `$1`);
return { [name]: sp };
}
)
);
} catch (e) {
throw new Error("There was an error parsing the spells.");
}
}
if (will) {
try {
ret.push({
"At will": will
.join(", ")
.replace(/\{@spell ([\s\S]+?)\}/g, `$1`);
return { [name]: sp };
}
)
];
.replace(/\{@spell ([\s\S]+?)\}/g, `$1`)
})
} catch(e) {
throw new Error("There was an error parsing the at-will spells.")
}
}
if (daily) {
try {
ret.push(
...Object.entries(daily).map(
([num, spells]) => {
let name = `Daily (${num})`;

const sp = spells
.join(", ")
.replace(/\{@spell ([\s\S]+?)\}/g, `$1`);
return { [name]: sp };
}
)
);
} catch (e) {
throw new Error("There was an error parsing the daily spells.");
}
}

return ret;
}

function getAlignmentString(alignment: any) {
Expand Down
1 change: 1 addition & 0 deletions src/importers/DnDAppFilesImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async function buildMonsterFromFile(file: File): Promise<Map<string, Monster>> {
};
importedMonsters.set(importedMonster.name, importedMonster);
} catch (e) {
console.error(e);
continue;
}
}
Expand Down

0 comments on commit 2534ed1

Please sign in to comment.