Fix CSS issues and add omen re-roll function
This commit is contained in:
@@ -146,6 +146,67 @@ Hooks.on("renderChatMessageHTML", (message, element) => {
|
||||
})
|
||||
})
|
||||
|
||||
root.querySelectorAll(".mgne-omen-reroll-btn").forEach(btn => {
|
||||
btn.addEventListener("click", async () => {
|
||||
const actorId = btn.dataset.actorId
|
||||
const actor = game.actors.get(actorId)
|
||||
if (!actor) {
|
||||
ui.notifications.warn(game.i18n.localize("MGNE.Notification.ActorNotFound"))
|
||||
return
|
||||
}
|
||||
|
||||
const currentOmens = actor.system.omens?.current ?? 0
|
||||
if (currentOmens === 0) {
|
||||
ui.notifications.warn(game.i18n.localize("MGNE.Notification.NoOmensLeft"))
|
||||
return
|
||||
}
|
||||
|
||||
// Save original state for rollback
|
||||
const originalOmens = currentOmens
|
||||
|
||||
// Disable button and show loading state
|
||||
const originalInnerHTML = btn.innerHTML
|
||||
btn.disabled = true
|
||||
btn.innerHTML = '<i class="fa-solid fa-star"></i> ' + game.i18n.localize("MGNE.Common.Processing")
|
||||
|
||||
try {
|
||||
// Spend the omen
|
||||
await actor.update({ "system.omens.current": Math.max(0, currentOmens - 1) })
|
||||
|
||||
// Re-roll with the same parameters
|
||||
const abilityId = btn.dataset.abilityId
|
||||
const label = btn.dataset.label
|
||||
const baseDR = parseInt(btn.dataset.baseDr ?? "12", 10)
|
||||
const modifier = parseInt(btn.dataset.modifier ?? "0", 10)
|
||||
const rollType = btn.dataset.rollType ?? "check"
|
||||
const itemId = btn.dataset.itemId
|
||||
const item = itemId ? actor.items.get(itemId) : null
|
||||
|
||||
await MGNERoll.promptCheck({
|
||||
actor,
|
||||
abilityId,
|
||||
label,
|
||||
baseDR,
|
||||
modifier,
|
||||
rollType,
|
||||
item,
|
||||
})
|
||||
} catch (error) {
|
||||
// Rollback omen spend on error
|
||||
const currentOmensAfterError = actor.system.omens?.current ?? 0
|
||||
if (currentOmensAfterError < originalOmens) {
|
||||
await actor.update({ "system.omens.current": originalOmens })
|
||||
}
|
||||
ui.notifications.error(game.i18n.localize("MGNE.Notification.RollError"))
|
||||
console.error("Omen re-roll failed:", error)
|
||||
} finally {
|
||||
// Restore button state
|
||||
btn.disabled = false
|
||||
btn.innerHTML = originalInnerHTML
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
root.querySelectorAll(".mgne-apply-damage-select").forEach(select => {
|
||||
const isAllowed = game.user.isGM || message.isAuthor
|
||||
if (!isAllowed) {
|
||||
|
||||
Reference in New Issue
Block a user