From 449a3a80b5dcb1328c64f5204e41f88f2dc5e5f6 Mon Sep 17 00:00:00 2001 From: agaringer Date: Sat, 10 Sep 2022 15:18:57 -0400 Subject: [PATCH] Numerous major updates --- CHANGELOG.txt | 2 + lang/en.json | 15 ++++- module.json | 11 ++-- scripts/fitdroller.js | 15 +++-- scripts/main.js | 81 +++++++++++++++++++++++ templates/fitd-roll.html | 118 +++++++++++++++++++++++++++++----- templates/message-dialog.html | 88 +++++++++++++++++++++++++ 7 files changed, 301 insertions(+), 29 deletions(-) create mode 100644 templates/message-dialog.html diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e0b57b0..457842d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -23,3 +23,5 @@ 1.6.1 Fixed pt-BR translation 1.6.2 Additional V10 fixes, new interface fixes, Roll Purpose field label correction + +1.7.0 V10 only release!, Fix position of icon in roller button on sidebar, move button to a Token Layer sub-control, Make new interface # of dice follow setting, change dice setting to range sliders, set new interface as default, add setting for Extreme Effect, add Custom Messages and Editor menu diff --git a/lang/en.json b/lang/en.json index 9728a89..7c1c168 100644 --- a/lang/en.json +++ b/lang/en.json @@ -34,7 +34,7 @@ "FitDRoller.RollDo": "You do it.", "FitDRoller.RollPartialSuccessPositionControlled": "You hesitate. Withdraw and try a different approach, or else do it with a minor consequence: a minor complication occurs, you have reduced effect, you suffer lesser harm, you end up in a risky position.", "FitDRoller.RollPartialSuccessPositionRisky": "You do it, but there’s a consequence: you suffer harm, a complication occurs, you have reduced effect, you end up in a desperate position.", - "FitDRoller.RollPartialSuccessPosition": "You do it, but there’s a consequence: you suffer severe harm, a serious complication occurs, you have reduced effect.", + "FitDRoller.RollPartialSuccessPositionDesperate": "You do it, but there’s a consequence: you suffer severe harm, a serious complication occurs, you have reduced effect.", "FitDRoller.RollFailurePositionControlled": "You falter. Press on by seizing a risky opportunity, or withdraw and try a different approach.", "FitDRoller.RollFailurePositionRisky": "Things go badly. You suffer harm, a complication occurs, you end up in a desperate position, you lose this opportunity for action.", "FitDRoller.RollFailurePositionDesperate": "It’s the worst outcome. You suffer severe harm, a serious complication occurs, you lose this opportunity for action.", @@ -77,5 +77,16 @@ "FitDRoller.newInterface": "New Interface", "FitDRoller.newInterfaceHint": "Use new GUI interface for roller", - "FitDRoller.RollPurpose": "Roll Purpose" + "FitDRoller.RollPurpose": "Roll Purpose", + + "FitDRoller.DesperateBonus": "Additional Message for Desperate Position Rolls", + "FitDRoller.customMessagesMenu": "Custom Roll Result Messages", + "FitDRoller.customMessagesButton": "Edit Messages", + "FitDRoller.customMessagesHint": "Use this menu to edit the various messages in the chat results", + "FitDRoller.customMessagesHeader": "Custom Roll Result Message Editor", + "FitDRoller.customMessagesNotes": "Use this interface to edit the messages displayed in the chat messages based in the roll results. Basic HTML tags may be manually added to the fields.", + "FitDRoller.customMessagesNotes2": "In order to revert to the default messages, use the Reset Defaults button below (which will clear all fields in this dialog) or delete all content from a specific field.", + "FitDRoller.ResetDefaults": "Revert all to defaults?", + "FitDRoller.ResetDefaultsWarning": "This will clear all fields in this menu dialog and revert to the default messages.", + "FitDRoller.ResetDefaultsDone": "All Custom Messages reverted to defaults." } diff --git a/module.json b/module.json index 98c8952..b9fbd9f 100644 --- a/module.json +++ b/module.json @@ -10,16 +10,15 @@ {"name": "Mestre Digital"}, {"name": "Gus"} ], - "version": "1.6.2", - "minimumCoreVersion": "0.7.5", - "compatibleCoreVersion": "10.284", + "version": "1.7.0", + "minimumCoreVersion": 10, "compatibility": { - "minimum": "0.7.5", - "verified": "10.284" + "minimum": 10, + "verified": "10.285" }, "url": "https://github.com/drewg13/foundryvtt-fitdroller", "manifest": "https://raw.githubusercontent.com/drewg13/foundryvtt-fitdroller/main/module.json", - "download": "https://github.com/drewg13/foundryvtt-fitdroller/archive/v1.6.2.zip", + "download": "https://github.com/drewg13/foundryvtt-fitdroller/archive/v1.7.0.zip", "bugs": "https://github.com/drewg13/foundryvtt-fitdroller/issues", "styles": ["styles/fitdroller.css"], "esmodules": ["scripts/main.js"], diff --git a/scripts/fitdroller.js b/scripts/fitdroller.js index 0033af6..6a3e164 100644 --- a/scripts/fitdroller.js +++ b/scripts/fitdroller.js @@ -102,7 +102,6 @@ export default class Roller { } ).render( true ); } else { let htmlContent = await renderTemplate( "modules/" + this.moduleName + "/templates/roll-dialog.html", { numDice: game.fitdroller.maxDice, useExtreme: game.fitdroller.useExtreme } ); - htmlContent = new DOMParser().parseFromString(htmlContent, "text/html"); htmlContent.getElementById( game.fitdroller.defaultDice + "d" ).setAttribute("checked", ""); htmlContent = htmlContent.querySelector("form").parentElement.innerHTML; @@ -302,8 +301,8 @@ export default class Roller { default: effect_localize = 'FitDRoller.EffectStandard'; } - - const result = await renderTemplate("modules/" + this.moduleName + "/templates/fitd-roll.html", { rolls, roll_status, attribute, position, position_localize, effect, effect_localize, zeromode, color, purpose }); + const customMessages = await game.settings.get( this.moduleName, "customMessages" ); + const result = await renderTemplate("modules/" + this.moduleName + "/templates/fitd-roll.html", { rolls, roll_status, attribute, position, position_localize, effect, effect_localize, zeromode, color, purpose, custom: customMessages }); const messageData = { speaker, @@ -377,6 +376,7 @@ export default class Roller { let roll_status; let use_die; let prev_use_die; + let prev_prev_use_die; if (zeromode) { use_die = sorted_rolls[0]; @@ -384,6 +384,9 @@ export default class Roller { use_die = sorted_rolls[sorted_rolls.length - 1]; if (sorted_rolls.length - 2 >= 0) { prev_use_die = sorted_rolls[sorted_rolls.length - 2] + if (sorted_rolls.length - 3 >= 0) { + prev_prev_use_die = sorted_rolls[sorted_rolls.length - 3] + } } } @@ -393,7 +396,11 @@ export default class Roller { } else if (use_die === 6) { // 6,6 - critical success if (prev_use_die && prev_use_die === 6) { - roll_status = "great"; + if ( prev_prev_use_die && prev_prev_use_die === 6 ) { + roll_status = "extreme"; + } else { + roll_status = "great"; + } } else { roll_status = "standard"; } diff --git a/scripts/main.js b/scripts/main.js index 272277d..bd49bbf 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -137,6 +137,23 @@ Hooks.once("init", () => { "type": Boolean }); + game.settings.registerMenu( moduleName, "customMessagesMenu", { + name: "FitDRoller.customMessagesMenu", + label: "FitDRoller.customMessagesButton", + hint: "FitDRoller.customMessagesHint", + icon: "fas fa-envelope-open-text", + type: CustomMessagesConfig, + restricted: true + }); + + game.settings.register( moduleName, "customMessages", { + "name": "Custom Messages", + "scope": "world", + "config": false, + "default": {}, + "type": Object + }); + game.keybindings.register( moduleName, "FitDRollerShortcut", { name: game.i18n.localize("FitDRoller.FitDRollerShortcutName"), hint: game.i18n.localize("FitDRoller.FitDRollerShortcutHint"), @@ -160,4 +177,68 @@ Hooks.once("init", () => { game.fitdroller.useExtreme = game.settings.get( moduleName, "useExtreme" ); }); +/** + * An application for configuring the permissions which are available to each User role. + */ +class CustomMessagesConfig extends FormApplication { + + /** @override */ + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("FitDRoller.customMessagesMenu"), + id: "custom-messages-config", + classes: ["fitdroller", "custom-messages-config"], + template: "modules/foundryvtt-fitdroller/templates/message-dialog.html", + width: 660, + height: "auto", + resizable: true, + closeOnSubmit: true + }); + } + + /* -------------------------------------------- */ + + /** @override */ + async getData(options) { + return game.settings.get( moduleName, "customMessages" ); + } + + /* -------------------------------------------- */ + /* Event Listeners and Handlers */ + /* -------------------------------------------- */ + + /** @override */ + activateListeners(html) { + super.activateListeners(html); + html.find('button[name="reset"]').click(this._onResetDefaults.bind(this)); + } + + /* -------------------------------------------- */ + + /** + * Handle button click to reset default settings + * @param event {Event} The initial button click event + * @private + */ + async _onResetDefaults(event) { + event.preventDefault(); + const confirm = await Dialog.confirm({ + title: game.i18n.localize("FitDRoller.ResetDefaults"), + content: `

