Skip to content

Commit

Permalink
fix: Sync to new Dice Roller API
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Apr 23, 2024
1 parent 447f8ab commit 672dc8b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 54 deletions.
18 changes: 9 additions & 9 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 @@ -18,7 +18,7 @@
"@codemirror/language": "^6.6.0",
"@codemirror/search": "^6.2.3",
"@codemirror/view": "^6.9.1",
"@javalent/dice-roller": "^10.5.3",
"@javalent/dice-roller": "^10.5.7",
"@javalent/utilities": "^1.1.5",
"@lezer/common": "^1.0.2",
"@lezer/highlight": "^1.1.3",
Expand Down
44 changes: 15 additions & 29 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,15 @@ export default class StatBlockPlugin extends Plugin {

getRoller(str: string) {
if (!this.canUseDiceRoller) return;
const roller = this.app.plugins
.getPlugin("obsidian-dice-roller")
?.api.getRollerSync(str, DICE_ROLLER_SOURCE);
const roller = window.DiceRoller.getRollerSync(str, DICE_ROLLER_SOURCE);
return roller;
}
getRollerString(str: string) {
if (!this.canUseDiceRoller) return str;
return this.app.plugins
.getPlugin("obsidian-dice-roller")
?.api.getRollerString(str, DICE_ROLLER_SOURCE);
return window.DiceRoller.getRollerString(str, DICE_ROLLER_SOURCE);
}
get diceRollerInstalled() {
if (this.app.plugins.getPlugin("obsidian-dice-roller") != null) {
if (!this.app.plugins.getPlugin("obsidian-dice-roller").api) {
new Notice(
"Please update Dice Roller to the latest version to use with Fantasy Statblocks."
);
return false;
}
if (window.DiceRoller != null) {
return true;
}
return false;
Expand Down Expand Up @@ -222,29 +212,25 @@ export default class StatBlockPlugin extends Plugin {
(leaf: WorkspaceLeaf) => new CreatureView(leaf, this)
);
if (this.canUseDiceRoller) {
this.app.plugins
.getPlugin("obsidian-dice-roller")
?.api.registerSource(DICE_ROLLER_SOURCE, {
window.DiceRoller.registerSource(DICE_ROLLER_SOURCE, {
showDice: true,
shouldRender: this.settings.renderDice,
showFormula: false,
showParens: false,
expectedValue: ExpectedValue.Average,
text: null
});
}
this.registerEvent(
this.app.workspace.on("dice-roller:loaded", () => {
window.DiceRoller.registerSource(DICE_ROLLER_SOURCE, {
showDice: true,
shouldRender: this.settings.renderDice,
showFormula: false,
showParens: false,
expectedValue: ExpectedValue.Average,
text: null
});
}
this.registerEvent(
this.app.workspace.on("dice-roller:loaded", () => {
this.app.plugins
.getPlugin("obsidian-dice-roller")
?.api.registerSource(DICE_ROLLER_SOURCE, {
showDice: true,
shouldRender: this.settings.renderDice,
showFormula: false,
showParens: false,
expectedValue: ExpectedValue.Average,
text: null
});
})
);
}
Expand Down
20 changes: 8 additions & 12 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
App,
ButtonComponent,
debounce,
Modal,
normalizePath,
Notice,
PluginSettingTab,
prepareSimpleSearch,
setIcon,
Setting,
TFolder
} from "obsidian";
Expand All @@ -18,19 +14,18 @@ import LayoutEditor from "./layout/LayoutEditor.svelte";
import fastCopy from "fast-copy";

import Importer from "src/importers/importer";
import { EditMonsterModal, ViewMonsterModal } from "./modal";
import { EditMonsterModal } from "./modal";
import { Layout5e } from "src/layouts/basic 5e/basic5e";
import type { DefaultLayout, Layout } from "src/layouts/layout.types";
import { DefaultLayouts } from "src/layouts";
import { nanoid, stringify } from "src/util/util";
import { nanoid } from "src/util/util";
import { DICE_ROLLER_SOURCE } from "src/main";
import type { Monster } from "index";
import { ExpectedValue } from "obsidian-overload";
import FantasyStatblockModal from "src/modal/modal";
import { FolderInputSuggest } from "@javalent/utilities";
import { Watcher } from "src/watcher/watcher";
import { Bestiary } from "src/bestiary/bestiary";
import Creatures from "./creatures/Creatures.svelte";
import { ExpectedValue } from "@javalent/dice-roller";

export default class StatblockSettingTab extends PluginSettingTab {
importer: Importer;
Expand Down Expand Up @@ -179,17 +174,18 @@ export default class StatblockSettingTab extends PluginSettingTab {
.onChange(async (v) => {
this.plugin.settings.renderDice = v;
if (this.plugin.diceRollerInstalled) {
this.app.plugins
.getPlugin("obsidian-dice-roller")
?.api.registerSource(DICE_ROLLER_SOURCE, {
window.DiceRoller.registerSource(
DICE_ROLLER_SOURCE,
{
showDice: true,
shouldRender:
this.plugin.settings.renderDice,
showFormula: false,
showParens: false,
expectedValue: ExpectedValue.Average,
text: null
});
}
);
}
await this.plugin.saveSettings();
})
Expand Down
3 changes: 0 additions & 3 deletions src/typings/obsidian-extended.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import "obsidian";

interface StatblockEvents {
"dice-roller:rendered-result": number;
"dice-roller:unload": null;
"dice-roller:loaded": null;
"fantasy-statblocks:settings-change": StatblockData;
"fantasy-statblocks:frontmatter-change": boolean;
"fantasy-statblocks:srd-change": boolean;
Expand Down

0 comments on commit 672dc8b

Please sign in to comment.