ENhance actor sheet with roll messages
This commit is contained in:
@@ -86,6 +86,8 @@ export default class AwEActorSheet extends HandlebarsApplicationMixin(foundry.ap
|
||||
*/
|
||||
async _onRoll(event) {
|
||||
if (this.isEditMode) return
|
||||
// Skip if the element has a registered data-action (handled by the action system)
|
||||
if (event.currentTarget.dataset.action) return
|
||||
const attributeId = event.currentTarget.dataset.attributeId
|
||||
if (!attributeId) return
|
||||
await this.document.rollAttribute(attributeId)
|
||||
@@ -233,6 +235,7 @@ export default class AwEActorSheet extends HandlebarsApplicationMixin(foundry.ap
|
||||
static async #onItemDelete(event, target) {
|
||||
const itemUuid = target.getAttribute("data-item-uuid")
|
||||
const item = await fromUuid(itemUuid)
|
||||
if (!item) return
|
||||
await item.deleteDialog()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export default class AwECreatureSheet extends AwEActorSheet {
|
||||
const context = await super._prepareContext()
|
||||
context.tabs = this.#getTabs()
|
||||
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
||||
this.document.system.description, { async: true }
|
||||
this.document.system.description ?? "", { async: true }
|
||||
)
|
||||
return context
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user