Finalize aappv2 data models migration

This commit is contained in:
2026-02-27 14:36:54 +01:00
parent 8735b7e4a4
commit c45837ea31
87 changed files with 10701 additions and 1225 deletions

View File

@@ -1,155 +1,132 @@
import { MaleficesUtility } from "./malefices-utility.js";
export class MaleficesTirageTarotDialog extends Dialog {
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api
export class MaleficesTirageTarotDialog extends HandlebarsApplicationMixin(ApplicationV2) {
/* -------------------------------------------- */
static async create(actor, tirageData) {
static DEFAULT_OPTIONS = {
id: "malefices-tirage-tarot",
classes: ["MaleficesDialog"],
window: { title: "Tirage des Tarots", resizable: true },
position: { width: 720, height: 740 },
}
let options = { classes: ["MaleficesDialog"], width: 720, height: 740, 'z-index': 99999 };
let html = await foundry.applications.handlebars.renderTemplate('systems/fvtt-malefices/templates/dialogs/tirage-tarot-dialog.hbs', tirageData);
return new MaleficesTirageTarotDialog(actor, tirageData, html, options);
static PARTS = {
form: { template: 'systems/fvtt-malefices/templates/dialogs/tirage-tarot-dialog.hbs' }
}
/* -------------------------------------------- */
constructor(actor, tirageData, html, options, close = undefined) {
let conf = {
title: "Tirage des tarots",
content: html,
buttons: {
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Fermer/Annuler",
callback: () => { this.close() }
}
},
close: close
}
constructor(actor, tirageData, options = {}) {
super(options)
this.actor = actor
this.tirageData = tirageData
}
super(conf, options);
/* -------------------------------------------- */
static async create(actor, tirageData) {
const app = new MaleficesTirageTarotDialog(actor, tirageData)
app.render({ force: true })
return app
}
this.actor = actor;
this.tirageData = tirageData;
/* -------------------------------------------- */
async _prepareContext(_options) {
return { ...this.tirageData }
}
/* -------------------------------------------- */
_onRender(_context, _options) {
const el = this.element
el.querySelector('#playerId')?.addEventListener('change', (event) => {
if (event.currentTarget.value !== "none") {
this.tirageData.playerId = event.currentTarget.value
this.processSelectedPlayer()
}
})
el.querySelector('#actorId')?.addEventListener('change', (event) => {
if (event.currentTarget.value !== "none") {
this.attributeToActor(event.currentTarget.value)
}
})
el.querySelector('.tirage-close-btn')?.addEventListener('click', () => this.close())
}
/* -------------------------------------------- */
async sendCardRequest() {
this.tirageData.state = 'waiting-user-card'
let msg = await MaleficesUtility.createChatMessage(this.tirageData.user.name, "useronly", {
content: await renderTemplate(`systems/fvtt-malefices/templates/chat/request-tarot-card.hbs`, this.tirageData)
await MaleficesUtility.createChatMessage(this.tirageData.user.name, "useronly", {
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-malefices/templates/chat/request-tarot-card.hbs`, this.tirageData)
})
//msg.setFlag("world", "tirage-data", this.tirageData)
console.log("MSG IS", msg)
}
/* -------------------------------------------- */
drawCard() {
let index = Math.round(Math.random() * (this.tirageData.deck.length-1))
let index = Math.round(Math.random() * (this.tirageData.deck.length - 1))
let selectedCard = this.tirageData.deck[index]
selectedCard.system.ispositif = true
if ( selectedCard.system.isdualside) { // Cas des cartes pouvant avoir 2 sens
if (selectedCard.system.isdualside) {
selectedCard.system.ispositif = (Math.random() > 0.5)
}
console.log("CARD SELECTED:", selectedCard)
// Cas spécial de la Roue de la Fortune
if ( selectedCard.name.toLowerCase().includes("fortune")) {
if (selectedCard.name.toLowerCase().includes("fortune")) {
this.tirageData.maxPlayerCard += 1
this.tirageData.maxSecretCard += 1
}
let newList = []
for(let card of this.tirageData.deck) {
if (card.name != selectedCard.name) {
newList.push(card)
}
}
this.tirageData.deck = newList
this.tirageData.deck = this.tirageData.deck.filter(c => c.name !== selectedCard.name)
return selectedCard
}
/* -------------------------------------------- */
async addCard( msgId ) {
async addCard(msgId) {
MaleficesUtility.removeChatMessageId(msgId)
let selectedCard = this.drawCard()
selectedCard.system.isgm = false
await MaleficesUtility.createChatMessage(this.tirageData.user.name, "gmroll", {
content: await renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, selectedCard)
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, selectedCard)
})
if (this.tirageData.cards[0].name == "???") {
this.tirageData.cards.shift()
}
if (this.tirageData.cards[0].name == "???") this.tirageData.cards.shift()
this.tirageData.cards.push(selectedCard)
this.tirageData.nbCard++
if (this.tirageData.nbCard == this.tirageData.maxPlayerCard) {
for (let i=0; i<this.tirageData.maxSecretCard; i++) {
let selectedCard = this.drawCard()
selectedCard.system.isgm = true
for (let i = 0; i < this.tirageData.maxSecretCard; i++) {
let secretCard = this.drawCard()
secretCard.system.isgm = true
await MaleficesUtility.createChatMessage(this.tirageData.user.name, "blindroll", {
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, selectedCard)
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-malefices/templates/chat/display-tarot-card.hbs`, secretCard)
})
if (this.tirageData.secretCards[0].name == "???") {
this.tirageData.secretCards.shift()
}
this.tirageData.secretCards.push(selectedCard)
if (this.tirageData.secretCards[0].name == "???") this.tirageData.secretCards.shift()
this.tirageData.secretCards.push(secretCard)
}
this.tirageData.actors = foundry.utils.duplicate(game.actors)
this.tirageData.state = 'attribute-to-actor'
}else {
} else {
this.sendCardRequest()
}
this.refreshDialog()
this.render({ force: true })
}
/* -------------------------------------------- */
async processSelectedPlayer() {
let user = game.users.get(this.tirageData.playerId)
this.tirageData.user = user
this.tirageData.user = game.users.get(this.tirageData.playerId)
this.tirageData.players = null
console.log("Going to work with ", user.name)
game.system.malefices.currentTirage = this
this.refreshDialog()
this.render({ force: true })
this.sendCardRequest()
}
/* -------------------------------------------- */
attributeToActor(actorId) {
let actor = game.actors.get(actorId)
const actor = game.actors.get(actorId)
if (actor) {
actor.createEmbeddedDocuments('Item', this.tirageData.cards)
actor.createEmbeddedDocuments('Item', this.tirageData.secretCards)
ui.notifications.info("Les cartes ont été attribuées à " + actor.name)
}
}
/* -------------------------------------------- */
async refreshDialog() {
const content = await foundry.applications.handlebars.renderTemplate("systems/fvtt-malefices/templates/dialogs/tirage-tarot-dialog.hbs", this.tirageData)
this.data.content = content
this.render(true)
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
let dialog = this;
function onLoad() {
}
$(function () { onLoad(); });
html.find('#playerId').change((event) => {
if ( event.currentTarget.value != "none") {
dialog.tirageData.playerId = event.currentTarget.value
dialog.processSelectedPlayer()
}
})
html.find('#actorId').change((event) => {
if ( event.currentTarget.value != "none") {
let actorId = event.currentTarget.value
dialog.attributeToActor(actorId)
}
})
}
}