Nouvelles corrections sur la fiche

This commit is contained in:
2026-03-06 11:10:48 +01:00
parent badfea1166
commit 65dc626380
8 changed files with 96 additions and 22 deletions
@@ -146,6 +146,15 @@ export default class AwEActorSheet extends HandlebarsApplicationMixin(foundry.ap
*/
_onDragStart(event) {
if ("link" in event.target.dataset) return
const el = event.currentTarget
const itemId = el.dataset.itemId
const itemUuid = el.dataset.itemUuid
if (!itemUuid && !itemId) return
const item = itemUuid
? fromUuidSync(itemUuid)
: this.document.items.get(itemId)
if (!item) return
event.dataTransfer.setData("text/plain", JSON.stringify({ type: "Item", uuid: item.uuid }))
}
/**
+27 -5
View File
@@ -83,6 +83,9 @@ export default class AwECharacterSheet extends AwEActorSheet {
break
case "biography":
context.tab = context.tabs.biography
context.fields = doc.itemTypes.field
context.archetypes = doc.itemTypes.archetype
context.backgrounds = doc.itemTypes.background
context.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
doc.system.description, { async: true }
)
@@ -102,7 +105,7 @@ export default class AwECharacterSheet extends AwEActorSheet {
/** @override */
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
if (!this.isEditable) return
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event)
if (data.type === "Item") {
const item = await fromUuid(data.uuid)
@@ -110,13 +113,29 @@ 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") {
const existing = this.document.itemTypes[item.type]
if (existing.length > 0) await existing[0].delete()
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
}
if (item.type === "archetype") {
return this.document.createEmbeddedDocuments("Item", [item.toObject()])
}
return super._onDropItem(item)
}
/**
* Create a new ability item.
* @param {Event} event - The triggering event.
* @param {HTMLElement} target - The target element.
*/
static #onCreateAbility(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: "New Ability", type: "ability" }])
const type = "ability"
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
}
/**
@@ -125,7 +144,8 @@ export default class AwECharacterSheet extends AwEActorSheet {
* @param {HTMLElement} target - The target element.
*/
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: "New Weapon", type: "weapon" }])
const type = "weapon"
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
}
/**
@@ -134,7 +154,8 @@ export default class AwECharacterSheet extends AwEActorSheet {
* @param {HTMLElement} target - The target element.
*/
static #onCreateKit(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: "New Kit", type: "kit" }])
const type = "kit"
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
}
/**
@@ -143,7 +164,8 @@ export default class AwECharacterSheet extends AwEActorSheet {
* @param {HTMLElement} target - The target element.
*/
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: "New Equipment", type: "equipment" }])
const type = "equipment"
this.document.createEmbeddedDocuments("Item", [{ name: CONFIG.Item.documentClass.defaultName({ type }), type }])
}
/**
+6
View File
@@ -3,4 +3,10 @@ export default class AwEItem extends Item {
prepareData() {
super.prepareData()
}
/** Return "New Ability", "New Weapon", etc. based on item type. */
static defaultName(context = {}) {
const typeLabel = game.i18n.localize(CONFIG.Item.typeLabels[context.type] ?? "Item")
return `New ${typeLabel}`
}
}
-3
View File
@@ -11,10 +11,7 @@ export default class AwECharacter extends foundry.abstract.TypeDataModel {
// Identity
schema.pronouns = new fields.StringField({ initial: "", required: false, nullable: true })
schema.fieldName = new fields.StringField({ initial: "", required: false, nullable: true })
schema.specialization = new fields.StringField({ initial: "", required: false, nullable: true })
schema.archetypeName = new fields.StringField({ initial: "", required: false, nullable: true })
schema.backgroundName = new fields.StringField({ initial: "", required: false, nullable: true })
// Core stats
schema.level = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1, max: 10,