refactor: extract inline HTML to templates, split oversized files, fix bugs
- Extract all inline HTML from JS into 21 Handlebars templates (chat/, dialogs/, ui/) - Split utils.mjs (1507) into barrel + helpers.mjs, combat.mjs, d30.mjs - Split roll.mjs (1632) into barrel + roll-base.mjs, roll-prompt.mjs, roll-combat.mjs, roll-damage.mjs - Split lethal-fantasy.mjs (1426) into bootstrap + chat-reaction.mjs - Fix: missing async on injectDiceTray (free-roll.mjs:29 SyntaxError) - Fix: weapon._id fallback for deserialized chat-message weapon objects - Fix: missing await on rollModifier.evaluate() calls in roll-combat.mjs - Fix: choices→choicesList ReferenceError in utils.mjs - Fix: add 12 missing i18n keys (chooseWeapon, chooseSave, attackRoll, etc.) - Fix: restore sideLabel in bonus-die-select.hbs - Clean: remove dead messageContent param, console.log→log() - Style: barrel files preserve existing import paths
This commit is contained in:
@@ -16,7 +16,7 @@ const DICE_TYPES = ["d4", "d6", "d8", "d10", "d12", "d20", "d30"]
|
||||
* @param {Application} _chatLog
|
||||
* @param {HTMLElement|jQuery} html
|
||||
*/
|
||||
export function injectDiceTray(_chatLog, html) {
|
||||
export async function injectDiceTray(_chatLog, html) {
|
||||
const el = (html instanceof HTMLElement) ? html : (html[0] ?? html)
|
||||
if (!el?.querySelector) return
|
||||
if (el.querySelector(".lf-dice-tray")) return
|
||||
@@ -24,27 +24,14 @@ export function injectDiceTray(_chatLog, html) {
|
||||
const bar = document.createElement("div")
|
||||
bar.className = "lf-dice-tray"
|
||||
|
||||
const diceButtons = DICE_TYPES.map(d =>
|
||||
`<button type="button" class="lf-dt-die-btn" data-die="${d}" title="${d.toUpperCase()}">${d.toUpperCase()}</button>`
|
||||
).join("")
|
||||
|
||||
const countOptions = Array.from({ length: 9 }, (_, i) =>
|
||||
`<option value="${i + 1}">${i + 1}</option>`
|
||||
).join("")
|
||||
|
||||
bar.innerHTML = `
|
||||
<div class="lf-dt-row">
|
||||
<span class="lf-dt-label"><i class="fa-solid fa-dice"></i></span>
|
||||
<select class="lf-dt-count" title="${game.i18n.localize("LETHALFANTASY.DiceTray.CountTitle")}">
|
||||
${countOptions}
|
||||
</select>
|
||||
<div class="lf-dt-dice">${diceButtons}</div>
|
||||
<label class="lf-dt-explode-label" title="${game.i18n.localize("LETHALFANTASY.DiceTray.ExplodeTitle")}">
|
||||
<input type="checkbox" class="lf-dt-explode" />
|
||||
<i class="fa-solid fa-explosion"></i>
|
||||
</label>
|
||||
</div>
|
||||
`
|
||||
const diceButtons = DICE_TYPES.map(d => ({ value: d, label: d.toUpperCase() }))
|
||||
const countOptions = Array.from({ length: 9 }, (_, i) => i + 1)
|
||||
bar.innerHTML = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/ui/dice-tray.hbs", {
|
||||
countTitle: game.i18n.localize("LETHALFANTASY.DiceTray.CountTitle"),
|
||||
explodeTitle: game.i18n.localize("LETHALFANTASY.DiceTray.ExplodeTitle"),
|
||||
countOptions,
|
||||
diceButtons
|
||||
})
|
||||
|
||||
bar.addEventListener("click", async ev => {
|
||||
const btn = ev.target.closest(".lf-dt-die-btn")
|
||||
@@ -113,33 +100,19 @@ export async function rollFreeDie(dieType, count = 1, explode = false) {
|
||||
}
|
||||
}
|
||||
|
||||
const resultHtml = dieChips.map(chip => {
|
||||
const isMax = !chip.exploded && chip.value === sides
|
||||
const isMin = chip.value === 1
|
||||
const explodeIcon = chip.exploded ? `<i class="fa-solid fa-burst lf-dt-explode-icon"></i>` : ""
|
||||
const classes = ["lf-frc-die-chip", isMax ? "lf-frc-max" : "", isMin ? "lf-frc-min" : ""].filter(Boolean).join(" ")
|
||||
return `<div class="${classes}">
|
||||
<span class="lf-frc-die-type">${chip.label}</span>
|
||||
<span class="lf-frc-die-sep">→</span>
|
||||
<span class="lf-frc-die-val">${chip.value}${explodeIcon}</span>
|
||||
</div>`
|
||||
}).join("")
|
||||
const dieChipsWithClasses = dieChips.map(chip => ({
|
||||
...chip,
|
||||
classes: ["lf-frc-die-chip", !chip.exploded && chip.value === sides ? "lf-frc-max" : "", chip.value === 1 ? "lf-frc-min" : ""].filter(Boolean).join(" ")
|
||||
}))
|
||||
|
||||
const totalLabel = game.i18n.localize("LETHALFANTASY.Label.total").toUpperCase()
|
||||
const content = `
|
||||
<div class="lf-free-roll-card">
|
||||
<div class="lf-frc-header">
|
||||
<i class="fa-solid fa-dice"></i>
|
||||
<span class="lf-frc-title-text">${game.i18n.localize("LETHALFANTASY.DiceTray.ChatTitle")}</span>
|
||||
<span class="lf-frc-badge">${label}</span>
|
||||
</div>
|
||||
<div class="lf-frc-dice">${resultHtml}</div>
|
||||
<div class="lf-frc-total-bar">
|
||||
<span class="lf-frc-total-label">${totalLabel}</span>
|
||||
<span class="lf-frc-total-value">${total}</span>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
const content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-lethal-fantasy/templates/chat/free-roll-card.hbs", {
|
||||
titleText: game.i18n.localize("LETHALFANTASY.DiceTray.ChatTitle"),
|
||||
badge: label,
|
||||
dieChips: dieChipsWithClasses,
|
||||
totalLabel,
|
||||
total
|
||||
})
|
||||
|
||||
const rollMode = game.settings.get("core", "rollMode")
|
||||
// Normalize old-style rollMode keys (v12/v13) to new-style (v14), fallback to "public"
|
||||
|
||||
Reference in New Issue
Block a user