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

View file

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

View file

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

View file

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

View file

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

View file

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