feat: tarot deck auto-import depuis compendium/data JSON
resetDeck() cherche les cartes dans cet ordre : 1. game.items (items monde existants) 2. Compendium système fvtt-hamalron.hamalron-items 3. assets/data/tarot.json (création automatique) Ajout de assets/data/tarot.json : 78 cartes standard
This commit is contained in:
@@ -5,7 +5,7 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
|
||||
super(options)
|
||||
this.deck = []
|
||||
this.discard = []
|
||||
this.loadDeckState()
|
||||
this.loadDeckState().catch(e => console.warn("Deck init error:", e))
|
||||
}
|
||||
|
||||
/** @override */
|
||||
@@ -58,46 +58,81 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
|
||||
/**
|
||||
* Load the deck state from settings
|
||||
*/
|
||||
loadDeckState() {
|
||||
async loadDeckState() {
|
||||
const state = game.settings.get("fvtt-hamalron", "tarotDeckState")
|
||||
if (state && state.deck && state.deck.length > 0) {
|
||||
this.deck = state.deck
|
||||
this.discard = state.discard || []
|
||||
console.log("Deck state loaded:", state)
|
||||
} else {
|
||||
// Si aucun état sauvegardé, initialiser un nouveau deck
|
||||
this.resetDeck()
|
||||
await this.resetDeck()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the deck to a full tarot deck
|
||||
*/
|
||||
resetDeck() {
|
||||
async resetDeck() {
|
||||
this.deck = []
|
||||
this.discard = []
|
||||
|
||||
// Créer toutes les cartes du jeu de tarot
|
||||
const items = game.items.filter(i => i.type === "tarot")
|
||||
let items = game.items.filter(i => i.type === "tarot")
|
||||
|
||||
if (items.length > 0) {
|
||||
// Utiliser les items existants
|
||||
this.deck = items.map(item => ({
|
||||
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,
|
||||
}))
|
||||
} else {
|
||||
ui.notifications.warn("HAMALRON.TarotDeck.NoCardsFound", { localize: true })
|
||||
// Si aucune carte dans le monde, importer depuis le compendium système
|
||||
if (items.length === 0) {
|
||||
const pack = game.packs.get("fvtt-hamalron.hamalron-items")
|
||||
if (pack) {
|
||||
const docs = await pack.getDocuments()
|
||||
const tarotDocs = docs.filter(d => d.type === "tarot")
|
||||
if (tarotDocs.length > 0) {
|
||||
for (const doc of tarotDocs) {
|
||||
const imported = await Item.create(doc.toObject(), { temporary: false })
|
||||
if (imported) items.push(imported)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dernier recours : créer les cartes depuis les données JSON
|
||||
if (items.length === 0) {
|
||||
try {
|
||||
const resp = await fetch("systems/fvtt-hamalron/assets/data/tarot.json")
|
||||
const data = await resp.json()
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
for (const card of data) {
|
||||
const created = await Item.create({
|
||||
name: card.name,
|
||||
type: "tarot",
|
||||
img: "icons/svg/treasure.svg",
|
||||
system: {
|
||||
type: card.type,
|
||||
symbole: card.symbole,
|
||||
valeur: card.valeur,
|
||||
description: card.description || `<p>${card.name}</p>`,
|
||||
image: "icons/svg/treasure.svg",
|
||||
},
|
||||
})
|
||||
if (created) items.push(created)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Hamalron | Failed to load tarot.json:", e)
|
||||
}
|
||||
}
|
||||
|
||||
// Construire le deck
|
||||
this.deck = items.map(item => ({
|
||||
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,
|
||||
}))
|
||||
|
||||
// Mélanger le deck
|
||||
this.shuffleDeck()
|
||||
this.saveDeckState()
|
||||
await this.saveDeckState()
|
||||
this.render()
|
||||
}
|
||||
|
||||
@@ -186,7 +221,7 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
|
||||
})
|
||||
|
||||
if (confirmed) {
|
||||
this.resetDeck()
|
||||
await this.resetDeck()
|
||||
ui.notifications.info("HAMALRON.TarotDeck.DeckReset", { localize: true })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user