Files
fvtt-celestopol/module/applications/sheets/npc-sheet.mjs
LeRatierBretonnier 44cc07db73
Some checks failed
Release Creation / build (release) Failing after 1m24s
Portraits et corrections sur valeurs des PNJ
2026-04-12 11:52:17 +02:00

158 lines
6.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Célestopol 1922 — Système FoundryVTT
*
* Célestopol 1922 est un jeu de rôle édité par Antre-Monde Éditions.
* Ce système FoundryVTT est une implémentation indépendante et n'est pas
* affilié à Antre-Monde Éditions,
* mais a été réalisé avec l'autorisation d'Antre-Monde Éditions.
*
* @author LeRatierBretonnien
* @copyright 20252026 LeRatierBretonnien
* @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
*/
import CelestopolActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"
export default class CelestopolNPCSheet extends CelestopolActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["npc"],
position: { width: 780, height: 640 },
window: { contentClasses: ["npc-content"] },
actions: {
createAspect: CelestopolNPCSheet.#onCreateAspect,
createEquipment: CelestopolNPCSheet.#onCreateEquipment,
createWeapon: CelestopolNPCSheet.#onCreateWeapon,
createArmure: CelestopolNPCSheet.#onCreateArmure,
rollMoonDie: CelestopolNPCSheet.#onRollMoonDie,
},
}
/** @override */
static PARTS = {
main: { template: "systems/fvtt-celestopol/templates/npc-main.hbs" },
tabs: { template: "templates/generic/tab-navigation.hbs" },
competences: { template: "systems/fvtt-celestopol/templates/npc-competences.hbs" },
blessures: { template: "systems/fvtt-celestopol/templates/npc-blessures.hbs" },
equipement: { template: "systems/fvtt-celestopol/templates/npc-equipement.hbs" },
biographie: { template: "systems/fvtt-celestopol/templates/npc-biographie.hbs" },
}
tabGroups = { sheet: "competences" }
#getTabs() {
const tabs = {
competences: { id: "competences", group: "sheet", icon: "fa-solid fa-dice-d6", label: "CELESTOPOL.Tab.competences" },
blessures: { id: "blessures", group: "sheet", icon: "fa-solid fa-heart-crack", label: "CELESTOPOL.Tab.blessures" },
equipement: { id: "equipement", group: "sheet", icon: "fa-solid fa-shield-halved",label: "CELESTOPOL.Tab.equipement" },
biographie: { id: "biographie", group: "sheet", icon: "fa-solid fa-book-open", label: "CELESTOPOL.Tab.biographie" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.stats = SYSTEM.STATS
context.anomalyTypes = SYSTEM.ANOMALY_TYPES
context.woundLevels = SYSTEM.WOUND_LEVELS
context.npcTypes = SYSTEM.NPC_TYPES
context.factions = SYSTEM.FACTIONS
context.antagonisteStats = SYSTEM.ANTAGONISTE_STATS
const sys = this.document.system
context.aspects = this.document.itemTypes.aspect ?? []
context.weapons = this.document.itemTypes.weapon.sort((a, b) => a.name.localeCompare(b.name))
context.armures = this.document.itemTypes.armure.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = this.document.itemTypes.equipment.sort((a, b) => a.name.localeCompare(b.name))
context.armorMalus = sys.armorMalus ?? 0
// Label effectif de chaque domaine selon le type de PNJ
const isAntagoniste = sys.npcType === "antagoniste"
context.domainLabels = {
ame: isAntagoniste ? "CELESTOPOL.NPC.emprise" : "CELESTOPOL.Stat.ame",
corps: isAntagoniste ? "CELESTOPOL.NPC.peril" : "CELESTOPOL.Stat.corps",
coeur: isAntagoniste ? "CELESTOPOL.NPC.menace" : "CELESTOPOL.Stat.coeur",
esprit: isAntagoniste ? "CELESTOPOL.NPC.danger" : "CELESTOPOL.Stat.esprit",
}
return context
}
/** @override */
async _preparePartContext(partId, context) {
context.systemFields = this.document.system.schema.fields
switch (partId) {
case "competences":
context.tab = context.tabs.competences
// Enrichissement des aspects
context.enrichedAspects = await Promise.all(
(context.aspects ?? []).map(async a => ({
item: a,
enrichedDesc: await foundry.applications.ux.TextEditor.implementation.enrichHTML(
a.system.description, { relativeTo: this.document }
),
}))
)
break
case "blessures":
context.tab = context.tabs.blessures
context.enrichedNotes = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
context.system.notes, { relativeTo: this.document }
)
break
case "equipement":
context.tab = context.tabs.equipement
break
case "biographie":
context.tab = context.tabs.biographie
context.biographyPortrait = context.system.portraitImage || ""
context.hasBiographyPortrait = !!context.system.portraitImage
context.enrichedHistoire = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
context.system.histoire, { relativeTo: this.document }
)
context.enrichedDescriptionPhysique = await foundry.applications.ux.TextEditor.implementation.enrichHTML(
context.system.descriptionPhysique, { relativeTo: this.document }
)
break
}
return context
}
static async #onCreateAspect() {
await this.document.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("CELESTOPOL.Item.newAspect"), type: "aspect",
}])
}
static async #onCreateWeapon() {
await this.document.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("TYPES.Item.weapon"), type: "weapon",
}])
}
static async #onCreateEquipment() {
await this.document.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("TYPES.Item.equipment"), type: "equipment",
}])
}
static async #onCreateArmure() {
await this.document.createEmbeddedDocuments("Item", [{
name: game.i18n.localize("TYPES.Item.armure"), type: "armure",
system: { protection: 1, malus: 1 },
}])
}
/** Lance le Dé de la Lune de façon autonome depuis le header de la fiche PNJ. */
static async #onRollMoonDie() {
const { CelestopolRoll } = await import("../../documents/roll.mjs")
await CelestopolRoll.rollMoonStandalone(this.document)
}
}