${game.i18n.localize("FitDRoller.ResetDefaultsWarning")}

` + }); + if ( !confirm ) return; + await game.settings.set( moduleName, "customMessages", {}); + ui.notifications.info(game.i18n.localize('FitDRoller.ResetDefaultsDone')); + return this.render(); + } + + /* -------------------------------------------- */ + + /** @override */ + async _updateObject(event, formData) { + const customMessages = foundry.utils.expandObject(formData); + await game.settings.set(moduleName, "customMessages", customMessages); + } +} + console.log("FitDRoller | Forged in the Dark Dice Roller loaded"); diff --git a/templates/fitd-roll.html b/templates/fitd-roll.html index aa6c7e1..33d8095 100644 --- a/templates/fitd-roll.html +++ b/templates/fitd-roll.html @@ -16,10 +16,19 @@ {{#if (eq roll_status "critical-success")}}
{{localize "FitDRoller.RollCriticalSuccess"}}
-

{{{localize "FitDRoller.RollDoWithIncreasedEffect"}}}

- + {{#if custom.criticalSuccess}} +

{{{custom.criticalSuccess}}}

+ {{else}} +

{{{localize "FitDRoller.RollDoWithIncreasedEffect"}}}

+ {{/if}} {{#if (eq position "desperate")}} -

{{{localize "FitDRoller.RollXP"}}}

+

+ {{#if custom.desperateBonus}} + {{{custom.desperateBonus}}} + {{else}} + {{{localize "FitDRoller.RollXP"}}} + {{/if}} +

{{/if}}
{{/if}} @@ -27,10 +36,20 @@ {{#if (eq roll_status "success")}}
{{localize "FitDRoller.RollSuccess"}}
-

{{{localize "FitDRoller.RollDo"}}}

+ {{#if custom.success}} +

{{{custom.success}}}

+ {{else}} +

{{{localize "FitDRoller.RollDo"}}}

+ {{/if}} {{#if (eq position "desperate")}} -

{{{localize "FitDRoller.RollXP"}}}

+

+ {{#if custom.desperateBonus}} + {{{custom.desperateBonus}}} + {{else}} + {{{localize "FitDRoller.RollXP"}}} + {{/if}} +

{{/if}}
{{/if}} @@ -40,15 +59,33 @@

{{#if (eq position "controlled")}} - {{{localize "FitDRoller.RollPartialSuccessPositionControlled"}}} + {{#if custom.partialSuccessControlled}} + {{{custom.partialSuccessControlled}}} + {{else}} + {{{localize "FitDRoller.RollPartialSuccessPositionControlled"}}} + {{/if}} {{else if (eq position "risky")}} - {{{localize "FitDRoller.RollPartialSuccessPositionRisky"}}} + {{#if custom.partialSuccessRisky}} + {{{custom.partialSuccessRisky}}} + {{else}} + {{{localize "FitDRoller.RollPartialSuccessPositionRisky"}}} + {{/if}} {{else}} - {{{localize "FitDRoller.RollPartialSuccessPosition"}}} + {{#if custom.partialSuccessDesperate}} + {{{custom.partialSuccessDesperate}}} + {{else}} + {{{localize "FitDRoller.RollPartialSuccessPositionDesperate"}}} + {{/if}} {{/if}}

{{#if (eq position "desperate")}} -

{{{localize "FitDRoller.RollXP"}}}

+

+ {{#if custom.desperateBonus}} + {{{custom.desperateBonus}}} + {{else}} + {{{localize "FitDRoller.RollXP"}}} + {{/if}} +

{{/if}}
{{/if}} @@ -58,24 +95,59 @@

{{#if (eq position "controlled")}} - {{{localize "FitDRoller.RollFailurePositionControlled"}}} + {{#if custom.failureControlled}} + {{{custom.failureControlled}}} + {{else}} + {{{localize "FitDRoller.RollFailurePositionControlled"}}} + {{/if}} {{else if (eq position "risky")}} - {{{localize "FitDRoller.RollFailurePositionRisky"}}} + {{#if custom.failureRisky}} + {{{custom.failureRisky}}} + {{else}} + {{{localize "FitDRoller.RollFailurePositionRisky"}}} + {{/if}} {{else}} - {{{localize "FitDRoller.RollFailurePositionDesperate"}}} + {{#if custom.failureDesperate}} + {{{custom.failureDesperate}}} + {{else}} + {{{localize "FitDRoller.RollFailurePositionDesperate"}}} + {{/if}} {{/if}}

{{#if (eq position "desperate")}} -

{{{localize "FitDRoller.RollXP"}}}

+

+ {{#if custom.desperateBonus}} + {{{custom.desperateBonus}}} + {{else}} + {{{localize "FitDRoller.RollXP"}}} + {{/if}} +

{{/if}}
{{/if}} + {{#if (eq roll_status "extreme")}} +
{{localize "FitDRoller.RollExtremeEffect"}}
+
+

+ {{#if custom.fortuneExtreme}} + {{{custom.fortuneExtreme}}} + {{else}} + {{{localize "FitDRoller.RollExtremeEffectDescription"}}} + {{/if}} +

+
+ {{/if}} + {{#if (eq roll_status "great")}}
{{localize "FitDRoller.RollGreatEffect"}}

- {{{localize "FitDRoller.RollGreatEffectDescription"}}} + {{#if custom.fortuneGreat}} + {{{custom.fortuneGreat}}} + {{else}} + {{{localize "FitDRoller.RollGreatEffectDescription"}}} + {{/if}}

{{/if}} @@ -84,7 +156,11 @@
{{localize "FitDRoller.RollStandardEffect"}}

- {{{localize "FitDRoller.RollStandardEffectDescription"}}} + {{#if custom.fortuneStandard}} + {{{custom.fortuneStandard}}} + {{else}} + {{{localize "FitDRoller.RollStandardEffectDescription"}}} + {{/if}}

{{/if}} @@ -93,7 +169,11 @@
{{localize "FitDRoller.RollLimitedEffect"}}

- {{{localize "FitDRoller.RollLimitedEffectDescription"}}} + {{#if custom.fortuneLimited}} + {{{custom.fortuneLimited}}} + {{else}} + {{{localize "FitDRoller.RollLimitedEffectDescription"}}} + {{/if}}

{{/if}} @@ -102,7 +182,11 @@
{{localize "FitDRoller.RollZeroEffect"}}

- {{{localize "FitDRoller.RollZeroEffectDescription"}}} + {{#if custom.fortuneZero}} + {{{custom.fortuneZero}}} + {{else}} + {{{localize "FitDRoller.RollZeroEffectDescription"}}} + {{/if}}

{{/if}} diff --git a/templates/message-dialog.html b/templates/message-dialog.html new file mode 100644 index 0000000..ec2b6ce --- /dev/null +++ b/templates/message-dialog.html @@ -0,0 +1,88 @@ +
+ +

{{{localize "FitDRoller.customMessagesHeader"}}}

+

{{{localize "FitDRoller.customMessagesNotes"}}}

+

{{{localize "FitDRoller.customMessagesNotes2"}}}

+ +
+

{{localize "FitDRoller.RollCriticalSuccess"}}

+ + +

{{localize "FitDRoller.RollSuccess"}}

+ + +

{{localize "FitDRoller.RollPartialSuccess"}} - {{localize "FitDRoller.PositionControlled"}}

+ + +

{{localize "FitDRoller.RollPartialSuccess"}} - {{localize "FitDRoller.PositionRisky"}}

+ + +

{{localize "FitDRoller.RollPartialSuccess"}} - {{localize "FitDRoller.PositionDesperate"}}

+ + +

{{localize "FitDRoller.RollFailure"}} - {{localize "FitDRoller.PositionControlled"}}

+ + +

{{localize "FitDRoller.RollFailure"}} - {{localize "FitDRoller.PositionRisky"}}

+ + +

{{localize "FitDRoller.RollFailure"}} - {{localize "FitDRoller.PositionDesperate"}}

+ + +

{{localize "FitDRoller.DesperateBonus"}}

+ + +

{{localize "FitDRoller.FortuneRoll"}} - {{localize "FitDRoller.RollExtremeEffect"}}

+ + +

{{localize "FitDRoller.FortuneRoll"}} - {{localize "FitDRoller.RollGreatEffect"}}

+ + +

{{localize "FitDRoller.FortuneRoll"}} - {{localize "FitDRoller.RollStandardEffect"}}

+ + +

{{localize "FitDRoller.FortuneRoll"}} - {{localize "FitDRoller.RollLimitedEffect"}}

+ + +

{{localize "FitDRoller.FortuneRoll"}} - {{localize "FitDRoller.RollZeroEffect"}}

+ +
+ +
+ + + +
+
\ No newline at end of file