DIvers petites corrections pour les specialités et les competences
All checks were successful
Release Creation / build (release) Successful in 54s

This commit is contained in:
2026-01-18 18:39:51 +01:00
parent d3c24e44d8
commit f445741eda
66 changed files with 277 additions and 238 deletions

View File

@@ -186,7 +186,8 @@ export default class HeritiersActorSheet extends HandlebarsApplicationMixin(foun
const itemType = li?.dataset.itemType
const itemField = event.target.dataset.itemField
const dataType = event.target.dataset.dtype
const value = event.target.value
// Pour les checkboxes, utiliser checked au lieu de value
const value = event.target.type === 'checkbox' ? event.target.checked : event.target.value
if (itemId && itemType && itemField) {
this.actor.editItemField(itemId, itemType, itemField, dataType, value)
}

View File

@@ -11,8 +11,6 @@ export default class HeritiersCompetenceSheet extends HeritiersItemSheet {
actions: {
addSpecialite: HeritiersCompetenceSheet.#onAddSpecialite,
deleteSpecialite: HeritiersCompetenceSheet.#onDeleteSpecialite,
editSpecialite: HeritiersCompetenceSheet.#onEditSpecialite,
editSpecialiteDescription: HeritiersCompetenceSheet.#onEditSpecialiteDescription,
}
}
@@ -23,43 +21,55 @@ export default class HeritiersCompetenceSheet extends HeritiersItemSheet {
},
}
/** @override */
_onRender(context, options) {
super._onRender(context, options)
// Attacher les écouteurs pour l'édition des spécialités
this.element.querySelectorAll('.edit-specialite').forEach(input => {
input.addEventListener('change', async (event) => {
const li = event.target.closest('.specialite-item')
const index = Number.parseInt(li?.dataset.specialiteIndex)
if (index !== undefined && !Number.isNaN(index)) {
const spec = foundry.utils.duplicate(this.item.system.specialites) || []
if (spec[index]) {
spec[index].name = event.target.value
await this.item.update({ 'system.specialites': spec })
}
}
})
})
this.element.querySelectorAll('.edit-specialite-description').forEach(textarea => {
textarea.addEventListener('change', async (event) => {
const li = event.target.closest('.specialite-item')
const index = Number.parseInt(li?.dataset.specialiteIndex)
if (index !== undefined && !Number.isNaN(index)) {
const spec = foundry.utils.duplicate(this.item.system.specialites) || []
if (spec[index]) {
spec[index].description = event.target.value
await this.item.update({ 'system.specialites': spec })
}
}
})
})
}
/* -------------------------------------------- */
/* Event Handlers */
/* -------------------------------------------- */
static async #onAddSpecialite(event, target) {
let spec = foundry.utils.duplicate(this.item.system.specialites) || []
spec.push({ name: "Nouvelle Spécialité", id: foundry.utils.randomID(16), used: false })
spec.push({ name: "Nouvelle Spécialité", description: "", used: false })
await this.item.update({ 'system.specialites': spec })
}
static async #onDeleteSpecialite(event, target) {
const li = target.closest(".specialite-item")
let index = parseInt(li.dataset.specialiteIndex)
let index = Number.parseInt(li.dataset.specialiteIndex)
let spec = foundry.utils.duplicate(this.item.system.specialites) || []
spec.splice(index, 1)
await this.item.update({ 'system.specialites': spec })
}
static async #onEditSpecialite(event, target) {
const li = target.closest(".specialite-item")
let index = parseInt(li.dataset.specialiteIndex)
let spec = foundry.utils.duplicate(this.item.system.specialites) || []
if (spec[index]) {
spec[index].name = target.value
spec[index].id = spec[index].id || foundry.utils.randomID(16)
await this.item.update({ 'system.specialites': spec })
}
}
static async #onEditSpecialiteDescription(event, target) {
const li = target.closest(".specialite-item")
let index = parseInt(li.dataset.specialiteIndex)
let spec = foundry.utils.duplicate(this.item.system.specialites) || []
if (spec[index]) {
spec[index].description = target.value
spec[index].id = spec[index].id || foundry.utils.randomID(16)
await this.item.update({ 'system.specialites': spec })
}
}
}

View File

@@ -277,7 +277,7 @@ export class HeritiersActor extends Actor {
let comp = {}
for (let key in game.system.lesheritiers.config.competenceProfil) {
if (game.system.lesheritiers.config.competenceProfil[key].kind == kind)
comp[key] = { skills: [], niveau: this.system.competences[key].niveau }
comp[key] = { skills: [], niveau: this.system.competences[key].niveau, rang: this.system.competences[key].rang }
}
for (let item of this.items) {
if (item.type == "competence") {
@@ -394,6 +394,34 @@ export class HeritiersActor extends Actor {
}
if (this.type == 'personnage') {
// Calculate rang for each competence profile
let competencesRangs = {
aventurier: 0,
combattant: 0,
erudit: 0,
gentleman: 0,
roublard: 0,
savant: 0
}
// Sum up niveau for each profil
for (let item of this.items) {
if (item.type == "competence" && item.system.profil) {
let profil = item.system.profil.toLowerCase()
if (competencesRangs.hasOwnProperty(profil)) {
competencesRangs[profil] += item.system.niveau
}
}
}
// Calculate rang (total / 4, rounded down) for each competence
for (let profil in competencesRangs) {
let total = competencesRangs[profil]
let rang = Math.floor(total / 4)
if (this.system.competences[profil]) {
this.system.competences[profil].rang = rang
}
}
}
super.prepareDerivedData()
@@ -431,6 +459,8 @@ export class HeritiersActor extends Actor {
if (dataType) {
if (dataType.toLowerCase() == "number") {
value = Number(value)
} else if (dataType.toLowerCase() == "boolean") {
value = Boolean(value)
} else {
value = String(value)
}