From 8e901b6a813d75a3942a62c6591c6e68d96e8616 Mon Sep 17 00:00:00 2001 From: Jeremy Valentine <38669521+valentine195@users.noreply.github.com> Date: Tue, 31 Oct 2023 20:02:24 -0400 Subject: [PATCH] feat: Can now disable Notice for graphical rolls --- src/main.ts | 18 ++++++++++++++++-- src/roller/dice.ts | 6 +++++- src/settings/settings.ts | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index c95ebee..dab9afa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -113,6 +113,10 @@ declare module "obsidian" { name: "dice-roller:rendered-result", callback: (result: number) => void ): EventRef; + on( + name: "dice-roller:settings-change", + callback: (data: DiceRollerSettings) => void + ): EventRef; } interface MetadataCache { on(name: "dataview:api-ready", callback: () => void): EventRef; @@ -169,6 +173,8 @@ interface DiceRollerSettings { initialDisplay: ExpectedValue; icons: DiceIcon[]; + + showRenderNotice: boolean; } export const DEFAULT_SETTINGS: DiceRollerSettings = { @@ -200,7 +206,8 @@ export const DEFAULT_SETTINGS: DiceRollerSettings = { displayAsEmbed: true, round: Round.None, initialDisplay: ExpectedValue.Roll, - icons: copy(DEFAULT_ICONS) + icons: copy(DEFAULT_ICONS), + showRenderNotice: true }; export default class DiceRollerPlugin extends Plugin { @@ -225,13 +232,16 @@ export default class DiceRollerPlugin extends Plugin { persistingFiles: Set = new Set(); renderer: DiceRenderer; + existingDice: WeakSet = new WeakSet(); + getRendererData(): RendererData { return { diceColor: this.data.diceColor, textColor: this.data.textColor, colorfulDice: this.data.colorfulDice, scaler: this.data.scaler, - renderTime: this.data.renderTime + renderTime: this.data.renderTime, + textFont: this.data.textFont }; } async onload() { @@ -927,6 +937,8 @@ export default class DiceRollerPlugin extends Plugin { ); roller.showFormula = showFormula; roller.shouldRender = shouldRender; + roller.showRenderNotice = this.data.showRenderNotice; + this.existingDice.add(roller); return roller; } case "table": { @@ -1026,6 +1038,8 @@ export default class DiceRollerPlugin extends Plugin { ); roller.shouldRender = shouldRender; roller.showFormula = showFormula; + roller.showRenderNotice = this.data.showRenderNotice; + this.existingDice.add(roller); return roller; } case "table": { diff --git a/src/roller/dice.ts b/src/roller/dice.ts index fe9c690..53e532a 100644 --- a/src/roller/dice.ts +++ b/src/roller/dice.ts @@ -972,6 +972,7 @@ export class StackRoller extends GenericRoller { expectedValue: ExpectedValue; round: Round; signed: boolean; + showRenderNotice: boolean; get replacer() { return `${this.result}`; } @@ -1399,7 +1400,10 @@ export class StackRoller extends GenericRoller { this.calculate(); this.render(); - if (render || (this.shouldRender && this.hasRunOnce)) { + if ( + this.showRenderNotice && + (render || (this.shouldRender && this.hasRunOnce)) + ) { new Notice(`${this.tooltip}\n\nResult: ${this.result}`); } diff --git a/src/settings/settings.ts b/src/settings/settings.ts index a2e9b73..dd4d352 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -640,6 +640,28 @@ export default class SettingTab extends PluginSettingTab { }; } ); + + new Setting(containerEl) + .setName("Show Notice for Results") + .setDesc( + createFragment((e) => { + e.createSpan({ + text: "A notice will be displayed for each rendered dice roll." + }); + e.createEl("br"); + e.createSpan({ + text: "Changing this setting will not effect any existing dice rollers in opened notes." + }); + }) + ) + .addToggle((t) => { + t.setValue(this.plugin.data.showRenderNotice).onChange( + async (v) => { + this.plugin.data.showRenderNotice = v; + await this.plugin.saveSettings(); + } + ); + }); } buildFormulaSettings(containerEl: HTMLDetailsElement) {