Add roll windows from actor sheet

This commit is contained in:
2026-03-15 23:20:32 +01:00
parent 82fddb0cb3
commit 49347370c7
57 changed files with 6372 additions and 184 deletions

View File

@@ -5,6 +5,8 @@ import * as models from "./module/models/_module.mjs"
import * as documents from "./module/documents/_module.mjs"
import * as applications from "./module/applications/_module.mjs"
import OathHammerUtils from "./module/utils.mjs"
import OathHammerWeaponDialog from "./module/applications/weapon-dialog.mjs"
import { rollWeaponDamage } from "./module/rolls.mjs"
Hooks.once("init", function () {
console.info(SYSTEM.ASCII)
@@ -32,7 +34,6 @@ Hooks.once("init", function () {
"magic-item": models.OathHammerMagicItem,
trait: models.OathHammerTrait,
oath: models.OathHammerOath,
lineage: models.OathHammerLineage,
"class": models.OathHammerClass,
building: models.OathHammerBuilding
}
@@ -59,7 +60,6 @@ Hooks.once("init", function () {
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerMagicItemSheet, { types: ["magic-item"], makeDefault: true, label: "OATHHAMMER.Sheet.MagicItem" })
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerTraitSheet, { types: ["trait"], makeDefault: true, label: "OATHHAMMER.Sheet.Trait" })
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerOathSheet, { types: ["oath"], makeDefault: true, label: "OATHHAMMER.Sheet.Oath" })
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerLineageSheet, { types: ["lineage"], makeDefault: true, label: "OATHHAMMER.Sheet.Lineage" })
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerClassSheet, { types: ["class"], makeDefault: true, label: "OATHHAMMER.Sheet.Class" })
foundry.documents.collections.Items.registerSheet("fvtt-oath-hammer", applications.OathHammerBuildingSheet, { types: ["building"], makeDefault: true, label: "OATHHAMMER.Sheet.Building" })
@@ -70,6 +70,39 @@ Hooks.once("init", function () {
console.info("Oath Hammer | System Initialized")
})
Hooks.once("ready", function () {
Hooks.once("ready", async function () {
console.info("Oath Hammer | System Ready")
// Migration: remove orphaned items with removed types (lineage → actor field, ability → trait)
const removedTypes = new Set(["lineage", "ability"])
for (const actor of game.actors) {
const invalidItems = actor._source.items?.filter(i => removedTypes.has(i.type)) ?? []
if (invalidItems.length) {
console.info(`Oath Hammer | Migrating ${actor.name}: removing ${invalidItems.length} obsolete item(s)`)
await actor.deleteEmbeddedDocuments("Item", invalidItems.map(i => i._id))
}
}
for (const id of game.items.invalidDocumentIds) {
const item = game.items.getInvalid(id)
if (item && removedTypes.has(item._source.type)) {
console.info(`Oath Hammer | Deleting world item: ${item._source.name} (${item._source.type})`)
await item.delete()
}
}
})
// Handle "Roll Damage" button in weapon attack chat cards
Hooks.on("renderChatMessageHTML", (message, html) => {
const btn = html.querySelector("[data-action=\"rollWeaponDamage\"]")
if (!btn) return
btn.addEventListener("click", async () => {
const flagData = message.getFlag("fvtt-oath-hammer", "weaponAttack")
if (!flagData) return
const { actorUuid, weaponUuid, attackSuccesses } = flagData
const actor = await fromUuid(actorUuid)
const weapon = await fromUuid(weaponUuid)
if (!actor || !weapon) return ui.notifications.warn(game.i18n.localize("OATHHAMMER.Roll.NoActor"))
const opts = await OathHammerWeaponDialog.promptDamage(actor, weapon, attackSuccesses ?? 0)
if (opts) await rollWeaponDamage(actor, weapon, opts)
})
})