From 7333b54a3533b6b7032bce0d675adadbdb2b0d3a Mon Sep 17 00:00:00 2001 From: Ender Date: Sun, 24 Mar 2024 23:44:29 +0100 Subject: [PATCH] Anpassung Zauber und Kampftabs --- source/module/M5Base.ts | 1 + source/module/rolls/M5Roll.ts | 2 +- source/module/sheets/M5CharacterSheet.ts | 52 +++++++++++++++++++++++- templates/chat/task-check-dialog.hbs | 20 +++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 templates/chat/task-check-dialog.hbs diff --git a/source/module/M5Base.ts b/source/module/M5Base.ts index 586b84f..11b9a8c 100644 --- a/source/module/M5Base.ts +++ b/source/module/M5Base.ts @@ -180,6 +180,7 @@ export interface M5CharacterCalculatedData { pa: M5AttributeCalculated; wk: M5AttributeCalculated; }; + stats: { lp: M5ModResult; ap: M5ModResult; diff --git a/source/module/rolls/M5Roll.ts b/source/module/rolls/M5Roll.ts index 9a5f316..b3a67b3 100644 --- a/source/module/rolls/M5Roll.ts +++ b/source/module/rolls/M5Roll.ts @@ -314,7 +314,7 @@ export class M5Roll { return null; } } - + interface FormulaParseResult { sides: number; type: string; diff --git a/source/module/sheets/M5CharacterSheet.ts b/source/module/sheets/M5CharacterSheet.ts index 7cbc2ff..56bf187 100644 --- a/source/module/sheets/M5CharacterSheet.ts +++ b/source/module/sheets/M5CharacterSheet.ts @@ -77,7 +77,17 @@ export default class M5CharacterSheet extends ActorSheet { let target = event.target.closest("[data-attribute]") as HTMLElement; let attributeValue = target ? parseInt(target.dataset.value) : null; let attributeStr = target ? target.dataset.attribute : null; - + let hasFortune: boolean; + let taskType: string; + let useFortune: boolean; + let modifier: number; + let difficulty: number; + let closedRoll: boolean; + let checkOptions = await GetRollOptions({ hasFortune, taskType, useFortune, modifier, difficulty, closedRoll }); + console.log("Check Options", checkOptions); + if (checkOptions["cancelled"]) { + return; + } const roll = M5Roll.fromAttributeValue(this.actor, attributeStr, attributeValue); await roll.toMessage(); }); @@ -517,3 +527,43 @@ export default class M5CharacterSheet extends ActorSheet { return true; } } +async function GetRollOptions({ + hasFortune = true, + taskType = null, + useFortune = false, + difficulty = 0, + modifier = 0, + closedRoll = false, + template = "systems/midgard5/templates/chat/task-check-dialog.hbs" } = {}) { + const html = await renderTemplate(template, { hasFortune, useFortune, difficulty, modifier, closedRoll }); + + return new Promise(resolve => { + const data = { + title: (game as Game).i18n.format("midgard5.chat.taskCheck.title", { type: taskType }), + content: html, + buttons: { + normal: { + label: (game as Game).i18n.localize("midgard5.chat.actions.roll"), + callback: html => resolve(_processTaskCheckOptions(html[0].querySelector("form"))) + }, + cancel: { + label: (game as Game).i18n.localize("midgard5.chat.actions.cancel"), + callback: html => resolve({ cancelled: true }) + } + }, + default: "normal", + close: () => resolve({ cancelled: true }) + }; + + new Dialog(data, null).render(true); + }); + } + + function _processTaskCheckOptions(form) { + return { + difficulty: parseInt(form.difficulty?.value), + modifier: parseInt(form.modifier?.value), + useFortune: form.useFortune?.checked, + closedRoll: form.closedRoll?.checked + } + } diff --git a/templates/chat/task-check-dialog.hbs b/templates/chat/task-check-dialog.hbs new file mode 100644 index 0000000..74482ce --- /dev/null +++ b/templates/chat/task-check-dialog.hbs @@ -0,0 +1,20 @@ +
+
+ + +
+
+ + +
+ {{#if hasFortune}} +
+ + +
+ {{/if}} +
+ + +
+
\ No newline at end of file