2023-02-08 17:51:16 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
import { MaleficesUtility } from "./malefices-utility.js";
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class MaleficesCharacterSummary extends Application {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-02-26 15:38:44 +01:00
|
|
|
static displayPCSummary() {
|
|
|
|
if (game.user.isGM) {
|
|
|
|
game.system.malefices.charSummary.render(true)
|
|
|
|
} else {
|
|
|
|
ui.notifications.info("Commande /tirage réservée au MJ !")
|
|
|
|
}
|
2023-02-08 17:51:16 +01:00
|
|
|
}
|
2023-02-26 15:38:44 +01:00
|
|
|
|
2023-02-08 17:51:16 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-02-26 15:38:44 +01:00
|
|
|
updatePCSummary() {
|
|
|
|
if (this.rendered) {
|
2023-02-08 17:51:16 +01:00
|
|
|
this.render(true)
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 15:38:44 +01:00
|
|
|
|
2023-02-08 17:51:16 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createSummaryPos() {
|
|
|
|
return { top: 200, left: 200 };
|
|
|
|
}
|
2023-02-26 15:38:44 +01:00
|
|
|
|
2023-02-08 17:51:16 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static ready() {
|
2023-02-26 15:38:44 +01:00
|
|
|
if (!game.user.isGM) { // Uniquement si GM
|
2023-02-08 17:51:16 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
let charSummary = new MaleficesCharacterSummary()
|
|
|
|
game.system.malefices.charSummary = charSummary
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
//game.settings.set("world", "character-summary-data", {npcList: [], x:0, y:0})
|
|
|
|
this.settings = game.settings.get("world", "character-summary-data")
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
template: "systems/fvtt-malefices/templates/dialogs/character-summary.hbs",
|
|
|
|
popOut: true,
|
|
|
|
resizable: true,
|
|
|
|
dragDrop: [{ dragSelector: ".items-list .item", dropSelector: null }],
|
|
|
|
classes: ["bol", "dialog"], width: 920, height: 'fit-content'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getData() {
|
|
|
|
let formData = super.getData();
|
|
|
|
|
2023-02-26 15:38:44 +01:00
|
|
|
formData.pcs = game.actors.filter(ac => ac.type == "personnage" && ac.hasPlayerOwner)
|
2023-02-08 17:51:16 +01:00
|
|
|
formData.npcs = []
|
|
|
|
let newList = []
|
2023-02-26 15:38:44 +01:00
|
|
|
let toUpdate = false
|
|
|
|
for (let actorId of this.settings.npcList) {
|
2023-02-08 17:51:16 +01:00
|
|
|
let actor = game.actors.get(actorId)
|
|
|
|
if (actor) {
|
2023-02-26 15:38:44 +01:00
|
|
|
formData.npcs.push(actor)
|
2023-02-08 17:51:16 +01:00
|
|
|
newList.push(actorId)
|
|
|
|
} else {
|
|
|
|
toUpdate = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
formData.config = game.system.malefices.config
|
|
|
|
|
2023-02-26 15:38:44 +01:00
|
|
|
if (toUpdate) {
|
2023-02-08 17:51:16 +01:00
|
|
|
this.settings.npcList = newList
|
|
|
|
//console.log("Going to update ...", this.settings)
|
|
|
|
game.settings.set("world", "character-summary-data", this.settings)
|
|
|
|
}
|
|
|
|
|
|
|
|
return formData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
updateNPC() {
|
|
|
|
game.settings.set("world", "character-summary-data", game.system.malefices.charSummary.settings)
|
|
|
|
game.system.malefices.charSummary.close()
|
2023-02-26 15:38:44 +01:00
|
|
|
setTimeout(function () { game.system.malefices.charSummary.render(true) }, 500)
|
2023-02-08 17:51:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onDrop(event) {
|
|
|
|
//console.log("Dragged data are : ", dragData)
|
|
|
|
let data = event.dataTransfer.getData('text/plain')
|
2023-02-26 15:38:44 +01:00
|
|
|
let dataItem = JSON.parse(data)
|
2023-02-08 17:51:16 +01:00
|
|
|
let actor = fromUuidSync(dataItem.uuid)
|
|
|
|
if (actor) {
|
2023-02-26 15:38:44 +01:00
|
|
|
game.system.malefices.charSummary.settings.npcList.push(actor.id)
|
2023-02-08 17:51:16 +01:00
|
|
|
game.system.malefices.charSummary.updateNPC()
|
2023-02-26 15:38:44 +01:00
|
|
|
|
2023-02-08 17:51:16 +01:00
|
|
|
} else {
|
2023-02-26 15:38:44 +01:00
|
|
|
ui.notifications.warn("Pas d'acteur trouvé")
|
2023-02-08 17:51:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** @override */
|
|
|
|
async activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
html.find('.actor-open').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const actor = game.actors.get(li.data("actor-id"))
|
|
|
|
actor.sheet.render(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
html.find('.summary-roll').click((event) => {
|
|
|
|
const li = $(event.currentTarget).parents(".item")
|
|
|
|
const actor = game.actors.get(li.data("actor-id"))
|
|
|
|
let type = $(event.currentTarget).data("type")
|
|
|
|
let key = $(event.currentTarget).data("key")
|
|
|
|
actor.rollAttribut(key)
|
|
|
|
})
|
|
|
|
|
|
|
|
html.find('.actor-delete').click(event => {
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
let actorId = li.data("actor-id")
|
|
|
|
let newList = game.system.malefices.charSummary.settings.npcList.filter(id => id != actorId)
|
|
|
|
game.system.malefices.charSummary.settings.npcList = newList
|
|
|
|
game.system.malefices.charSummary.updateNPC()
|
|
|
|
})
|
|
|
|
|
2023-02-26 15:38:44 +01:00
|
|
|
}
|
2023-02-08 17:51:16 +01:00
|
|
|
|
|
|
|
}
|