mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Added flavor for DualityRollEnrichment
This commit is contained in:
parent
b9334447de
commit
25fc663caa
4 changed files with 24 additions and 17 deletions
|
|
@ -187,12 +187,14 @@ Hooks.on('renderHandlebarsApplication', (_, element) => {
|
||||||
|
|
||||||
Hooks.on('chatMessage', (_, message) => {
|
Hooks.on('chatMessage', (_, message) => {
|
||||||
if (message.startsWith('/dr')) {
|
if (message.startsWith('/dr')) {
|
||||||
const rollCommand = rollCommandToJSON(message.replace(/\/dr\s?/, ''));
|
const result = rollCommandToJSON(message.replace(/\/dr\s?/, ''));
|
||||||
if (!rollCommand) {
|
if (!result) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.dualityParsing'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.dualityParsing'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { result: rollCommand, flavor } = result;
|
||||||
|
|
||||||
const reaction = rollCommand.reaction;
|
const reaction = rollCommand.reaction;
|
||||||
const traitValue = rollCommand.trait?.toLowerCase();
|
const traitValue = rollCommand.trait?.toLowerCase();
|
||||||
const advantage = rollCommand.advantage
|
const advantage = rollCommand.advantage
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,21 @@ import { abilities } from '../config/actorConfig.mjs';
|
||||||
import { getCommandTarget, rollCommandToJSON } from '../helpers/utils.mjs';
|
import { getCommandTarget, rollCommandToJSON } from '../helpers/utils.mjs';
|
||||||
|
|
||||||
export default function DhDualityRollEnricher(match, _options) {
|
export default function DhDualityRollEnricher(match, _options) {
|
||||||
const roll = rollCommandToJSON(match[1]);
|
const roll = rollCommandToJSON(match[1], match[0]);
|
||||||
if (!roll) return match[0];
|
if (!roll) return match[0];
|
||||||
|
|
||||||
return getDualityMessage(roll);
|
return getDualityMessage(roll.result, roll.flavor);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDualityMessage(roll) {
|
function getDualityMessage(roll, flavor) {
|
||||||
const trait = roll.trait && abilities[roll.trait] ? game.i18n.localize(abilities[roll.trait].label) : null;
|
const trait = roll.trait && abilities[roll.trait] ? game.i18n.localize(abilities[roll.trait].label) : null;
|
||||||
const label = roll.trait
|
const label =
|
||||||
? game.i18n.format('DAGGERHEART.GENERAL.rollWith', { roll: trait })
|
flavor ??
|
||||||
: roll.reaction
|
(roll.trait
|
||||||
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
? game.i18n.format('DAGGERHEART.GENERAL.rollWith', { roll: trait })
|
||||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
: roll.reaction
|
||||||
|
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
||||||
|
: game.i18n.localize('DAGGERHEART.GENERAL.duality'));
|
||||||
|
|
||||||
const dataLabel = trait
|
const dataLabel = trait
|
||||||
? game.i18n.localize(abilities[roll.trait].label)
|
? game.i18n.localize(abilities[roll.trait].label)
|
||||||
|
|
@ -48,7 +50,7 @@ function getDualityMessage(roll) {
|
||||||
>
|
>
|
||||||
${roll.reaction ? '<i class="fa-solid fa-reply"></i>' : '<i class="fa-solid fa-circle-half-stroke"></i>'}
|
${roll.reaction ? '<i class="fa-solid fa-reply"></i>' : '<i class="fa-solid fa-circle-half-stroke"></i>'}
|
||||||
${label}
|
${label}
|
||||||
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
|
${!flavor && (roll.difficulty || advantageLabel) ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,19 @@ export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEn
|
||||||
|
|
||||||
export const enricherConfig = [
|
export const enricherConfig = [
|
||||||
{
|
{
|
||||||
pattern: /^@Damage\[(.*)\]$/g,
|
pattern: /^@Damage\[(.*)\]({.*})?$/g,
|
||||||
enricher: DhDamageEnricher
|
enricher: DhDamageEnricher
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /\[\[\/dr\s?(.*?)\]\]/g,
|
pattern: /\[\[\/dr\s?(.*?)\]\]({.*})?/g,
|
||||||
enricher: DhDualityRollEnricher
|
enricher: DhDualityRollEnricher
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^@Effect\[(.*)\]$/g,
|
pattern: /^@Effect\[(.*)\]({.*})?$/g,
|
||||||
enricher: DhEffectEnricher
|
enricher: DhEffectEnricher
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^@Template\[(.*)\]$/g,
|
pattern: /^@Template\[(.*)\]({.*})?$/g,
|
||||||
enricher: DhTemplateEnricher
|
enricher: DhTemplateEnricher
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@ export const capitalize = string => {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function rollCommandToJSON(text) {
|
export function rollCommandToJSON(text, raw) {
|
||||||
if (!text) return {};
|
if (!text) return {};
|
||||||
|
|
||||||
|
const flavorMatch = raw?.match(/{(.*)}$/);
|
||||||
|
const flavor = flavorMatch ? flavorMatch[1] : null;
|
||||||
|
|
||||||
// Match key="quoted string" OR key=unquotedValue
|
// Match key="quoted string" OR key=unquotedValue
|
||||||
const PAIR_RE = /(\w+)=("(?:[^"\\]|\\.)*"|\S+)/g;
|
const PAIR_RE = /(\w+)=("(?:[^"\\]|\\.)*"|\S+)/g;
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
@ -28,7 +31,7 @@ export function rollCommandToJSON(text) {
|
||||||
}
|
}
|
||||||
result[key] = value;
|
result[key] = value;
|
||||||
}
|
}
|
||||||
return Object.keys(result).length > 0 ? result : null;
|
return Object.keys(result).length > 0 ? { result, flavor } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCommandTarget = (options = {}) => {
|
export const getCommandTarget = (options = {}) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue