Actor sheet -> working !!!

This commit is contained in:
2026-06-06 15:48:18 +02:00
parent 9b77a0c552
commit 891769816a
13 changed files with 129 additions and 69 deletions
@@ -64,6 +64,35 @@ export class VermineBaseActorSheet extends HandlebarsApplicationMixin(foundry.ap
_canDragStart() { return this.isEditable }
_canDragDrop() { return this.isEditable }
// ── Soumission du formulaire ────────────────────────────────────────
/** @override - coerce string values from HTML form inputs to numbers */
_prepareSubmitData(submitData, form, formData) {
const fd = foundry.utils.deepClone(formData.object)
for (const [key, value] of Object.entries(fd)) {
if (!key.startsWith("system.") || typeof value === "number") continue
const segments = key.slice(7).split(".")
let node = this.document.system.schema
for (const seg of segments) {
if (node instanceof foundry.data.fields.SchemaField) node = node.fields[seg]
else { node = undefined; break }
}
if (!(node instanceof foundry.data.fields.NumberField)) continue
// Handle arrays from duplicate-named form inputs
let raw = Array.isArray(value) ? value.filter(v => v !== "" && v !== null).pop() : value
if (raw === undefined) continue
if (typeof raw === "string" && raw.trim() === "") { fd[key] = 0; continue }
const num = Number(typeof raw === "string" ? raw.trim() : raw)
if (!isNaN(num)) fd[key] = num
}
return fd
}
// ── Contexte commun ─────────────────────────────────────────────────
async _prepareContext() {
@@ -12,6 +12,7 @@ export class VermineCharacterSheetV2 extends VermineBaseActorSheet {
}
static PARTS = {
header: { template: "systems/vermine2047/templates/actor/appv2/character-header.hbs" },
main: { template: "systems/vermine2047/templates/actor/appv2/character-main.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
abilities: { template: "systems/vermine2047/templates/actor/appv2/character-abilities.hbs" },
@@ -39,6 +39,14 @@ export class VermineCreatureSheetV2 extends VermineBaseActorSheet {
return context
}
changeTab(tab, group, options = {}) {
super.changeTab(tab, group, options)
if (group === "sheet") {
const main = this.element?.querySelector('[data-group="sheet"][data-tab="main"]')
if (main) main.classList.add("active")
}
}
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
+8 -1
View File
@@ -7,7 +7,6 @@ export class VermineGroupSheetV2 extends VermineBaseActorSheet {
position: { width: 700, height: 600 },
window: { contentClasses: ["group-content"] },
actions: {
chooseTotem: VermineGroupSheetV2.#onChooseTotem,
chooseActor: VermineGroupSheetV2.#onChooseActor,
deleteMember: VermineGroupSheetV2.#onDeleteMember,
deleteEncounter: VermineGroupSheetV2.#onDeleteEncounter,
@@ -62,6 +61,14 @@ export class VermineGroupSheetV2 extends VermineBaseActorSheet {
return context
}
changeTab(tab, group, options = {}) {
super.changeTab(tab, group, options)
if (group === "sheet") {
const main = this.element?.querySelector('[data-group="sheet"][data-tab="main"]')
if (main) main.classList.add("active")
}
}
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {