Skip to content

Commit

Permalink
Merge pull request #129 from MangoFVTT/develop
Browse files Browse the repository at this point in the history
release/1.3.14
  • Loading branch information
MangoFVTT authored Jan 10, 2023
2 parents e672e0f + 4471100 commit bc9edb1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
8 changes: 8 additions & 0 deletions css/ready-set-roll.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
padding: 0px 4px 0px 4px;
}

.dice-roll .dice-total.critical {
color: var(--color-text-dark-primary);
}

.dice-roll .dice-total.fumble {
color: var(--color-text-dark-primary);
}

.rsr-dual .dice-row .failure {
color: #aa0200;
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"enableItemQuickRoll.hint": "When clicking on an item's image (weapons, spells, features, etc.), automatically roll to chat instead of using the normal chat output. This functionality can be bypassed by holding Alt when clicking.",
"enableAltQuickRoll.name": "Enable Alternate Roll for Items",
"enableAltQuickRoll.hint": "When Alt-clicking on an item's image, output a different quick roll which can be configured separately, replacing the ability to bypass quick rolling for items. This setting has no effect if item quick rolling is disabled.",
"enableQuickRollDesc.name": "Enable Descriptions by Default",
"enableQuickRollDesc.hint": "When outputting a quick roll, always show the description by default. This can still be changed per item in quick roll configuration.",
"enableD20Icons.name": "Show D20 Rolls for Quick Rolls",
"enableD20Icons.hint": "When outputting a quick roll, display an icon showing the natural die roll next to the total result.",
"enableDiceSounds.name": "Enable Dice Sounds for Quick Rolls",
Expand Down
5 changes: 3 additions & 2 deletions src/module/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ITEM_TYPE } from "../utils/item.js";
import { FIELD_TYPE } from "../utils/render.js";
import { SettingsUtility, SETTING_NAMES } from "../utils/settings.js";
import { MODULE_SHORT } from "./const.js";

