Fix submit on close

This commit is contained in:
Dapoolp 2025-06-22 23:43:48 +02:00
parent 6223b05eb1
commit 0d60cd90b6
6 changed files with 27 additions and 6 deletions

View file

@ -13,6 +13,7 @@ export class DHRoll extends Roll {
static async build(config={}, message={}) {
const roll = await this.buildConfigure(config, message);
if(!roll) return;
await this.buildEvaluate(roll, config, message={});
await this.buildPost(roll, config, message={});
return roll;
@ -35,14 +36,13 @@ export class DHRoll extends Roll {
// Open Roll Dialog
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
config = await DialogClass.configure(config, message);
if(!config) return;
}
console.log(config)
let roll = new this(config.formula, config.actor, config);
for ( const hook of config.hooks ) {
if ( Hooks.call(`${SYSTEM.id}.post${hook.capitalize()}RollConfiguration`, roll, config, message) === false ) return [];
}
console.log(roll);
return roll;
}

View file

@ -220,6 +220,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
// Proceed with Roll
config = await this.proceedRoll(config);
if(!config) return;
// Update Actor resources based on Action Cost configuration
this.spendCost(config.costs.values);

View file

@ -22,7 +22,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
actions: {
updateIsAdvantage: this.updateIsAdvantage,
selectExperience: this.selectExperience,
// finish: this.finish
submitRoll: this.submitRoll
},
form: {
handler: this.updateRollConfiguration,
@ -80,6 +80,15 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.render();
}
static async submitRoll() {
await this.close({ submitted: true });
}
/** @override */
_onClose(options={}) {
if ( !options.submitted ) this.config = false;
}
static async configure(config={}) {
return new Promise(resolve => {
const app = new this(config);

View file

@ -15,7 +15,9 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
width: 400,
height: 'auto'
},
actions: {},
actions: {
submitRoll: this.submitRoll
},
form: {
handler: this.updateRollConfiguration,
submitOnChange: true,
@ -38,6 +40,15 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application
return context;
}
static async submitRoll() {
await this.close({ submitted: true });
}
/** @override */
_onClose(options={}) {
if ( !options.submitted ) this.config = false;
}
static async configure(config={}) {
return new Promise(resolve => {
const app = new this(config);

View file

@ -24,6 +24,6 @@
</div>
{{/each}} --}}
<footer>
<button data-action="close">Roll</button>
<button data-action="submitRoll">Roll</button>
</footer>
</div>

View file

@ -35,7 +35,7 @@
{{!-- {{/if}} --}}
</div>
<footer>
<button data-action="close"{{#unless canRoll}} disabled{{/unless}}>Roll</button>
<button data-action="submitRoll"{{#unless canRoll}} disabled{{/unless}}>Roll</button>
</footer>
</div>
</div>