mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Error checking for the fate type parsing in all potential problem locations
This commit is contained in:
parent
9ce5c27c85
commit
3e366a4c44
2 changed files with 35 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.
|
|||
import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs';
|
||||
import { BaseRoll, DHRoll, DualityRoll, D20Roll, DamageRoll, FateRoll } from './module/dice/_module.mjs';
|
||||
import { enrichedDualityRoll } from './module/enrichers/DualityRollEnricher.mjs';
|
||||
import { enrichedFateRoll } from './module/enrichers/FateRollEnricher.mjs';
|
||||
import { enrichedFateRoll, getFateType } from './module/enrichers/FateRollEnricher.mjs';
|
||||
import {
|
||||
handlebarsRegistration,
|
||||
runMigrations,
|
||||
|
|
@ -259,12 +259,10 @@ Hooks.on('chatMessage', (_, message) => {
|
|||
|
||||
const { result: rollCommand, flavor } = result;
|
||||
|
||||
const fateTypeFromRollCommand = rollCommand?.type ?
|
||||
(rollCommand?.type?.toLowerCase() == "fear" ? "Fear" :
|
||||
(rollCommand?.type?.toLowerCase() == "hope" ? "Hope" : "BAD")) : "Hope";
|
||||
const fateTypeFromRollCommand = getFateType(rollCommand?.type);
|
||||
|
||||
if (fateTypeFromRollCommand == "BAD") {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateParsing'));
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateParsing') + ". Bad Fate Type. Valid Fate Types are 'Hope' and 'Fear'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,33 @@ export default function DhFateRollEnricher(match, _options) {
|
|||
const roll = rollCommandToJSON(match[1], match[0]);
|
||||
if (!roll) return match[0];
|
||||
|
||||
const fateTypeFromRoll = getFateType(roll?.type);
|
||||
|
||||
if (fateTypeFromRoll == "BAD") {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateParsing') + ". Bad Fate Type. Valid Fate Types are 'Hope' and 'Fear'.");
|
||||
return;
|
||||
}
|
||||
|
||||
return getFateMessage(roll.result, roll?.flavor);
|
||||
}
|
||||
|
||||
export function getFateType(fateTypeValue) {
|
||||
const fateTypeFromValue = fateTypeValue ?
|
||||
(fateTypeValue.toLowerCase() == "fear" ? "Fear" :
|
||||
(fateTypeValue.toLowerCase() == "hope" ? "Hope" : "BAD")) : "Hope";
|
||||
|
||||
|
||||
return fateTypeFromValue;
|
||||
}
|
||||
|
||||
function getFateMessage(roll, flavor) {
|
||||
const fateType = roll?.type ?? 'Hope';
|
||||
const fateType = getFateType(roll?.type);
|
||||
|
||||
if (fateType == "BAD") {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateParsing') + ". Bad Fate Type. Valid Fate Types are 'Hope' and 'Fear'.");
|
||||
return '';
|
||||
}
|
||||
|
||||
const fateTypeLocalized = fateType === "Hope" ? game.i18n.localize("DAGGERHEART.GENERAL.hope") : game.i18n.localize("DAGGERHEART.GENERAL.fear");
|
||||
|
||||
const title = flavor ?? fateTypeLocalized + ' ' +
|
||||
|
|
@ -34,13 +56,21 @@ function getFateMessage(roll, flavor) {
|
|||
export const renderFateButton = async event => {
|
||||
const button = event.currentTarget,
|
||||
target = getCommandTarget({ allowNull: true });
|
||||
console.log("button", button);
|
||||
|
||||
const fateTypeFromButton = getFateType(button.dataset?.fatetype);
|
||||
|
||||
if (fateTypeFromButton == "BAD") {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateParsing') + ". Bad Fate Type. Valid Fate Types are 'Hope' and 'Fear'.");
|
||||
return;
|
||||
}
|
||||
|
||||
await enrichedFateRoll(
|
||||
{
|
||||
target,
|
||||
title: button.dataset.title,
|
||||
label: button.dataset.label,
|
||||
fateType: button.dataset.fatetype
|
||||
fateType: fateTypeFromButton
|
||||
},
|
||||
event
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue