From 65dc626380ed6a2a5ecd34852e2ac2029824c4b5 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Fri, 6 Mar 2026 11:10:48 +0100 Subject: [PATCH] Nouvelles corrections sur la fiche --- lang/en.json | 3 + .../applications/sheets/base-actor-sheet.mjs | 9 +++ .../applications/sheets/character-sheet.mjs | 32 +++++++++-- module/documents/item.mjs | 6 ++ module/models/character.mjs | 3 - templates/character-biography.hbs | 57 +++++++++++++++---- templates/character-equipment.hbs | 6 +- templates/character-main.hbs | 2 +- 8 files changed, 96 insertions(+), 22 deletions(-) diff --git a/lang/en.json b/lang/en.json index 1c4bcc6..202aa8e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -80,6 +80,9 @@ "AWEMMY.Character.Notes": "Notes", "AWEMMY.Character.Pronouns": "Pronouns", "AWEMMY.Character.Specialization": "Specialization", + "AWEMMY.Character.DropField": "Drag & drop a Field item here", + "AWEMMY.Character.DropArchetype": "Drag & drop Archetype items here", + "AWEMMY.Character.DropBackground": "Drag & drop a Background item here", "AWEMMY.Creature.EurekaRubric": "Eureka Rubric", "AWEMMY.Creature.Claims": "Claims", "AWEMMY.Creature.Evidence": "Evidence", diff --git a/module/applications/sheets/base-actor-sheet.mjs b/module/applications/sheets/base-actor-sheet.mjs index 926ba92..1244e4e 100644 --- a/module/applications/sheets/base-actor-sheet.mjs +++ b/module/applications/sheets/base-actor-sheet.mjs @@ -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 })) } /** diff --git a/module/applications/sheets/character-sheet.mjs b/module/applications/sheets/character-sheet.mjs index cb98965..ff6dc81 100644 --- a/module/applications/sheets/character-sheet.mjs +++ b/module/applications/sheets/character-sheet.mjs @@ -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 }]) } /** diff --git a/module/documents/item.mjs b/module/documents/item.mjs index 731d76f..9198985 100644 --- a/module/documents/item.mjs +++ b/module/documents/item.mjs @@ -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}` + } } diff --git a/module/models/character.mjs b/module/models/character.mjs index 4884a38..88d2f9e 100644 --- a/module/models/character.mjs +++ b/module/models/character.mjs @@ -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, diff --git a/templates/character-biography.hbs b/templates/character-biography.hbs index e7c2c4e..1b6ab5e 100644 --- a/templates/character-biography.hbs +++ b/templates/character-biography.hbs @@ -6,22 +6,58 @@ {{formInput systemFields.pronouns value=system.pronouns disabled=isPlayMode}} -
- - {{formInput systemFields.fieldName value=system.fieldName disabled=isPlayMode}} -
{{formInput systemFields.specialization value=system.specialization disabled=isPlayMode}}
-
- - {{formInput systemFields.archetypeName value=system.archetypeName disabled=isPlayMode}} + + + +
+ {{localize "AWEMMY.Item.Field"}} + {{#each fields}} +
+ {{name}} + {{name}} +
+ + +
-
- - {{formInput systemFields.backgroundName value=system.backgroundName disabled=isPlayMode}} + {{/each}} + {{#unless fields.length}}
{{localize "AWEMMY.Character.DropField"}}
{{/unless}} +
+ + +
+ {{localize "AWEMMY.Item.Archetype"}} + {{#each archetypes}} +
+ {{name}} + {{name}} +
+ + +
+ {{/each}} + {{#unless archetypes.length}}
{{localize "AWEMMY.Character.DropArchetype"}}
{{/unless}} +
+ + +
+ {{localize "AWEMMY.Item.Background"}} + {{#each backgrounds}} +
+ {{name}} + {{name}} +
+ + +
+
+ {{/each}} + {{#unless backgrounds.length}}
{{localize "AWEMMY.Character.DropBackground"}}
{{/unless}}
@@ -47,3 +83,4 @@
+ diff --git a/templates/character-equipment.hbs b/templates/character-equipment.hbs index eb3cd66..6113766 100644 --- a/templates/character-equipment.hbs +++ b/templates/character-equipment.hbs @@ -5,7 +5,7 @@ {{localize "AWEMMY.Item.Kit"}}
{{#each kits as |item|}} -
+
{{item.name}}
{{item.system.charges.value}}/{{item.system.charges.max}}
@@ -30,7 +30,7 @@ {{localize "AWEMMY.Item.Weapon"}}
{{#each weapons as |item|}} -
+
{{item.name}}
{{item.system.damageFormula}} ({{item.system.damageType}})
@@ -56,7 +56,7 @@ {{localize "AWEMMY.Item.Equipment"}}
{{#each equipments as |item|}} -
+
{{item.name}}
x{{item.system.quantity}}
diff --git a/templates/character-main.hbs b/templates/character-main.hbs index f9b5923..1524c94 100644 --- a/templates/character-main.hbs +++ b/templates/character-main.hbs @@ -51,7 +51,7 @@ {{localize "AWEMMY.Item.Ability"}}
{{#each abilities as |item|}} -
+
{{item.name}}
{{item.costLabel}}