2024-10-05 00:37:55 +02:00
|
|
|
import { RdDActorSheet } from "../../actor-sheet.js"
|
|
|
|
import { SYSTEM_RDD } from "../../constants.js";
|
|
|
|
import { Misc } from "../../misc.js";
|
2024-10-05 12:50:29 +02:00
|
|
|
import { EXPORT_CSV_SCRIPTARIUM, OptionsAvancees } from "../../settings/options-avancees.js";
|
2024-10-05 00:37:55 +02:00
|
|
|
import { ExportScriptarium } from "./export-scriptarium.js";
|
2024-10-05 12:41:28 +02:00
|
|
|
import { CATEGORIES_COMPETENCES, CATEGORIES_DRACONIC, Mapping } from "./mapping.js";
|
2024-10-05 00:37:55 +02:00
|
|
|
|
|
|
|
export class RdDActorExportSheet extends RdDActorSheet {
|
|
|
|
static async init() {
|
|
|
|
await loadTemplates([
|
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/arme.hbs",
|
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/carac.hbs",
|
2024-10-05 15:13:29 +02:00
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/carac-compteur.hbs",
|
2024-10-05 00:37:55 +02:00
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/carac-derivee.hbs",
|
2024-10-05 15:13:29 +02:00
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/carac-derivee-compteur.hbs",
|
2024-10-05 12:41:28 +02:00
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/competences.hbs",
|
2024-10-05 00:37:55 +02:00
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/esquive.hbs",
|
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/protection.hbs",
|
|
|
|
"systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/sort.hbs",
|
|
|
|
])
|
|
|
|
Actors.registerSheet(SYSTEM_RDD, RdDActorExportSheet, { types: ["personnage"], makeDefault: false, label: "Feuille d'encart" })
|
|
|
|
}
|
|
|
|
static get defaultOptions() {
|
|
|
|
return foundry.utils.mergeObject(RdDActorSheet.defaultOptions, {
|
2024-10-05 12:50:29 +02:00
|
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/actor/export-scriptarium/actor-encart-sheet.hbs",
|
2024-10-05 00:37:55 +02:00
|
|
|
width: 550,
|
|
|
|
showCompNiveauBase: false,
|
|
|
|
vueArchetype: false,
|
|
|
|
}, { inplace: false })
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(actor, options) {
|
|
|
|
super(actor, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
async getData() {
|
|
|
|
const formData = await super.getData()
|
|
|
|
// Add any structured, precomputed list of data
|
2024-10-05 12:41:28 +02:00
|
|
|
formData.export = this.getMappingValues();
|
|
|
|
formData.competences = this.getCompetences(CATEGORIES_COMPETENCES)
|
|
|
|
formData.draconic = this.getCompetences(CATEGORIES_DRACONIC)
|
2024-10-05 12:50:29 +02:00
|
|
|
formData.options.exportScriptarium = OptionsAvancees.isUsing(EXPORT_CSV_SCRIPTARIUM)
|
2024-10-05 00:37:55 +02:00
|
|
|
return formData
|
|
|
|
}
|
|
|
|
|
2024-10-05 12:41:28 +02:00
|
|
|
getMappingValues() {
|
|
|
|
const context = Mapping.prepareContext(this.actor)
|
|
|
|
return Object.fromEntries(Mapping.getMapping().map(it => [it.column, {
|
|
|
|
colName: it.colName ?? it.column,
|
|
|
|
column: it.column,
|
2024-10-05 15:13:29 +02:00
|
|
|
rollClass: it.rollClass,
|
2024-10-05 12:41:28 +02:00
|
|
|
value: it.getter(this.actor, context)
|
|
|
|
}]))
|
|
|
|
}
|
|
|
|
|
|
|
|
getCompetences(categories) {
|
|
|
|
const competences = Mapping.getCompetencesCategorie(this.actor, categories)
|
|
|
|
if (competences.length == 0) {
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
const byCategories = Mapping.competencesByCategoriesByNiveau(competences, categories)
|
|
|
|
const listByCategories = Object.values(byCategories)
|
|
|
|
.map(it => it.competencesParNiveau)
|
|
|
|
.map(byNiveau => {
|
|
|
|
const niveaux = Object.keys(byNiveau).map(it => Number(it)).sort(Misc.ascending())
|
|
|
|
if (niveaux.length == 0) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
const listCategorieByNiveau = niveaux.map(niveau => {
|
|
|
|
const list = byNiveau[niveau].sort(Misc.ascending(it => it.name))
|
|
|
|
return {niveau, list}
|
|
|
|
})
|
|
|
|
return Misc.concat(listCategorieByNiveau)
|
|
|
|
}).filter(it => it != undefined)
|
|
|
|
|
|
|
|
return Misc.concat(listByCategories)
|
|
|
|
}
|
|
|
|
|
2024-10-05 00:37:55 +02:00
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
this.html.find('.button-export').click(async event => {
|
|
|
|
|
|
|
|
ExportScriptarium.INSTANCE.exportActors([this.actor],
|
|
|
|
`${this.actor.uuid}-${this.actor.name}`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|