From 83574242f0ebea8564215efe63c4e83516362791 Mon Sep 17 00:00:00 2001 From: The Last Scrub Date: Sat, 28 Nov 2020 21:33:44 -0800 Subject: [PATCH] added dialogue for modifying damage rolls --- css/dialogue.css | 27 +++++++++++- lang/en.json | 6 ++- lang/ja.json | 6 ++- module/actor/actor-sheet.js | 5 +-- module/roll/roll.js | 52 ++++++++++++++++++++++++ templates/dialog/modify-damage-roll.html | 13 ++++++ 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 templates/dialog/modify-damage-roll.html diff --git a/css/dialogue.css b/css/dialogue.css index bd98669..1995119 100644 --- a/css/dialogue.css +++ b/css/dialogue.css @@ -11,4 +11,29 @@ .numeric-label-field{ width: 50px !important; text-align: center !important; - } \ No newline at end of file + } + + + .damage-modify-label-grid{ + display: grid; + grid-template-columns: auto auto; + align-content: left; + justify-content: left; + align-items: left; + padding: 10px; + grid-gap: 10px 15px; +} + .damage-modify-formula-modify-grid{ + display: grid; + grid-template-columns: auto auto auto auto auto auto; + align-content: left; + justify-content: left; + align-items: left; + padding: 10px; + grid-gap: 10px 15px; + } + + .damage-roll-formula-part{ + min-width: 100px !important; + text-align: center !important; +} \ No newline at end of file diff --git a/lang/en.json b/lang/en.json index bb4e2ed..be41f93 100644 --- a/lang/en.json +++ b/lang/en.json @@ -207,5 +207,9 @@ "DG.ModifySkillRollDialogue.Test": "Test:", "DG.ModifySkillRollDialogue.OriginalTarget": "Original Target:", "DG.ModifySkillRollDialogue.TargetModifier": "Modify Target:", - "DG.ModifySkillRollDialogue.ModifierTooltip": "Give a positive or negative modifier here to add/subtract from the target for the skill check." + "DG.ModifySkillRollDialogue.ModifierTooltip": "Give a positive or negative modifier here to add/subtract from the target for the skill check.", + + "DG.ModifyDamageRollDialogue.Weapon": "Weapon:", + "DG.ModifyDamageRollDialogue.OuterModifierTooltip": "Use this field to modify the outer part of the formula, such as to double the result.", + "DG.ModifyDamageRollDialogue.InnerModifierTooltip": "Use this field to add a flat modifier such as '+1' or another dice term such as '+1d4'." } \ No newline at end of file diff --git a/lang/ja.json b/lang/ja.json index 5270982..08c494b 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -207,5 +207,9 @@ "DG.ModifySkillRollDialogue.Test": "テスト:", "DG.ModifySkillRollDialogue.OriginalTarget": "元のターゲット:", "DG.ModifySkillRollDialogue.TargetModifier": "変換:", - "DG.ModifySkillRollDialogue.ModifierTooltip": "スキルチェックのターゲットに加算/減算します。" + "DG.ModifySkillRollDialogue.ModifierTooltip": "スキルチェックのターゲットに加算/減算します。", + + "DG.ModifyDamageRollDialogue.Weapon": "武器:", + "DG.ModifyDamageRollDialogue.OuterModifierTooltip": "ここでダイスの式の外を変えられる、結果を二倍にするために使われる。", + "DG.ModifyDamageRollDialogue.InnerModifierTooltip": "ここでダイスの式の内側を変えられる、結果を「+1」とか、「+1d4」とかにするために使われる。" } \ No newline at end of file diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 066c217..94bbf56 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -1,4 +1,4 @@ -import { sendPercentileTestToChat, sendLethalityTestToChat, sendDamageRollToChat, showModifyPercentileTestDialogue } from "../roll/roll.js" +import { sendPercentileTestToChat, sendLethalityTestToChat, sendDamageRollToChat, showModifyPercentileTestDialogue, showModifyDamageRollDialogue } from "../roll/roll.js" /** * Extend the basic ActorSheet with some very simple modifications * @extends {ActorSheet} @@ -344,7 +344,7 @@ export class DeltaGreenActorSheet extends ActorSheet { if(isDamageRoll){ if(requestedModifyRoll){ - // TO DO: Damage roll modifier dialogue + showModifyDamageRollDialogue(this.actor, label, dataset.roll); } else{ sendDamageRollToChat(this.actor, label, dataset.roll); @@ -362,7 +362,6 @@ export class DeltaGreenActorSheet extends ActorSheet { else{ sendPercentileTestToChat(this.actor, label, targetVal); } - } } } diff --git a/module/roll/roll.js b/module/roll/roll.js index 92bf3e7..25fd56a 100644 --- a/module/roll/roll.js +++ b/module/roll/roll.js @@ -233,4 +233,56 @@ export function sendPercentileTestToChat(actor, skill, target){ } } ).render(true); + } + + export async function showModifyDamageRollDialogue(actor, label, originalFormula){ + + let template = "systems/deltagreen/templates/dialog/modify-damage-roll.html"; + let backingData = { + data:{ + label: label, + originalFormula: originalFormula, + outerModifier: "2 * ", + innerModifier: "+ 0" + }, + }; + + let html = await renderTemplate(template, backingData); + + new Dialog({ + content: html, + title: game.i18n.localize("DG.ModifySkillRollDialogue.Title"), + default: "roll", + buttons: { + roll:{ + label: game.i18n.translations.DG.Roll.Roll, + + callback: html => { + try{ + let outerModifier = html.find("[name='outerModifier']").val(); // this is text as a heads up + let innerModifier = html.find("[name='innerModifier']").val(); // this is text as a heads up + let modifiedBaseRoll = html.find("[name='originalFormula']").val(); // this is text as a heads up + + if(innerModifier.replace(" ", "") === "+0"){ + innerModifier = ""; + } + + let newRoll = ""; + if(outerModifier.trim() != ""){ + newRoll += outerModifier + "(" + modifiedBaseRoll + innerModifier.trim() + ")"; + } + else{ + newRoll += modifiedBaseRoll + innerModifier.trim(); + } + + sendDamageRollToChat(actor, label, newRoll); + } + catch(ex){ + console.log(ex); + } + } + } + } + } + ).render(true); } \ No newline at end of file diff --git a/templates/dialog/modify-damage-roll.html b/templates/dialog/modify-damage-roll.html new file mode 100644 index 0000000..180d510 --- /dev/null +++ b/templates/dialog/modify-damage-roll.html @@ -0,0 +1,13 @@ +
+
+ {{localize 'DG.ModifyDamageRollDialogue.Weapon'}} + {{data.label}} +
+
+ + ( + + + ) +
+
\ No newline at end of file