Skip to content

Commit

Permalink
fix: YAML parsing respects monster key (close #191)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Apr 22, 2023
1 parent d8bf5a3 commit 78eaf40
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
13 changes: 7 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Component } from "obsidian";
import type { Creature, HomebrewCreature } from "obsidian-overload";
import type { DefaultLayout, Layout } from "types/layout";

export type ability =
Expand Down Expand Up @@ -105,11 +106,11 @@ export interface StatblockParameters
| "legendary_actions"
| "reactions"
> {
traits?: { desc: string; name: string }[] | [string, string][];
actions?: Trait[] | [string, string][];
bonus_actions?: Trait[] | [string, string][];
legendary_actions?: Trait[] | [string, string][];
reactions?: Trait[] | [string, string][];
traits?: { desc: string; name: string }[];
actions?: Trait[];
bonus_actions?: Trait[];
legendary_actions?: Trait[];
reactions?: Trait[];
}

export type Spell = string | { [key: string]: string };
Expand Down Expand Up @@ -153,7 +154,7 @@ export interface StatblockAPI {
statblockEl: HTMLDivElement,
display: string
): Component;
saveMonsters(homebrew: import(".").HomebrewCreature[]): unknown;
saveMonsters(homebrew: HomebrewCreature[]): unknown;
settings: StatblockData;
data: Map<string, Monster>;
}
80 changes: 63 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"fast-sort": "^3.0.2",
"jest": "^27.4.7",
"obsidian": "^0.16.0",
"obsidian-overload": "^1.7.0",
"obsidian-overload": "^1.15.1",
"standard-version": "^9.3.2",
"svelte": "^3.49.0",
"svelte-dnd-action": "^0.9.12",
Expand Down
2 changes: 1 addition & 1 deletion src/view/statblock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App, ButtonComponent, Modal, TFile } from "obsidian";
import { Layout5e } from "src/layouts/basic 5e/basic5e";
import { MarkdownRenderChild } from "obsidian";
import type { Monster, StatblockParameters, Trait } from "types";
import type { Monster, StatblockParameters, Trait } from "../../index";

import Statblock from "./Statblock.svelte";
import type StatBlockPlugin from "src/main";
Expand Down
13 changes: 12 additions & 1 deletion src/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Watcher extends Component {
"message",
async (evt: MessageEvent<UpdateEventMessage>) => {
if (evt.data.type == "update") {
const { monster, path } = evt.data;
let { monster, path } = evt.data;
let update = false;
if (this.watchPaths.has(path)) {
const existing = this.watchPaths.get(path);
Expand All @@ -124,6 +124,17 @@ export class Watcher extends Component {
`Fantasy Statblocks: Updating ${monster.name}`
);
}

if (
"monster" in monster &&
this.plugin.bestiary.has(monster.monster)
) {
monster = {
...this.plugin.bestiary.get(monster.monster),
...monster
};
}

this.watchPaths.set(path, monster.name);
await this.plugin.saveMonster(monster, false, false);

Expand Down

0 comments on commit 78eaf40

Please sign in to comment.