Skip to content

Commit

Permalink
feat: Can now disable Notice for graphical rolls
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Nov 1, 2023
1 parent 0f2c599 commit 8e901b6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,6 +173,8 @@ interface DiceRollerSettings {
initialDisplay: ExpectedValue;

icons: DiceIcon[];

showRenderNotice: boolean;
}

export const DEFAULT_SETTINGS: DiceRollerSettings = {
Expand Down Expand Up @@ -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 {
Expand All @@ -225,13 +232,16 @@ export default class DiceRollerPlugin extends Plugin {
persistingFiles: Set<string> = new Set();
renderer: DiceRenderer;

existingDice: WeakSet<StackRoller> = 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() {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/roller/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ export class StackRoller extends GenericRoller<number> {
expectedValue: ExpectedValue;
round: Round;
signed: boolean;
showRenderNotice: boolean;
get replacer() {
return `${this.result}`;
}
Expand Down Expand Up @@ -1399,7 +1400,10 @@ export class StackRoller extends GenericRoller<number> {
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}`);
}

Expand Down
22 changes: 22 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8e901b6

Please sign in to comment.