Workable system, firt step
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import HamalronActorSheet from "./base-actor-sheet.mjs"
|
||||
import { SYSTEM } from "../../config/system.mjs"
|
||||
|
||||
export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
/** @override */
|
||||
@@ -20,6 +21,12 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
createRitual: HamalronPersonnageSheet.#onCreateRitual,
|
||||
createPerk: HamalronPersonnageSheet.#onCreatePerk,
|
||||
modifyAmmo: HamalronPersonnageSheet.#onModifyAmmo,
|
||||
modifyResistance: HamalronPersonnageSheet.#onModifyResistance,
|
||||
discardCard: HamalronPersonnageSheet.#onDiscardCard,
|
||||
rollCompetence: HamalronPersonnageSheet.#onRollCompetence,
|
||||
drawCard: HamalronPersonnageSheet.#onDrawCard,
|
||||
selectCard: HamalronPersonnageSheet.#onSelectCard,
|
||||
discardAndDraw: HamalronPersonnageSheet.#onDiscardAndDraw,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -31,18 +38,18 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
tabs: {
|
||||
template: "templates/generic/tab-navigation.hbs",
|
||||
},
|
||||
status: {
|
||||
competences: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-status.hbs",
|
||||
},
|
||||
maleficas: {
|
||||
tarot: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-tarot.hbs",
|
||||
},
|
||||
sortileges: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-sortileges.hbs",
|
||||
},
|
||||
equipment: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-equipement.hbs",
|
||||
},
|
||||
tarot: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-tarot.hbs",
|
||||
},
|
||||
biography: {
|
||||
template: "systems/fvtt-hamalron/templates/personnage-biographie.hbs",
|
||||
},
|
||||
@@ -50,7 +57,7 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
|
||||
/** @override */
|
||||
tabGroups = {
|
||||
sheet: "status",
|
||||
sheet: "competences",
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,10 +66,10 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
*/
|
||||
#getTabs() {
|
||||
const tabs = {
|
||||
status: { id: "status", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.status" },
|
||||
maleficas: { id: "maleficas", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.maleficas" },
|
||||
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.equipment" },
|
||||
competences: { id: "competences", group: "sheet", icon: "fa-solid fa-list-check", label: "HAMALRON.Label.competences" },
|
||||
tarot: { id: "tarot", group: "sheet", icon: "fa-solid fa-cards", label: "HAMALRON.Label.tarot" },
|
||||
sortileges: { id: "sortileges", group: "sheet", icon: "fa-solid fa-wand-magic-sparkles", label: "HAMALRON.Label.sortileges" },
|
||||
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.equipment" },
|
||||
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HAMALRON.Label.biography" },
|
||||
}
|
||||
for (const v of Object.values(tabs)) {
|
||||
@@ -78,9 +85,6 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
context.tabs = this.#getTabs()
|
||||
|
||||
const doc = this.document
|
||||
context.trait = doc.itemTypes['species-trait']?.[0]
|
||||
context.upright = doc.itemTypes.tarot.find(t => t.system.orientation === "Upright")
|
||||
context.downright = doc.itemTypes.tarot.find(t => t.system.orientation === "Downright")
|
||||
|
||||
return context
|
||||
}
|
||||
@@ -91,30 +95,36 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
context.systemFields = this.document.system.schema.fields
|
||||
switch (partId) {
|
||||
case "main":
|
||||
// Get peuple and faction items (only one of each allowed)
|
||||
context.peuple = doc.itemTypes.peuple?.[0] || null
|
||||
context.faction = doc.itemTypes.faction?.[0] || null
|
||||
context.isEditMode = this.isEditMode
|
||||
context.isPlayMode = this.isPlayMode
|
||||
break
|
||||
case "status":
|
||||
context.tab = context.tabs.status
|
||||
context.perks = doc.itemTypes.perk || []
|
||||
// Sort the perks by system.role and then by the system.level
|
||||
context.perks.sort((a, b) => {
|
||||
if (a.system.role === b.system.role) {
|
||||
return a.system.level.localeCompare(b.system.level)
|
||||
}
|
||||
return a.system.role.localeCompare(b.system.role)
|
||||
case "competences":
|
||||
context.tab = context.tabs.competences
|
||||
const allCompetences = doc.itemTypes.competence || []
|
||||
// Ajouter les données de niveau enrichies à chaque compétence
|
||||
allCompetences.forEach(c => {
|
||||
const niveauData = SYSTEM.NIVEAU_COMPETENCES[c.system.niveau]
|
||||
c.niveauName = niveauData?.name || c.system.niveau
|
||||
c.niveauModificateur = niveauData?.modificateur ?? 0
|
||||
})
|
||||
// Grouper les compétences par type et trier par nom dans chaque groupe
|
||||
context.competencesCommunes = allCompetences.filter(c => c.system.type === 'commune').sort((a, b) => a.name.localeCompare(b.name))
|
||||
context.competencesPeuple = allCompetences.filter(c => c.system.type === 'peuple').sort((a, b) => a.name.localeCompare(b.name))
|
||||
context.competencesFaction = allCompetences.filter(c => c.system.type === 'faction').sort((a, b) => a.name.localeCompare(b.name))
|
||||
break;
|
||||
case "maleficas":
|
||||
context.tab = context.tabs.maleficas
|
||||
context.maleficas = doc.itemTypes.malefica || []
|
||||
// Sort the maleficas by system.domain and then by the system.level
|
||||
context.maleficas.sort((a, b) => {
|
||||
case "sortileges":
|
||||
context.tab = context.tabs.sortileges
|
||||
context.sortileges = doc.itemTypes.sortilege || []
|
||||
// Sort the sortileges by system.domain and then by the system.level
|
||||
context.sortileges.sort((a, b) => {
|
||||
if (a.system.domain === b.system.domain) {
|
||||
return a.system.level.localeCompare(b.system.level)
|
||||
}
|
||||
return a.system.domain.localeCompare(b.system.domain)
|
||||
})
|
||||
context.rituals = doc.itemTypes.ritual || []
|
||||
context.rituals.sort((a, b) => a.name.localeCompare(b.name))
|
||||
break
|
||||
case "equipment":
|
||||
context.tab = context.tabs.equipment
|
||||
@@ -129,9 +139,23 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
context.tab = context.tabs.tarot
|
||||
context.tarotCards = doc.itemTypes.tarot || []
|
||||
context.tarotCards.sort((a, b) => a.name.localeCompare(b.name))
|
||||
// Enrich descriptions for each tarot card
|
||||
context.handLimit = 7
|
||||
context.handSize = context.tarotCards.length
|
||||
context.isOverLimit = context.handSize > context.handLimit
|
||||
context.canAddCard = context.handSize < 8
|
||||
// Marquer les cartes de succès et enrichir les descriptions
|
||||
for (const card of context.tarotCards) {
|
||||
card.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(card.system.description, { async: true })
|
||||
// Vérifier si c'est une carte de succès
|
||||
if (doc.system.cartesSucces && card.system.type !== "atout") {
|
||||
card.isSuccessCard = Object.keys(doc.system.cartesSucces).some(symbole => {
|
||||
const successCardData = doc.system.cartesSucces[symbole]
|
||||
return card.system.symbole === symbole &&
|
||||
card.system.valeur === successCardData.value.toString()
|
||||
})
|
||||
} else {
|
||||
card.isSuccessCard = false
|
||||
}
|
||||
}
|
||||
break
|
||||
case "biography":
|
||||
@@ -196,6 +220,190 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
await item.update({ "system.ammoQuantity": newAmmo })
|
||||
}
|
||||
|
||||
static async #onModifyResistance(event, target) {
|
||||
const symbole = target.dataset.symbole
|
||||
const delta = Number.parseInt(target.dataset.delta)
|
||||
|
||||
if (!symbole || isNaN(delta)) {
|
||||
console.warn(`HamalronPersonnageSheet: Invalid resistance modification parameters`)
|
||||
return
|
||||
}
|
||||
|
||||
const resistance = this.document.system.resistances[symbole]
|
||||
if (!resistance) {
|
||||
console.warn(`HamalronPersonnageSheet: Resistance ${symbole} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
const newValue = Math.max(0, Math.min(resistance.max, resistance.value + delta))
|
||||
await this.document.update({ [`system.resistances.${symbole}.value`]: newValue })
|
||||
}
|
||||
|
||||
static async #onDiscardCard(event, target) {
|
||||
const itemId = $(event.target).data("item-id")
|
||||
const item = this.document.items.get(itemId)
|
||||
if (!item || item.type !== "tarot") {
|
||||
console.warn(`HamalronPersonnageSheet: Tarot card with ID ${itemId} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
// Supprimer la carte du personnage
|
||||
await item.delete()
|
||||
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscarded") + item.name)
|
||||
}
|
||||
|
||||
static async #onSelectCard(event, target) {
|
||||
const cardWrapper = $(target).closest(".tarot-card-wrapper")
|
||||
const wasSelected = cardWrapper.hasClass("selected")
|
||||
|
||||
// Désélectionner toutes les cartes
|
||||
$(".tarot-card-wrapper").removeClass("selected")
|
||||
|
||||
// Sélectionner la carte cliquée si elle n'était pas déjà sélectionnée
|
||||
if (!wasSelected) {
|
||||
cardWrapper.addClass("selected")
|
||||
}
|
||||
}
|
||||
|
||||
static async #onDiscardAndDraw(event, target) {
|
||||
const itemId = $(target).data("item-id")
|
||||
const item = this.document.items.get(itemId)
|
||||
if (!item || item.type !== "tarot") {
|
||||
console.warn(`HamalronPersonnageSheet: Tarot card with ID ${itemId} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
// Dialog de confirmation
|
||||
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||
window: {
|
||||
title: game.i18n.localize("HAMALRON.Dialog.discardCardTitle"),
|
||||
},
|
||||
content: `<p>${game.i18n.format("HAMALRON.Dialog.discardCardContent", { cardName: item.name })}</p>`,
|
||||
rejectClose: false,
|
||||
modal: true,
|
||||
})
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
// Récupérer le deck manager
|
||||
const module = await import("../tarot-deck-manager.mjs")
|
||||
const HamalronTarotDeckManager = module.default
|
||||
|
||||
if (!HamalronTarotDeckManager._instance) {
|
||||
HamalronTarotDeckManager._instance = new HamalronTarotDeckManager()
|
||||
}
|
||||
|
||||
const deckManager = HamalronTarotDeckManager._instance
|
||||
|
||||
if (!deckManager) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckManagerNotAvailable"))
|
||||
return
|
||||
}
|
||||
|
||||
// Ajouter la carte à la défausse
|
||||
deckManager.addToDiscard({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
img: item.img,
|
||||
symbole: item.system.symbole,
|
||||
valeur: item.system.valeur,
|
||||
type: item.system.type,
|
||||
description: item.system.description,
|
||||
})
|
||||
|
||||
// Supprimer la carte du personnage
|
||||
await item.delete()
|
||||
|
||||
// Tirer une nouvelle carte si le deck n'est pas vide
|
||||
if (deckManager.deck.length > 0) {
|
||||
const newCards = deckManager.drawCards(1)
|
||||
if (newCards.length > 0) {
|
||||
const newCard = newCards[0]
|
||||
|
||||
// Cas spécial : Le Mat
|
||||
if (newCard.valeur === "lemat") {
|
||||
console.log("Le Mat drawn! Executing special rules...")
|
||||
const { default: HamalronTirageTarot } = await import("../../documents/tirage-tarot.mjs")
|
||||
await HamalronTirageTarot.handleLeMatEffect(this.document, deckManager)
|
||||
} else {
|
||||
const originalItem = game.items.get(newCard.id)
|
||||
if (originalItem) {
|
||||
await this.document.createEmbeddedDocuments("Item", [originalItem.toObject()])
|
||||
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscardedAndDrawn") + newCard.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscardedNoNew"))
|
||||
}
|
||||
|
||||
deckManager.saveDeckState()
|
||||
deckManager.render()
|
||||
}
|
||||
|
||||
static async #onDrawCard(event, target) {
|
||||
const currentTarotCount = this.document.items.filter(i => i.type === "tarot").length
|
||||
|
||||
// Vérifier que le joueur a moins de 7 cartes
|
||||
if (currentTarotCount >= 7) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.cannotDrawCard"))
|
||||
return
|
||||
}
|
||||
|
||||
// Récupérer le deck manager singleton
|
||||
const module = await import("../tarot-deck-manager.mjs")
|
||||
const HamalronTarotDeckManager = module.default
|
||||
|
||||
// Vérifier si l'instance existe, sinon la créer
|
||||
if (!HamalronTarotDeckManager._instance) {
|
||||
HamalronTarotDeckManager._instance = new HamalronTarotDeckManager()
|
||||
}
|
||||
|
||||
const deckManager = HamalronTarotDeckManager._instance
|
||||
|
||||
if (!deckManager) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckManagerNotAvailable"))
|
||||
return
|
||||
}
|
||||
|
||||
if (deckManager.deck.length === 0) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckEmpty"))
|
||||
return
|
||||
}
|
||||
|
||||
// Tirer une nouvelle carte
|
||||
const newCards = deckManager.drawCards(1)
|
||||
if (newCards.length > 0) {
|
||||
const newCard = newCards[0]
|
||||
|
||||
// Cas spécial : Le Mat
|
||||
if (newCard.valeur === "lemat") {
|
||||
console.log("Le Mat drawn! Executing special rules...")
|
||||
const { default: HamalronTirageTarot } = await import("../../documents/tirage-tarot.mjs")
|
||||
await HamalronTirageTarot.handleLeMatEffect(this.document, deckManager)
|
||||
} else {
|
||||
// Trouver l'item original pour le dupliquer
|
||||
const originalItem = game.items.get(newCard.id)
|
||||
if (originalItem) {
|
||||
await this.document.createEmbeddedDocuments("Item", [originalItem.toObject()])
|
||||
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.newCardDrawn") + newCard.name)
|
||||
}
|
||||
}
|
||||
deckManager.saveDeckState()
|
||||
deckManager.render()
|
||||
}
|
||||
}
|
||||
|
||||
static async #onRollCompetence(event, target) {
|
||||
const itemId = $(target).data("item-id")
|
||||
const item = this.document.items.get(itemId)
|
||||
if (!item || item.type !== "competence") {
|
||||
console.warn(`HamalronPersonnageSheet: Competence with ID ${itemId} not found`)
|
||||
return
|
||||
}
|
||||
await this.document.system.roll("competence", item)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the roll action triggered by user interaction.
|
||||
*
|
||||
@@ -239,12 +447,19 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
|
||||
if (data.type === "Item") {
|
||||
const item = await fromUuid(data.uuid)
|
||||
if (item.type === "tarot") {
|
||||
// Delete the existing tarot item
|
||||
const existingTarot = this.document.items.find(i => i.type === "tarot" && i.system.orientation === item.system.orientation)
|
||||
if (existingTarot) {
|
||||
await existingTarot.delete()
|
||||
// Display info message
|
||||
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.tarotDeleted") + existingTarot.name)
|
||||
// Check if a card with the same name already exists
|
||||
const existingCard = this.document.items.find(i => i.type === "tarot" && i.name === item.name)
|
||||
if (existingCard) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.tarotCardAlreadyExists") + item.name)
|
||||
return
|
||||
}
|
||||
|
||||
const currentTarotCount = this.document.items.filter(i => i.type === "tarot").length
|
||||
|
||||
// Check if we already have 8 cards (hard limit)
|
||||
if (currentTarotCount >= 8) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.tarotHandFull"))
|
||||
return
|
||||
}
|
||||
}
|
||||
if (item.type === "species-trait") {
|
||||
|
||||
Reference in New Issue
Block a user