/**
Expand Down Expand Up @@ -31,7 +32,7 @@ CONFIG[MODULE_SHORT] = {
},
flags: {
weapon: {
quickDesc: { type: "Boolean", value: false, altValue: false },
quickDesc: { type: "Boolean", get value() { return SettingsUtility.getSettingValue(SETTING_NAMES.QUICK_ROLL_DESC_ENABLED) }, altValue: false },
quickFlavor: { type: "Boolean", value: true, altValue: true },
quickFooter: { type: "Boolean", value: true, altValue: true },
quickAttack: { type: "Boolean", value: true, altValue: true },
Expand Down Expand Up @@ -83,7 +84,7 @@ CONFIG[MODULE_SHORT] = {
consumeRecharge: { type: "Boolean", value: true, altValue: true }
},
tool: {
quickDesc: { type: "Boolean", value: false, altValue: false },
quickDesc: { type: "Boolean", get value() { return SettingsUtility.getSettingValue(SETTING_NAMES.QUICK_ROLL_DESC_ENABLED) }, altValue: false },
quickFlavor: { type: "Boolean", value: true, altValue: true },
quickFooter: { type: "Boolean", value: true, altValue: true },
quickCheck: { type: "Boolean", value: true, altValue: true }
Expand Down
17 changes: 14 additions & 3 deletions src/module/quickroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export class QuickRoll {
* @returns {Promise<QuickRoll>} A quick roll instance derived from stored message data.
*/
static async fromMessage(message) {
const data = message.flags[`${MODULE_SHORT}`];
const data = message.flags[MODULE_SHORT];

// convert JSON string back to objects
if (typeof(data?.fields[0]) === "string") {
data.fields = data.fields.map(JSON.parse);
}

// Rolls in fields are unpacked and must be recreated.
const fields = data?.fields ?? [];
Expand Down Expand Up @@ -175,6 +180,12 @@ export class QuickRoll {
...CoreUtility.getWhisperData(rollMode),
}

// Can't store classes in flags, but the fields may contain D20Roll classes, so convert them to JSON strings.
const flags = chatData.flags[MODULE_SHORT];
if (flags.fields) {
flags.fields = flags.fields.map(JSON.stringify);
}

if (this.item) {
Hooks.callAll(HOOKS_DND5E.PRE_DISPLAY_CARD, item, chatData, { createMessage });
}
Expand Down Expand Up @@ -345,15 +356,15 @@ export class QuickRoll {
*/
_getFlags() {
const flags = {
rsr5e: {
[MODULE_SHORT]: {
version: CoreUtility.getVersion(),
actorId: this.actorId,
itemId: this.itemId,
tokenId: this.tokenId,
params: this.params,
fields: this.fields
}
};
};

if (this.fields.some(f => f[0] === ROLL_TYPE.ATTACK)) {
flags["dnd5e.roll.type"] = ROLL_TYPE.ATTACK;
Expand Down
7 changes: 6 additions & 1 deletion src/utils/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ export class ItemUtility {
* These booleans give a quick indication on if the item has that specific consume property.
* @param {Item} item The item on which to ensure consume properties exist.
*/
static ensureConsumePropertiesOnItem(item) {
static ensureConsumePropertiesOnItem(item) {
if (item?.type === ITEM_TYPE.SPELL)
{
return;
}

if (item) {
// For items with quantity (weapons, tools, consumables...)
item.hasQuantity = ("quantity" in item.system);
Expand Down
6 changes: 4 additions & 2 deletions src/utils/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ async function _renderMultiRoll(renderData = {}) {
if (roll.options.halflingLucky && d20Rolls.results[i].result === 1) {
i++;
tmpResults.push(d20Rolls.results[i]);
}
}

let critOptions = { critThreshold: roll.options.critical, fumbleThreshold: roll.options.fumble };

// Die terms must have active results or the base roll total of the generated roll is 0.
// This does not apply to dice that have been rerolled (unless they are replaced by a fixer value eg. for reliable talent).
tmpResults.forEach(r => {
Expand All @@ -198,7 +200,7 @@ async function _renderMultiRoll(renderData = {}) {
roll: baseRoll,
total: baseRoll.total + (bonusRoll?.total ?? 0),
ignored: tmpResults.some(r => r.discarded) ? true : undefined,
critType: RollUtility.getCritTypeForDie(baseTerm),
critType: RollUtility.getCritTypeForDie(baseTerm, critOptions),
d20Result: SettingsUtility.getSettingValue(SETTING_NAMES.D20_ICONS_ENABLED) ? d20Rolls.results[i].result : null
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const SETTING_NAMES = {
QUICK_ABILITY_ENABLED: "enableAbilityQuickRoll",
QUICK_ITEM_ENABLED: "enableItemQuickRoll",
ALT_ROLL_ENABLED: "enableAltQuickRoll",
QUICK_ROLL_DESC_ENABLED: "enableQuickRollDesc",
D20_ICONS_ENABLED: "enableD20Icons",
DICE_SOUNDS_ENABLED: "enableDiceSounds",
OVERLAY_BUTTONS_ENABLED: "enableOverlayButtons",
Expand Down Expand Up @@ -75,6 +76,7 @@ export class SettingsUtility {
// ADDITIONAL ROLL SETTINGS
const extraRollOptions = [
{ name: SETTING_NAMES.ALT_ROLL_ENABLED, default: false, scope: "world" },
{ name: SETTING_NAMES.QUICK_ROLL_DESC_ENABLED, default: false, scope: "world" },
{ name: SETTING_NAMES.ALWAYS_ROLL_MULTIROLL, default: false, scope: "client" },
{ name: SETTING_NAMES.ALWAYS_MANUAL_DAMAGE, default: false, scope: "client" }
];
Expand Down

0 comments on commit bc9edb1

Please sign in to comment.