Skip to content

Commit

Permalink
Numerous major updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drewg13 committed Sep 10, 2022
1 parent da9c5b5 commit 449a3a8
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>minor complication</strong> occurs, you have <strong>reduced effect</strong>, you suffer <strong>lesser harm</strong>, you end up in a <strong>risky</strong> position.",
"FitDRoller.RollPartialSuccessPositionRisky": "You do it, but there’s a consequence: you suffer <strong>harm</strong>, a <strong>complication</strong> occurs, you have <strong>reduced effect</strong>, you end up in a <strong>desperate</strong> position.",
"FitDRoller.RollPartialSuccessPosition": "You do it, but there’s a consequence: you suffer <strong>severe harm</strong>, a <strong>serious complication</strong> occurs, you have <strong>reduced effect</strong>.",
"FitDRoller.RollPartialSuccessPositionDesperate": "You do it, but there’s a consequence: you suffer <strong>severe harm</strong>, a <strong>serious complication</strong> occurs, you have <strong>reduced effect</strong>.",
"FitDRoller.RollFailurePositionControlled": "You falter. Press on by seizing a <strong>risky</strong> opportunity, or <strong>withdraw</strong> and try a different approach.",
"FitDRoller.RollFailurePositionRisky": "Things go badly. You suffer <strong>harm</strong>, a <strong>complication</strong> occurs, you end up in a <strong>desperate</strong> position, you <strong>lose this opportunity</strong> for action.",
"FitDRoller.RollFailurePositionDesperate": "It’s the worst outcome. You suffer <strong>severe harm</strong>, a <strong>serious complication occurs</strong>, you <strong>lose this opportunity</strong> for action.",
Expand Down Expand Up @@ -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."
}
11 changes: 5 additions & 6 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
15 changes: 11 additions & 4 deletions scripts/fitdroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -377,13 +376,17 @@ 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];
} else {
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]
}
}
}

Expand All @@ -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";
}
Expand Down
81 changes: 81 additions & 0 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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: `<p>${game.i18n.localize("FitDRoller.ResetDefaultsWarning")}</p>`
});
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");
118 changes: 101 additions & 17 deletions templates/fitd-roll.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@
{{#if (eq roll_status "critical-success")}}
<div class="die {{roll_status}}">{{localize "FitDRoller.RollCriticalSuccess"}}</div>
<div class="description">
<p>{{{localize "FitDRoller.RollDoWithIncreasedEffect"}}}</p>

{{#if custom.criticalSuccess}}
<p>{{{custom.criticalSuccess}}}</p>
{{else}}
<p>{{{localize "FitDRoller.RollDoWithIncreasedEffect"}}}</p>
{{/if}}
{{#if (eq position "desperate")}}
<p>{{{localize "FitDRoller.RollXP"}}}</p>
<p>
{{#if custom.desperateBonus}}
{{{custom.desperateBonus}}}
{{else}}
{{{localize "FitDRoller.RollXP"}}}
{{/if}}
</p>
{{/if}}
</div>
{{/if}}

{{#if (eq roll_status "success")}}
<div class="die {{roll_status}}">{{localize "FitDRoller.RollSuccess"}}</div>
<div class="description">
<p>{{{localize "FitDRoller.RollDo"}}}</p>
{{#if custom.success}}
<p>{{{custom.success}}}</p>
{{else}}
<p>{{{localize "FitDRoller.RollDo"}}}</p>
{{/if}}

{{#if (eq position "desperate")}}
<p>{{{localize "FitDRoller.RollXP"}}}</p>
<p>
{{#if custom.desperateBonus}}
{{{custom.desperateBonus}}}
{{else}}
{{{localize "FitDRoller.RollXP"}}}
{{/if}}
</p>
{{/if}}
</div>
{{/if}}
Expand All @@ -40,15 +59,33 @@
<div class="description">
<p>
{{#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}}
</p>
{{#if (eq position "desperate")}}
<p>{{{localize "FitDRoller.RollXP"}}}</p>
<p>
{{#if custom.desperateBonus}}
{{{custom.desperateBonus}}}
{{else}}
{{{localize "FitDRoller.RollXP"}}}
{{/if}}
</p>
{{/if}}
</div>
{{/if}}
Expand All @@ -58,24 +95,59 @@
<div class="description">
<p>
{{#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}}
</p>
{{#if (eq position "desperate")}}
<p>{{{localize "FitDRoller.RollXP"}}}</p>
<p>
{{#if custom.desperateBonus}}
{{{custom.desperateBonus}}}
{{else}}
{{{localize "FitDRoller.RollXP"}}}
{{/if}}
</p>
{{/if}}
</div>
{{/if}}

{{#if (eq roll_status "extreme")}}
<div class="die {{roll_status}}">{{localize "FitDRoller.RollExtremeEffect"}}</div>
<div class="description">
<p>
{{#if custom.fortuneExtreme}}
{{{custom.fortuneExtreme}}}
{{else}}
{{{localize "FitDRoller.RollExtremeEffectDescription"}}}
{{/if}}
</p>
</div>
{{/if}}

{{#if (eq roll_status "great")}}
<div class="die {{roll_status}}">{{localize "FitDRoller.RollGreatEffect"}}</div>
<div class="description">
<p>
{{{localize "FitDRoller.RollGreatEffectDescription"}}}
{{#if custom.fortuneGreat}}
{{{custom.fortuneGreat}}}
{{else}}
{{{localize "FitDRoller.RollGreatEffectDescription"}}}
{{/if}}
</p>
</div>
{{/if}}
Expand All @@ -84,7 +156,11 @@
<div class="die {{roll_status}}">{{localize "FitDRoller.RollStandardEffect"}}</div>
<div class="description">
<p>
{{{localize "FitDRoller.RollStandardEffectDescription"}}}
{{#if custom.fortuneStandard}}
{{{custom.fortuneStandard}}}
{{else}}
{{{localize "FitDRoller.RollStandardEffectDescription"}}}
{{/if}}
</p>
</div>
{{/if}}
Expand All @@ -93,7 +169,11 @@
<div class="die {{roll_status}}">{{localize "FitDRoller.RollLimitedEffect"}}</div>
<div class="description">
<p>
{{{localize "FitDRoller.RollLimitedEffectDescription"}}}
{{#if custom.fortuneLimited}}
{{{custom.fortuneLimited}}}
{{else}}
{{{localize "FitDRoller.RollLimitedEffectDescription"}}}
{{/if}}
</p>
</div>
{{/if}}
Expand All @@ -102,7 +182,11 @@
<div class="die {{roll_status}}">{{localize "FitDRoller.RollZeroEffect"}}</div>
<div class="description">
<p>
{{{localize "FitDRoller.RollZeroEffectDescription"}}}
{{#if custom.fortuneZero}}
{{{custom.fortuneZero}}}
{{else}}
{{{localize "FitDRoller.RollZeroEffectDescription"}}}
{{/if}}
</p>
</div>
{{/if}}
Expand Down
Loading

0 comments on commit 449a3a8

Please sign in to comment.