diff --git a/daggerheart.mjs b/daggerheart.mjs index da04334c..2c5d97b6 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -2,14 +2,14 @@ import { SYSTEM } from './module/config/system.mjs'; import * as applications from './module/applications/_module.mjs'; import * as models from './module/data/_module.mjs'; import * as documents from './module/documents/_module.mjs'; +import * as dice from './module/dice/_module.mjs'; import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs'; import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs'; import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs'; import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs'; import { DualityRollColor } from './module/data/settings/Appearance.mjs'; import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs'; -import { enrichedDualityRoll, renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs'; -import { renderMeasuredTemplate } from './module/enrichers/TemplateEnricher.mjs'; +import { enrichedDualityRoll } from './module/enrichers/DualityRollEnricher.mjs'; import { registerCountdownHooks } from './module/data/countdowns.mjs'; import { handlebarsRegistration, @@ -20,14 +20,14 @@ import { placeables } from './module/canvas/_module.mjs'; import { registerRollDiceHooks } from './module/dice/dhRoll.mjs'; import { registerDHActorHooks } from './module/documents/actor.mjs'; import './node_modules/@yaireo/tagify/dist/tagify.css'; -import { renderDamageButton } from './module/enrichers/DamageEnricher.mjs'; Hooks.once('init', () => { CONFIG.DH = SYSTEM; game.system.api = { applications, models, - documents + documents, + dice }; CONFIG.TextEditor.enrichers.push(...enricherConfig); @@ -49,6 +49,11 @@ Hooks.once('init', () => { DamageRoll: DamageRoll }; + CONFIG.Dice.terms = { + ...CONFIG.Dice.terms, + DualityDie + }; + CONFIG.Dice.rolls = [...CONFIG.Dice.rolls, ...[DHRoll, DualityRoll, D20Roll, DamageRoll]]; CONFIG.MeasuredTemplate.objectClass = placeables.DhMeasuredTemplate; diff --git a/lang/en.json b/lang/en.json index fc51a610..9c7bae99 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1339,6 +1339,7 @@ "quantity": "Quantity", "range": "Range", "recovery": "Recovery", + "rerollThing": "Reroll {thing}", "resource": "Resource", "roll": "Roll", "rollAll": "Roll All", diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 26db4d76..3d29abf1 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -1,3 +1,5 @@ +import { getDiceSoNicePresets } from '../../config/generalConfig.mjs'; + export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog { constructor(options) { super(options); @@ -313,47 +315,50 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo action.use(event); }; - //Reroll Functionality rerollEvent = async (event, message) => { - let DieTerm = foundry.dice.terms.Die; - let dicetype = event.target.value; + const target = event.target.closest('button[data-die-index]'); let originalRoll_parsed = message.rolls.map(roll => JSON.parse(roll))[0]; - console.log('Parsed Map:', originalRoll_parsed); - let originalRoll = Roll.fromData(originalRoll_parsed); - let diceIndex; - console.log('Dice to reroll is:', dicetype, ', and the message id is:', message._id, originalRoll_parsed); - console.log('Original Roll Terms:', originalRoll.terms); - switch (dicetype) { - case 'hope': { - diceIndex = 0; //Hope Die - break; + let parsedRoll = game.system.api.dice.DualityRoll.fromData({ ...originalRoll_parsed, evaluated: false }); + const term = parsedRoll.terms[target.dataset.dieIndex]; + await term.reroll(`/r1=${term.total}`); + if (game.modules.get('dice-so-nice')?.active) { + const diceSoNiceRoll = { + _evaluated: true, + dice: [new Die({ ...term, faces: term._faces, results: term.results.filter(x => !x.rerolled) })], + options: { appearance: {} } + }; + const diceSoNicePresets = getDiceSoNicePresets(); + switch (target.dataset.type) { + case 'hope': + diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.hope }; + break; + case 'fear': + diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.fear }; + break; + case 'advantage': + diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.advantage }; + break; + case 'disadvantage': + diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.disadvantage }; + break; } - case 'fear': { - diceIndex = 2; //Fear Die - break; + + await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true); + } + + await parsedRoll.evaluate(); + + const newRoll = game.system.api.dice.DualityRoll.postEvaluate(parsedRoll, { + targets: message.system.targets, + roll: { + advantage: message.system.roll.advantage?.type, + difficulty: message.system.roll.difficulty ? Number(message.system.roll.difficulty) : null } - default: - ui.notifications.warn('Invalid Dice type selected.'); - break; - } - let rollClone = originalRoll.clone(); - let rerolledTerm = originalRoll.terms[diceIndex]; - console.log('originalRoll:', originalRoll, 'rerolledTerm', rerolledTerm); - if (!(rerolledTerm instanceof DieTerm)) { - ui.notifications.error('Selected term is not a die.'); - return; - } - await rollClone.reroll({ allowStrings: true })[diceIndex]; - console.log(rollClone); - await rollClone.evaluate({ allowStrings: true }); - console.log(rollClone.result); - /* - const confirm = await foundry.applications.api.DialogV2.confirm({ - window: { title: 'Confirm Reroll' }, - content: `
You have rerolled your ${dicetype} die to ${rollClone.result}.
Apply this new roll?
` - }); - if (!confirm) return; - rollClone.toMessage({flavor: 'Selective reroll applied for ${dicetype}.'}); - console.log("Updated Roll",rollClone);*/ + }); + newRoll.extra = newRoll.extra.slice(2); + + await game.messages.get(message._id).update({ + 'system.roll': newRoll + }); }; } diff --git a/module/data/chat-message/adversaryRoll.mjs b/module/data/chat-message/adversaryRoll.mjs index 9210ef99..1e2d8da1 100644 --- a/module/data/chat-message/adversaryRoll.mjs +++ b/module/data/chat-message/adversaryRoll.mjs @@ -6,7 +6,7 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel { static defineSchema() { return { title: new fields.StringField(), - roll: new fields.DataField(), + roll: new fields.ObjectField(), targets: new fields.ArrayField( new fields.SchemaField({ id: new fields.StringField({}), diff --git a/module/dice/d20Roll.mjs b/module/dice/d20Roll.mjs index 95cba5ca..1bcf7348 100644 --- a/module/dice/d20Roll.mjs +++ b/module/dice/d20Roll.mjs @@ -147,7 +147,10 @@ export default class D20Roll extends DHRoll { const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion; target.hit = this.isCritical || roll.total >= difficulty; }); - } else if (config.roll.difficulty) data.success = roll.isCritical || roll.total >= config.roll.difficulty; + } else if (config.roll.difficulty) { + data.difficulty = config.roll.difficulty; + data.success = roll.isCritical || roll.total >= config.roll.difficulty; + } data.advantage = { type: config.roll.advantage, dice: roll.dAdvantage?.denomination, diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index 142f21e8..38a3a870 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -110,6 +110,13 @@ export default class DualityRoll extends D20Roll { return [...(hooks ?? []), 'Duality']; } + /** @inheritDoc */ + static fromData(data) { + data.terms[0].class = game.system.api.dice.DualityDie.name; + data.terms[2].class = game.system.api.dice.DualityDie.name; + return super.fromData(data); + } + createBaseDice() { if ( this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie && diff --git a/module/enrichers/DualityRollEnricher.mjs b/module/enrichers/DualityRollEnricher.mjs index dde82a48..70f376e7 100644 --- a/module/enrichers/DualityRollEnricher.mjs +++ b/module/enrichers/DualityRollEnricher.mjs @@ -48,7 +48,7 @@ function getDualityMessage(roll) { > ${label} - ${roll.difficulty || advantageLabel ? `(${[roll.difficulty, game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`)].filter(x => x).join(' ')})` : ''} + ${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''} `; diff --git a/styles/less/ui/chat/chat.less b/styles/less/ui/chat/chat.less index c2c72d48..5c646efc 100644 --- a/styles/less/ui/chat/chat.less +++ b/styles/less/ui/chat/chat.less @@ -44,6 +44,21 @@ &.duality { display: flex; gap: 0.25rem; + + > .roll { + background-image: none; + + .reroll-button { + border: none; + background: initial; + width: 42px; + + &:hover { + background: var(--button-background-color); + border: 1px solid var(--button-border-color); + } + } + } } // margin: 0; > .roll { @@ -52,6 +67,7 @@ justify-content: center; gap: 4px; margin-bottom: 4px; + .dice-container { display: flex; flex-direction: column; diff --git a/templates/ui/chat/duality-roll.hbs b/templates/ui/chat/duality-roll.hbs index a10928d8..0edf5788 100644 --- a/templates/ui/chat/duality-roll.hbs +++ b/templates/ui/chat/duality-roll.hbs @@ -38,11 +38,11 @@