First row of tests and fixes
This commit is contained in:
@@ -30,7 +30,9 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
|
||||
dragDrop: [{ dragSelector: "[data-drag]", dropSelector: null }],
|
||||
actions: {
|
||||
toggleSheet: AwEItemSheet.#onToggleSheet,
|
||||
editImage: AwEItemSheet.#onEditImage
|
||||
editImage: AwEItemSheet.#onEditImage,
|
||||
addTrait: AwEItemSheet.#onAddTrait,
|
||||
removeTrait: AwEItemSheet.#onRemoveTrait
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +79,16 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
|
||||
_onRender(context, options) {
|
||||
super._onRender(context, options)
|
||||
this.#dragDrop.forEach(d => d.bind(this.element))
|
||||
// Bind Enter key on tag input fields to trigger the addTrait/addSpecialization actions
|
||||
this.element.querySelectorAll("input.new-tag[data-action]").forEach(input => {
|
||||
input.addEventListener("keydown", event => {
|
||||
if (event.key !== "Enter") return
|
||||
event.preventDefault()
|
||||
const actionName = input.dataset.action
|
||||
const handler = this.options.actions?.[actionName]
|
||||
if (handler) handler.call(this, event, input)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// #region Drag-and-Drop Workflow
|
||||
@@ -182,4 +194,34 @@ export default class AwEItemSheet extends HandlebarsApplicationMixin(foundry.app
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Array field helpers (traits, specializations)
|
||||
/**
|
||||
* Handle adding a tag (trait, specialization) from the input field.
|
||||
* @param {PointerEvent|KeyboardEvent} event - The initiating event.
|
||||
* @param {HTMLElement} target - The input element.
|
||||
*/
|
||||
static async #onAddTrait(event, target) {
|
||||
const value = target.value.trim()
|
||||
if (!value) return
|
||||
const fieldName = target.dataset.field ?? "system.traits"
|
||||
const current = foundry.utils.getProperty(this.document, fieldName) ?? []
|
||||
await this.document.update({ [fieldName]: [...current, value] })
|
||||
target.value = ""
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle removing a tag (trait, specialization) from an array field.
|
||||
* @param {PointerEvent} event - The initiating click event.
|
||||
* @param {HTMLElement} target - The remove button.
|
||||
*/
|
||||
static async #onRemoveTrait(event, target) {
|
||||
const index = Number(target.dataset.index)
|
||||
const fieldName = target.dataset.field ?? "system.traits"
|
||||
const current = [...(foundry.utils.getProperty(this.document, fieldName) ?? [])]
|
||||
current.splice(index, 1)
|
||||
await this.document.update({ [fieldName]: current })
|
||||
}
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import AwEActorSheet from "./base-actor-sheet.mjs"
|
||||
import { SYSTEM } from "../../config/system.mjs"
|
||||
|
||||
export default class AwECharacterSheet extends AwEActorSheet {
|
||||
/** @override */
|
||||
@@ -23,6 +24,9 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
header: {
|
||||
template: "systems/fvtt-adventures-with-emmy/templates/character-header.hbs"
|
||||
},
|
||||
main: {
|
||||
template: "systems/fvtt-adventures-with-emmy/templates/character-main.hbs"
|
||||
},
|
||||
@@ -72,7 +76,10 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
switch (partId) {
|
||||
case "main":
|
||||
context.tab = context.tabs.main
|
||||
context.abilities = doc.itemTypes.ability
|
||||
context.abilities = doc.itemTypes.ability.map(item => ({
|
||||
...item,
|
||||
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost)
|
||||
}))
|
||||
break
|
||||
case "biography":
|
||||
context.tab = context.tabs.biography
|
||||
|
||||
@@ -5,7 +5,11 @@ export default class AwEFieldSheet extends AwEItemSheet {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["field"],
|
||||
position: { width: 620 },
|
||||
window: { contentClasses: ["field-content"] }
|
||||
window: { contentClasses: ["field-content"] },
|
||||
actions: {
|
||||
addSpecialization: AwEFieldSheet.#onAddSpecialization,
|
||||
removeSpecialization: AwEFieldSheet.#onRemoveSpecialization
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
@@ -14,4 +18,29 @@ export default class AwEFieldSheet extends AwEItemSheet {
|
||||
template: "systems/fvtt-adventures-with-emmy/templates/field.hbs"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle adding a specialization.
|
||||
* @param {PointerEvent} event - The initiating event.
|
||||
* @param {HTMLElement} target - The input element.
|
||||
*/
|
||||
static async #onAddSpecialization(event, target) {
|
||||
const value = target.value.trim()
|
||||
if (!value) return
|
||||
const current = this.document.system.specializations ?? []
|
||||
await this.document.update({ "system.specializations": [...current, value] })
|
||||
target.value = ""
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle removing a specialization.
|
||||
* @param {PointerEvent} event - The initiating click event.
|
||||
* @param {HTMLElement} target - The remove button.
|
||||
*/
|
||||
static async #onRemoveSpecialization(event, target) {
|
||||
const index = Number(target.dataset.index)
|
||||
const current = [...(this.document.system.specializations ?? [])]
|
||||
current.splice(index, 1)
|
||||
await this.document.update({ "system.specializations": current })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user