Correction compendiums
This commit is contained in:
+42
-1
@@ -27,7 +27,9 @@ import { CDECharacterSheet, CDENpcSheet } from "./ui/sheets/actors/index.js"
|
||||
import { CDEItemSheet, CDEKungfuSheet, CDESpellSheet, CDESupernaturalSheet, CDEWeaponSheet, CDEArmorSheet, CDESanheiSheet, CDEIngredientSheet } from "./ui/sheets/items/index.js"
|
||||
import { CDELoksyuApp } from "./ui/apps/loksyu-app.js"
|
||||
import { CDETinjiApp } from "./ui/apps/tinji-app.js"
|
||||
import { CDEWheelApp } from "./ui/apps/wheel-app.js"
|
||||
import { injectRollActions, refreshAllRollActions } from "./ui/roll-actions.js"
|
||||
import { CDECombat } from "./documents/combat.js"
|
||||
|
||||
Hooks.once("i18nInit", preLocalizeConfig)
|
||||
|
||||
@@ -39,7 +41,9 @@ Hooks.once("init", async () => {
|
||||
game.system.CONST = { MAGICS, SUBTYPES }
|
||||
|
||||
// Expose standalone apps globally for macros
|
||||
game.cde = { CDELoksyuApp, CDETinjiApp }
|
||||
game.cde = { CDELoksyuApp, CDETinjiApp, CDEWheelApp }
|
||||
|
||||
CONFIG.Combat.documentClass = CDECombat
|
||||
|
||||
CONFIG.Actor.dataModels = {
|
||||
[ACTOR_TYPES.character]: CharacterDataModel,
|
||||
@@ -126,6 +130,7 @@ Hooks.once("init", async () => {
|
||||
|
||||
Hooks.once("ready", async () => {
|
||||
await migrateIfNeeded()
|
||||
CDEWheelApp.registerHooks()
|
||||
})
|
||||
|
||||
/** Add Loksyu + Tin Ji quick-access buttons to the chat panel (FoundryVTT v13) */
|
||||
@@ -145,12 +150,16 @@ Hooks.on("renderChatLog", (_app, html) => {
|
||||
<button type="button" class="cde-chat-btn cde-chat-btn--tinji">
|
||||
<i class="fas fa-star"></i> ${game.i18n.localize("CDE.TinJi2")}
|
||||
</button>
|
||||
<button type="button" class="cde-chat-btn cde-chat-btn--wheel">
|
||||
<i class="fas fa-circle-notch"></i> ${game.i18n.localize("CDE.InitiativeWheel")}
|
||||
</button>
|
||||
`
|
||||
|
||||
// Use event delegation to avoid being swallowed by Foundry's own handlers
|
||||
wrapper.addEventListener("click", (ev) => {
|
||||
if (ev.target.closest(".cde-chat-btn--loksyu")) CDELoksyuApp.open()
|
||||
if (ev.target.closest(".cde-chat-btn--tinji")) CDETinjiApp.open()
|
||||
if (ev.target.closest(".cde-chat-btn--wheel")) CDEWheelApp.open()
|
||||
})
|
||||
|
||||
// Insert before the chat form — works on v12 and v13
|
||||
@@ -173,3 +182,35 @@ Hooks.on("updateSetting", setting => {
|
||||
refreshAllRollActions()
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* When an actor's initiative changes (via +/- buttons on the sheet),
|
||||
* sync the corresponding combatant in the active combat.
|
||||
*/
|
||||
Hooks.on("updateActor", (actor, diff) => {
|
||||
if (!foundry.utils.hasProperty(diff, "system.initiative")) return
|
||||
if (!game.combat) return
|
||||
const initiative = actor.system.initiative
|
||||
const combatant = game.combat.combatants.find(c => c.actor?.id === actor.id)
|
||||
if (combatant && combatant.initiative !== initiative) {
|
||||
combatant.update({ initiative }).catch(() => {})
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* When a combatant's initiative changes (via wheel action buttons),
|
||||
* sync the actor's system.initiative to match.
|
||||
* Uses setTimeout to defer until after Foundry's update chain resolves,
|
||||
* avoiding concurrent #recordPreviousState errors on the combat document.
|
||||
*/
|
||||
Hooks.on("updateCombatant", (combatant, diff) => {
|
||||
if (!("initiative" in diff)) return
|
||||
const initiative = combatant.initiative
|
||||
if (initiative == null) return
|
||||
setTimeout(() => {
|
||||
const actor = combatant.actor
|
||||
if (actor && actor.system?.initiative !== initiative) {
|
||||
actor.update({ "system.initiative": initiative }).catch(() => {})
|
||||
}
|
||||
}, 0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user