Implements DiceSoNice preview in config settings #710

This commit is contained in:
Chris Ryan 2025-08-09 17:35:35 +10:00
parent 3bd497bc21
commit fee3e38770
3 changed files with 35 additions and 9 deletions

View file

@ -1,4 +1,6 @@
import DhAppearance from '../../data/settings/Appearance.mjs'; import DhAppearance from '../../data/settings/Appearance.mjs';
import { getDiceSoNicePreset } from '../../config/generalConfig.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
@ -25,7 +27,8 @@ export default class DHAppearanceSettings extends HandlebarsApplicationMixin(App
}, },
actions: { actions: {
reset: this.reset, reset: this.reset,
save: this.save save: this.save,
preview: this.preview
}, },
form: { handler: this.updateData, submitOnChange: true } form: { handler: this.updateData, submitOnChange: true }
}; };
@ -89,6 +92,22 @@ export default class DHAppearanceSettings extends HandlebarsApplicationMixin(App
this.render(); this.render();
} }
static async preview() {
const source = this.settings._source.diceSoNice[this.tabGroups.diceSoNice];
let faces = 'd12';
switch (this.tabGroups.diceSoNice) {
case 'advantage':
case 'disadvantage':
faces = 'd6';
}
const preset = await getDiceSoNicePreset(source, faces);
const diceSoNiceRoll = await new Roll(`1${faces}`).evaluate();
diceSoNiceRoll.dice[0].options.appearance = preset.appearance;
diceSoNiceRoll.dice[0].options.modelFile = preset.modelFile;
await game.dice3d.showForRoll(diceSoNiceRoll, game.user, false);
}
static async reset() { static async reset() {
this.settings = new DhAppearance(); this.settings = new DhAppearance();
this.render(); this.render();

View file

@ -494,9 +494,7 @@ export const diceSetNumbers = {
flat: 'Flat' flat: 'Flat'
}; };
export const getDiceSoNicePresets = async (hopeFaces, fearFaces, advantageFaces = 'd6', disadvantageFaces = 'd6') => { export const getDiceSoNicePreset = async (type, faces) => {
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
const getPreset = async (type, faces) => {
const system = game.dice3d.DiceFactory.systems.get(type.system).dice.get(faces); const system = game.dice3d.DiceFactory.systems.get(type.system).dice.get(faces);
if (!system) { if (!system) {
ui.notifications.error( ui.notifications.error(
@ -523,11 +521,14 @@ export const getDiceSoNicePresets = async (hopeFaces, fearFaces, advantageFaces
}; };
}; };
export const getDiceSoNicePresets = async (hopeFaces, fearFaces, advantageFaces = 'd6', disadvantageFaces = 'd6') => {
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
return { return {
hope: await getPreset(diceSoNice.hope, hopeFaces), hope: await getDiceSoNicePreset(diceSoNice.hope, hopeFaces),
fear: await getPreset(diceSoNice.fear, fearFaces), fear: await getDiceSoNicePreset(diceSoNice.fear, fearFaces),
advantage: await getPreset(diceSoNice.advantage, advantageFaces), advantage: await getDiceSoNicePreset(diceSoNice.advantage, advantageFaces),
disadvantage: await getPreset(diceSoNice.disadvantage, disadvantageFaces) disadvantage: await getDiceSoNicePreset(diceSoNice.disadvantage, disadvantageFaces)
}; };
}; };

View file

@ -69,7 +69,13 @@
{{selectOptions diceSoNiceMaterials selected=diceTab.source.material valueAttr="key" labelAttr="name" localize=true}} {{selectOptions diceSoNiceMaterials selected=diceTab.source.material valueAttr="key" labelAttr="name" localize=true}}
</select> </select>
</div> </div>
</div> <div class="label-container">
<button data-action="preview">
<i class="fa-solid fa-dice right"></i>
<span>{{localize "Preview"}}</span>
</button>
</div>
</div>
</div> </div>
</fieldset> </fieldset>
{{/if}} {{/if}}