Skip to content

Commit

Permalink
Update renderer to allow inclusion of SRD monsters
Browse files Browse the repository at this point in the history
  • Loading branch information
ben committed Jan 7, 2022
1 parent 12975fa commit 9268e64
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 17 deletions.
2 changes: 1 addition & 1 deletion import-from-archmage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function doit() {
pd: parsed.data.attributes.pd.value,
md: parsed.data.attributes.md.value,
hp: parsed.data.attributes.hp.value,
initiative: parsed.data.attributes.init.modifier,
initiative: parsed.data.attributes.init.mod,
attacks: [] as any[],
traits: [] as any[],
specials: [] as any[],
Expand Down
29 changes: 20 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import {
} from "obsidian";
import { StatblockRenderer } from "statblockrenderer";

// Remember to rename these classes and interfaces!
const srdData = require('monsters.json')
console.log(srdData)

interface ArchmageSettings {


interface MyPluginSettings {
mySetting: string;
}

const DEFAULT_SETTINGS: MyPluginSettings = {
const DEFAULT_SETTINGS: ArchmageSettings = {
mySetting: "default",
};

export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
export default class ArchmagePlugin extends Plugin {
settings: ArchmageSettings;

async onload() {
await this.loadSettings();
Expand All @@ -39,8 +42,16 @@ export default class MyPlugin extends Plugin {
ctx: MarkdownPostProcessorContext
): Promise<any> {
const yaml = parseYaml(source);
console.log(yaml);
ctx.addChild(new StatblockRenderer(el, yaml));
let renderData = {...yaml}

if (yaml.monster) {
const lookupMonster = srdData.find(x => x.name === yaml.monster)
if (lookupMonster) {
renderData = {...lookupMonster, ...yaml}
}
}

ctx.addChild(new StatblockRenderer(el, renderData));
}

onunload() {}
Expand All @@ -59,9 +70,9 @@ export default class MyPlugin extends Plugin {
}

class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
plugin: ArchmagePlugin;

constructor(app: App, plugin: MyPlugin) {
constructor(app: App, plugin: ArchmagePlugin) {
super(app, plugin);
this.plugin = plugin;
}
Expand Down
Loading

0 comments on commit 9268e64

Please sign in to comment.