Migration vers datamodels
This commit is contained in:
@@ -1,77 +1,80 @@
|
||||
import { EcrymeUtility } from "../common/ecryme-utility.js";
|
||||
import { EcrymeConfrontDialog } from "./ecryme-confront-dialog.js";
|
||||
|
||||
export class EcrymeConfrontStartDialog extends Dialog {
|
||||
const { HandlebarsApplicationMixin } = foundry.applications.api
|
||||
|
||||
/**
|
||||
* Confrontation start dialog — Application V2 version.
|
||||
* Player picks which dice formula to roll (normal / spleen / ideal),
|
||||
* the dice are rolled and the main EcrymeConfrontDialog is opened.
|
||||
*/
|
||||
export class EcrymeConfrontStartDialog extends HandlebarsApplicationMixin(foundry.applications.api.ApplicationV2) {
|
||||
|
||||
/** @override */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["fvtt-ecryme", "ecryme-confront-start-dialog"],
|
||||
position: { width: 540 },
|
||||
window: { title: "ECRY.ui.confront" },
|
||||
actions: {
|
||||
rollNormal: EcrymeConfrontStartDialog.#onRollNormal,
|
||||
rollSpleen: EcrymeConfrontStartDialog.#onRollSpleen,
|
||||
rollIdeal: EcrymeConfrontStartDialog.#onRollIdeal,
|
||||
cancel: EcrymeConfrontStartDialog.#onCancel,
|
||||
},
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
content: { template: "systems/fvtt-ecryme/templates/dialogs/confront-start-dialog.hbs" },
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(actor, rollData, options = {}) {
|
||||
super(options)
|
||||
this.actor = actor?.token?.actor ?? actor
|
||||
this.rollData = rollData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async create(actor, rollData) {
|
||||
if (!actor) throw new Error("Ecryme | No actor provided for confront dialog");
|
||||
if (!rollData) throw new Error("Ecryme | No roll data provided for confront dialog");
|
||||
|
||||
if (actor?.token) rollData.tokenId = actor.token.id;
|
||||
let options = { classes: ["fvtt-ecryme ecryme-confront-dialog"], width: 540, height: 'fit-content', 'z-index': 99999 }
|
||||
let html = await foundry.applications.handlebars.renderTemplate('systems/fvtt-ecryme/templates/dialogs/confront-start-dialog.hbs', rollData);
|
||||
return new EcrymeConfrontStartDialog(actor, rollData, html, options);
|
||||
if (!actor) throw new Error("Ecryme | No actor provided for confront dialog")
|
||||
if (!rollData) throw new Error("Ecryme | No roll data provided for confront dialog")
|
||||
if (actor?.token) rollData.tokenId = actor.token.id
|
||||
return new EcrymeConfrontStartDialog(actor, rollData)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(actor, rollData, html, options, close = undefined) {
|
||||
let conf = {
|
||||
title: game.i18n.localize("ECRY.ui.confront"),
|
||||
content: html,
|
||||
buttons: {
|
||||
rollNormal: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: game.i18n.localize("ECRY.ui.rollnormal"),
|
||||
callback: () => { this.rollConfront("4d6") }
|
||||
},
|
||||
rollSpleen: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: game.i18n.localize("ECRY.ui.rollspleen"),
|
||||
callback: () => { this.rollConfront("5d6kl4") }
|
||||
},
|
||||
rollIdeal: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: game.i18n.localize("ECRY.ui.rollideal"),
|
||||
callback: () => { this.rollConfront("5d6kh4") }
|
||||
},
|
||||
cancel: {
|
||||
icon: '<i class="fas fa-times"></i>',
|
||||
label: game.i18n.localize("ECRY.ui.cancel"),
|
||||
callback: () => { this.close() }
|
||||
}
|
||||
},
|
||||
close: close
|
||||
async _prepareContext() {
|
||||
return {
|
||||
...this.rollData,
|
||||
config: game.system.ecryme.config,
|
||||
}
|
||||
|
||||
super(conf, options);
|
||||
|
||||
this.actor = actor?.token?.actor || actor;
|
||||
this.rollData = rollData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollConfront(diceFormula) {
|
||||
// Do the initial roll
|
||||
let myRoll = await new Roll(diceFormula).roll()
|
||||
async #rollConfront(diceFormula) {
|
||||
const myRoll = await new Roll(diceFormula).roll()
|
||||
await EcrymeUtility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
||||
// Fill the available dice table
|
||||
let rollData = this.rollData
|
||||
|
||||
const rollData = this.rollData
|
||||
rollData.roll = foundry.utils.duplicate(myRoll)
|
||||
rollData.availableDices = []
|
||||
for (let result of myRoll.terms[0].results) {
|
||||
for (const result of myRoll.terms[0].results) {
|
||||
if (!result.discarded) {
|
||||
let resultDup = foundry.utils.duplicate(result)
|
||||
resultDup.location = "mainpool"
|
||||
rollData.availableDices.push(resultDup)
|
||||
const dup = foundry.utils.duplicate(result)
|
||||
dup.location = "mainpool"
|
||||
rollData.availableDices.push(dup)
|
||||
}
|
||||
}
|
||||
let confrontDialog = await EcrymeConfrontDialog.create(this.actor, rollData)
|
||||
|
||||
const confrontDialog = await EcrymeConfrontDialog.create(this.actor, rollData)
|
||||
confrontDialog.render(true)
|
||||
this.close()
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
}
|
||||
}
|
||||
static async #onRollNormal(event, target) { await this.#rollConfront("4d6") }
|
||||
static async #onRollSpleen(event, target) { await this.#rollConfront("5d6kl4") }
|
||||
static async #onRollIdeal(event, target) { await this.#rollConfront("5d6kh4") }
|
||||
static #onCancel(event, target) { this.close() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user