Skip to content

Commit

Permalink
feat: Adds ability to open note-based creatures directly from the bes…
Browse files Browse the repository at this point in the history
…tiary in settings
  • Loading branch information
valentine195 committed Mar 7, 2024
1 parent 7b3da4c commit 4669df8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface Monster {
forceColumns?: boolean;

note?: string;
path?: string;
mtime?: number;

/* Extensions */
Expand Down
2 changes: 1 addition & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { Component } from "obsidian";
import type { HomebrewCreature } from "obsidian-overload";
import { Bestiary } from "src/bestiary/bestiary";
import type StatBlockPlugin from "src/main";
import { buildLoader } from "src/util";
import StatBlockRenderer from "src/view/statblock";

declare global {
interface Window {
FantasyStatblocks: API;
Expand Down
29 changes: 21 additions & 8 deletions src/settings/creatures/Creature.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import { Bestiary } from "src/bestiary/bestiary";
import { getContext } from "../layout/context";
import { NameFilter } from "./filters/filters";
import { createEventDispatcher } from "svelte";
export let item: Monster;
const dispatch = createEventDispatcher<{ close: void }>();
const plugin = getContext("plugin");
let content: Setting;
const buildSetting = (node: HTMLElement) => {
Expand All @@ -33,14 +35,7 @@
stringify(item.source, 0, ", ", false)
);
}
content.addExtraButton((b) => {
b.setIcon("info")
.setTooltip("View")
.onClick(() => {
const modal = new ViewMonsterModal(plugin, item as Monster);
modal.open();
});
});
if (Bestiary.isLocal(item.name)) {
content
.addExtraButton((b) => {
Expand All @@ -58,7 +53,25 @@
await plugin.deleteMonster(item.name);
});
});
} else if (item.path) {
const file = plugin.app.vault.getFileByPath(item.path);
if (!file) return;
content.addExtraButton((b) => {
b.setIcon("file-symlink").onClick(async () => {
const leaf = plugin.app.workspace.getLeaf();
await leaf.openFile(file);
plugin.app.setting.close();
});
});
}
content.addExtraButton((b) => {
b.setIcon("info")
.setTooltip("View")
.onClick(() => {
const modal = new ViewMonsterModal(plugin, item as Monster);
modal.open();
});
});
};
$: {
Expand Down
2 changes: 1 addition & 1 deletion src/settings/creatures/Creatures.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</div>
<div class="creatures-container">
{#each $sliced as item (item.name)}
<Creature {item} />
<Creature {item} on:close />
{/each}
</div>
<div class="pagination-container">
Expand Down
11 changes: 10 additions & 1 deletion src/typings/obsidian-extended.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ declare module "obsidian" {
listCommands: () => Command[];
executeCommandById: (id: string) => boolean;
};
setting: {
close: () => void;
};
}
interface MetadataCache {
initialized: boolean;
Expand All @@ -32,6 +35,12 @@ declare module "obsidian" {
name: T,
data: StatblockEvents[T]
): void;
trigger(name: "link-hover", popover: object, target: HTMLElement, link: string, source: string);
trigger(
name: "link-hover",
popover: object,
target: HTMLElement,
link: string,
source: string
);
}
}
1 change: 1 addition & 0 deletions src/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class WatcherClass extends Component {
let { monster, path } = evt.data.data;

let update = Bestiary.hasCreature(monster.name);
monster.path = path;

Bestiary.addEphemeralCreature(monster);

Expand Down

0 comments on commit 4669df8

Please sign in to comment.