ENhance actor sheet with roll messages

This commit is contained in:
2026-03-07 16:09:00 +01:00
parent 8dec307ced
commit 63da2ef664
32 changed files with 888 additions and 22 deletions
+63 -3
View File
@@ -20,7 +20,13 @@ export default class AwECharacterSheet extends AwEActorSheet {
flowPointsPlus: AwECharacterSheet.#onFlowPointsPlus,
flowPointsMinus: AwECharacterSheet.#onFlowPointsMinus,
rollField: AwECharacterSheet.#onRollField,
rollWeapon: AwECharacterSheet.#onRollWeapon
rollWeapon: AwECharacterSheet.#onRollWeapon,
rollDamage: AwECharacterSheet.#onRollDamage,
toggleCondition: AwECharacterSheet.#onToggleCondition,
useKit: AwECharacterSheet.#onUseKit,
useAbility: AwECharacterSheet.#onUseAbility,
dailyReset: AwECharacterSheet.#onDailyReset,
longRest: AwECharacterSheet.#onLongRest
}
}
@@ -84,7 +90,15 @@ export default class AwECharacterSheet extends AwEActorSheet {
name: item.name,
img: item.img,
system: item.system,
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost)
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost),
usedToday: item.system.usedToday
}))
context.hasUsedAbilities = context.abilities.some(a => a.usedToday)
context.conditions = Object.values(SYSTEM.CONDITIONS).map(c => ({
...c,
label: game.i18n.localize(c.label),
img: `systems/fvtt-adventures-with-emmy/assets/conditions/${c.id}.svg`,
active: doc.statuses.has(c.id)
}))
break
case "biography":
@@ -147,7 +161,10 @@ export default class AwECharacterSheet extends AwEActorSheet {
// field/background/specialization: max 1 (replace existing); archetype: multiple allowed
if (item.type === "field" || item.type === "background" || item.type === "specialization") {
const existing = this.document.itemTypes[item.type]
if (existing.length > 0) await existing[0].delete()
if (existing.length > 0) {
ui.notifications.info(game.i18n.format("AWEMMY.Character.ItemReplaced", { name: existing[0].name }))
await existing[0].delete()
}
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
}
if (item.type === "archetype") {
@@ -248,8 +265,51 @@ export default class AwECharacterSheet extends AwEActorSheet {
await this.document.rollWeapon(item)
}
static async #onRollDamage(event, target) {
const itemId = target.closest("[data-item-id]")?.dataset.itemId
const item = this.document.items.get(itemId)
if (!item) return
await this.document.rollDamage(item)
}
/** Slugify a string for loose name matching (lowercase, trim, spaces→dash, strip non-alphanum). */
static #slugify(str) {
return (str ?? "").toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "")
}
static async #onToggleCondition(event, target) {
const conditionId = target.dataset.conditionId
await this.document.toggleStatusEffect(conditionId)
}
static async #onUseKit(event, target) {
const itemId = target.closest("[data-item-id]")?.dataset.itemId
await this.document.useKit(itemId)
}
static async #onUseAbility(event, target) {
const itemId = target.closest("[data-item-id]")?.dataset.itemId
await this.document.useAbility(itemId)
}
static async #onDailyReset(event, target) {
const actor = this.document
const dailyAbilities = actor.itemTypes.ability.filter(i => i.system.usedToday)
if (!dailyAbilities.length) return
const updates = dailyAbilities.map(i => ({ _id: i.id, "system.usedToday": false }))
await actor.updateEmbeddedDocuments("Item", updates)
ui.notifications.info(game.i18n.localize("AWEMMY.Ability.DailyResetDone"))
}
static async #onLongRest(event, target) {
const actor = this.document
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("AWEMMY.Rest.LongRest") },
content: `<p>${game.i18n.format("AWEMMY.Rest.LongRestConfirm", { name: actor.name })}</p>`,
yes: { label: game.i18n.localize("AWEMMY.Rest.Rest"), icon: "fa-solid fa-moon" },
no: { label: game.i18n.localize("AWEMMY.Rest.Cancel") }
})
if (!confirmed) return
await actor.longRest()
}
}