Nouvelles corrections sur la fiche
This commit is contained in:
@@ -2,6 +2,7 @@ export { default as AwECharacterSheet } from "./sheets/character-sheet.mjs"
|
||||
export { default as AwECreatureSheet } from "./sheets/creature-sheet.mjs"
|
||||
export { default as AwEAbilitySheet } from "./sheets/ability-sheet.mjs"
|
||||
export { default as AwEFieldSheet } from "./sheets/field-sheet.mjs"
|
||||
export { default as AwESpecializationSheet } from "./sheets/specialization-sheet.mjs"
|
||||
export { default as AwEArchetypeSheet } from "./sheets/archetype-sheet.mjs"
|
||||
export { default as AwEBackgroundSheet } from "./sheets/background-sheet.mjs"
|
||||
export { default as AwEKitSheet } from "./sheets/kit-sheet.mjs"
|
||||
|
||||
@@ -78,19 +78,39 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
case "main":
|
||||
context.tab = context.tabs.main
|
||||
context.abilities = doc.itemTypes.ability.map(item => ({
|
||||
...item,
|
||||
id: item.id,
|
||||
uuid: item.uuid,
|
||||
name: item.name,
|
||||
img: item.img,
|
||||
system: item.system,
|
||||
costLabel: game.i18n.localize(SYSTEM.ABILITY_COST[item.system.cost]?.label ?? item.system.cost)
|
||||
}))
|
||||
break
|
||||
case "biography":
|
||||
context.tab = context.tabs.biography
|
||||
context.fields = doc.itemTypes.field.map(item => ({
|
||||
...item,
|
||||
id: item.id,
|
||||
uuid: item.uuid,
|
||||
name: item.name,
|
||||
img: item.img,
|
||||
system: item.system,
|
||||
keyAttrLabel: game.i18n.localize(SYSTEM.ATTRIBUTES[item.system.keyAttribute]?.label ?? item.system.keyAttribute),
|
||||
keyAttr2Label: item.system.keyAttribute2
|
||||
? game.i18n.localize(SYSTEM.ATTRIBUTES[item.system.keyAttribute2]?.label ?? item.system.keyAttribute2)
|
||||
: null
|
||||
}))
|
||||
context.specializations = (doc.itemTypes.specialization ?? []).map(item => {
|
||||
const fieldMatch = doc.itemTypes.field.some(f =>
|
||||
AwECharacterSheet.#slugify(f.name) === AwECharacterSheet.#slugify(item.system.fieldName)
|
||||
)
|
||||
const attrOverrideLabel = item.system.keyAttributeOverride
|
||||
? game.i18n.localize(SYSTEM.ATTRIBUTES[item.system.keyAttributeOverride]?.label ?? item.system.keyAttributeOverride)
|
||||
: null
|
||||
return {
|
||||
id: item.id, uuid: item.uuid, name: item.name, img: item.img, system: item.system,
|
||||
fieldMatch, attrOverrideLabel
|
||||
}
|
||||
})
|
||||
context.archetypes = doc.itemTypes.archetype
|
||||
context.backgrounds = doc.itemTypes.background
|
||||
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
|
||||
@@ -123,8 +143,8 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
/** @override */
|
||||
async _onDropItem(item) {
|
||||
if (!item) return
|
||||
// field/background: max 1 (replace existing); archetype: multiple allowed
|
||||
if (item.type === "field" || item.type === "background") {
|
||||
// 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()
|
||||
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
|
||||
@@ -197,6 +217,7 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
|
||||
/**
|
||||
* Roll the key attribute check from a Field item.
|
||||
* If a matching Specialization has a keyAttributeOverride, it takes priority.
|
||||
* @param {PointerEvent} event The triggering event.
|
||||
* @param {HTMLElement} target The target element.
|
||||
*/
|
||||
@@ -204,7 +225,23 @@ export default class AwECharacterSheet extends AwEActorSheet {
|
||||
const itemId = target.closest("[data-item-id]")?.dataset.itemId
|
||||
const item = this.document.items.get(itemId)
|
||||
if (!item) return
|
||||
const attrId = target.dataset.attributeId ?? item.system.keyAttribute
|
||||
await this.document.rollAttribute(attrId)
|
||||
|
||||
// Check for a specialization that matches this field and overrides the key attribute
|
||||
const spec = this.document.itemTypes.specialization?.find(s =>
|
||||
AwECharacterSheet.#slugify(s.system.fieldName) === AwECharacterSheet.#slugify(item.name)
|
||||
)
|
||||
const attrId = spec?.system.keyAttributeOverride
|
||||
|| target.dataset.attributeId
|
||||
|| item.system.keyAttribute
|
||||
|
||||
await this.document.rollAttribute(attrId, {
|
||||
sourceItemName: item.name,
|
||||
sourceItemImg: item.img
|
||||
})
|
||||
}
|
||||
|
||||
/** 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, "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,7 @@ export default class AwEFieldSheet extends AwEItemSheet {
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["field"],
|
||||
position: { width: 620 },
|
||||
window: { contentClasses: ["field-content"] },
|
||||
actions: {
|
||||
addSpecialization: AwEFieldSheet.#onAddSpecialization,
|
||||
removeSpecialization: AwEFieldSheet.#onRemoveSpecialization
|
||||
}
|
||||
window: { contentClasses: ["field-content"] }
|
||||
}
|
||||
|
||||
/** @override */
|
||||
@@ -18,29 +14,4 @@ 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 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import AwEItemSheet from "./base-item-sheet.mjs"
|
||||
import { SYSTEM } from "../../config/system.mjs"
|
||||
|
||||
export default class AwESpecializationSheet extends AwEItemSheet {
|
||||
/** @override */
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["specialization"],
|
||||
position: { width: 620 },
|
||||
window: { contentClasses: ["specialization-content"] }
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: "systems/fvtt-adventures-with-emmy/templates/specialization.hbs"
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options)
|
||||
context.attributeChoices = {
|
||||
"": "—",
|
||||
...Object.fromEntries(Object.values(SYSTEM.ATTRIBUTES).map(a => [a.id, game.i18n.localize(a.label)]))
|
||||
}
|
||||
return context
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user