diff --git a/lang/en.json b/lang/en.json index 9b69c473..c0dc1c3c 100755 --- a/lang/en.json +++ b/lang/en.json @@ -390,9 +390,7 @@ }, "ResourceDice": { "title": "{name} Resource", - "rerollDice": "Reroll Dice", - "rerollRecoveryInfo": "{name} refresh on {recovery}.", - "rerollConfirmation": "Are you sure you want to reroll your {name} dice?" + "rerollDice": "Reroll Dice" } }, diff --git a/module/applications/dialogs/resourceDiceDialog.mjs b/module/applications/dialogs/resourceDiceDialog.mjs index 89a4e67b..122b7422 100644 --- a/module/applications/dialogs/resourceDiceDialog.mjs +++ b/module/applications/dialogs/resourceDiceDialog.mjs @@ -1,13 +1,14 @@ const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; export default class ResourceDiceDialog extends HandlebarsApplicationMixin(ApplicationV2) { - constructor(name, recovery, actorName, resource, options = {}) { + constructor(name, recovery, actor, resource, options = {}) { super(options); this.name = name; this.recovery = recovery; - this.actorName = actorName; + this.actor = actor; this.resource = resource; + this.diceStates = foundry.utils.deepClone(resource.diceStates); } static DEFAULT_OPTIONS = { @@ -17,7 +18,8 @@ export default class ResourceDiceDialog extends HandlebarsApplicationMixin(Appli icon: 'fa-solid fa-dice' }, actions: { - rerollDice: this.rerollDice + rerollDice: this.rerollDice, + save: this.save }, form: { handler: this.updateResourceDice, @@ -42,15 +44,35 @@ export default class ResourceDiceDialog extends HandlebarsApplicationMixin(Appli const context = await super._prepareContext(_options); context.name = this.name; context.recovery = game.i18n.localize(CONFIG.DH.GENERAL.refreshTypes[this.recovery].label); + context.resource = this.resource; + context.diceStates = this.diceStates; + context.actor = this.actor; return context; } + static async updateResourceDice(event, _, formData) { + const { diceStates } = foundry.utils.expandObject(formData.object); + this.diceStates = Object.keys(diceStates).reduce((acc, key) => { + const resourceState = this.resource.diceStates[key]; + acc[key] = { ...diceStates[key], used: Boolean(resourceState?.used) }; + return acc; + }, {}); + + this.render(); + } + + static async save() { + this.rollValues = Object.values(this.diceStates); + this.close(); + } + static async rerollDice() { const diceFormula = `${this.resource.max}d${this.resource.dieFaces}`; const roll = await new Roll(diceFormula).evaluate(); if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true); - this.rollValues = roll.terms[0].results.map(x => x.result); + this.rollValues = roll.terms[0].results.map(x => ({ value: x.result, used: false })); + this.resetUsed = true; const cls = getDocumentClass('ChatMessage'); const msg = new cls({ @@ -58,7 +80,7 @@ export default class ResourceDiceDialog extends HandlebarsApplicationMixin(Appli content: await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/ui/chat/resource-roll.hbs', { - user: this.actorName, + user: this.actor.name, name: this.name } ) @@ -68,9 +90,9 @@ export default class ResourceDiceDialog extends HandlebarsApplicationMixin(Appli this.close(); } - static async create(name, recovery, actorName, resource, options = {}) { + static async create(name, recovery, actor, resource, options = {}) { return new Promise(resolve => { - const app = new this(name, recovery, actorName, resource, options); + const app = new this(name, recovery, actor, resource, options); app.addEventListener('close', () => resolve(app.rollValues), { once: true }); app.render({ force: true }); }); diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index c551084f..b4f11cc5 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -700,14 +700,14 @@ export default class CharacterSheet extends DHBaseActorSheet { const rollValues = await game.system.api.applications.dialogs.ResourceDiceDialog.create( item.name, item.system.resource.recovery, - this.document.name, + this.document, item.system.resource ); if (!rollValues) return; await item.update({ - 'system.resource.diceStates': rollValues.reduce((acc, value, index) => { - acc[index] = { value, used: false }; + 'system.resource.diceStates': rollValues.reduce((acc, state, index) => { + acc[index] = { value: state.value, used: state.used }; return acc; }, {}) }); diff --git a/styles/less/dialog/resource-dice/sheet.less b/styles/less/dialog/resource-dice/sheet.less index 99353fe9..c359cad2 100644 --- a/styles/less/dialog/resource-dice/sheet.less +++ b/styles/less/dialog/resource-dice/sheet.less @@ -1,8 +1,44 @@ +.theme-light .daggerheart.dialog.dh-style.views.resource-dice { + .resource-items input { + background-image: url('../assets/parchments/dh-parchment-light.png'); + } +} + .daggerheart.dialog.dh-style.views.resource-dice { .reroll-confirmation { margin-bottom: 8px; } + .resource-items { + display: flex; + gap: 8px; + + .resource-item { + position: relative; + display: flex; + align-items: center; + justify-content: center; + + input { + position: absolute; + border-color: light-dark(@dark-blue, @golden); + color: light-dark(black, white); + background-image: url('../assets/parchments/dh-parchment-dark.png'); + z-index: 2; + line-height: 22px; + height: unset; + text-align: center; + } + + img { + width: 48px; + height: 48px; + filter: brightness(0) saturate(100%) invert(97%) sepia(7%) saturate(580%) hue-rotate(332deg) + brightness(96%) contrast(95%); + } + } + } + footer { display: flex; gap: 8px; diff --git a/templates/dialogs/dice-roll/resourceDice.hbs b/templates/dialogs/dice-roll/resourceDice.hbs index a054986b..2613f9fd 100644 --- a/templates/dialogs/dice-roll/resourceDice.hbs +++ b/templates/dialogs/dice-roll/resourceDice.hbs @@ -1,10 +1,21 @@