Migration vers datamodels

This commit is contained in:
2026-02-26 13:45:24 +01:00
parent b0c6b2a3e8
commit 497c687eb8
33 changed files with 187 additions and 180 deletions

View File

@@ -1,8 +1,32 @@
/* -------------------------------------------- */
import { EcrymeUtility } from "../common/ecryme-utility.js";
const { HandlebarsApplicationMixin } = foundry.applications.api
/* -------------------------------------------- */
export class EcrymeCharacterSummary extends Application {
export class EcrymeCharacterSummary extends HandlebarsApplicationMixin(foundry.applications.api.ApplicationV2) {
/* -------------------------------------------- */
static DEFAULT_OPTIONS = {
id: "ecryme-character-summary",
classes: ["fvtt-ecryme", "dialog"],
position: { width: 920 },
window: { title: "ECRY.ui.charactersummary", resizable: true },
actions: {
actorOpen: EcrymeCharacterSummary.#onActorOpen,
summaryRoll: EcrymeCharacterSummary.#onSummaryRoll,
actorDelete: EcrymeCharacterSummary.#onActorDelete,
},
}
/* -------------------------------------------- */
static PARTS = {
content: { template: "systems/fvtt-ecryme/templates/dialogs/character-summary.hbs" },
}
/* -------------------------------------------- */
constructor(options = {}) {
super(options)
this.settings = game.settings.get("fvtt-ecryme", "character-summary-data")
}
/* -------------------------------------------- */
static displayPCSummary() {
@@ -16,18 +40,13 @@ export class EcrymeCharacterSummary extends Application {
/* -------------------------------------------- */
updatePCSummary() {
if (this.rendered) {
this.render(true)
this.render()
}
}
/* -------------------------------------------- */
static createSummaryPos() {
return { top: 200, left: 200 };
}
/* -------------------------------------------- */
static ready() {
if (!game.user.isGM) { // Uniquement si GM
if (!game.user.isGM) {
return
}
let charSummary = new EcrymeCharacterSummary()
@@ -35,100 +54,81 @@ export class EcrymeCharacterSummary extends Application {
}
/* -------------------------------------------- */
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 foundry.utils.mergeObject(super.defaultOptions, {
template: "systems/fvtt-ecryme/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();
formData.pcs = game.actors.filter(ac => ac.type == "personnage" && ac.hasPlayerOwner)
formData.npcs = []
async _prepareContext() {
let pcs = game.actors.filter(ac => ac.type == "pc" && ac.hasPlayerOwner)
let npcs = []
let newList = []
let toUpdate = false
for (let actorId of this.settings.npcList) {
let actor = game.actors.get(actorId)
if (actor) {
formData.npcs.push(actor)
npcs.push(actor)
newList.push(actorId)
} else {
toUpdate = true
}
}
formData.config = game.system.ecryme.config
if (toUpdate) {
this.settings.npcList = newList
//console.log("Going to update ...", this.settings)
game.settings.set("world", "character-summary-data", this.settings)
game.settings.set("fvtt-ecryme", "character-summary-data", this.settings)
}
return {
pcs,
npcs,
config: game.system.ecryme.config,
}
return formData
}
/* -------------------------------------------- */
updateNPC() {
game.settings.set("world", "character-summary-data", game.system.ecryme.charSummary.settings)
game.system.ecryme.charSummary.close()
setTimeout(function () { game.system.ecryme.charSummary.render(true) }, 500)
game.settings.set("fvtt-ecryme", "character-summary-data", this.settings)
this.close()
setTimeout(() => this.render(true), 500)
}
/* -------------------------------------------- */
async _onDrop(event) {
//console.log("Dragged data are : ", dragData)
let data = event.dataTransfer.getData('text/plain')
let dataItem = JSON.parse(data)
let actor = fromUuidSync(dataItem.uuid)
if (actor) {
game.system.ecryme.charSummary.settings.npcList.push(actor.id)
game.system.ecryme.charSummary.updateNPC()
_onDragOver(event) {
event.preventDefault()
}
/* -------------------------------------------- */
_onDrop(event) {
let data
try { data = JSON.parse(event.dataTransfer.getData('text/plain')) } catch(e) { return }
let actor = fromUuidSync(data.uuid)
if (actor) {
this.settings.npcList.push(actor.id)
this.updateNPC()
} else {
ui.notifications.warn("Pas d'acteur trouvé")
}
}
/* -------------------------------------------- */
/** @override */
async activateListeners(html) {
super.activateListeners(html);
_onRender(context, options) {
super._onRender(context, options)
this.element.addEventListener("dragover", this._onDragOver.bind(this))
this.element.addEventListener("drop", this._onDrop.bind(this))
}
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)
})
/* -------------------------------------------- */
static #onActorOpen(event, target) {
const actorId = target.closest("[data-actor-id]").dataset.actorId
game.actors.get(actorId)?.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.ecryme.charSummary.settings.npcList.filter(id => id != actorId)
game.system.ecryme.charSummary.settings.npcList = newList
game.system.ecryme.charSummary.updateNPC()
})
/* -------------------------------------------- */
static #onSummaryRoll(event, target) {
const actorId = target.closest("[data-actor-id]").dataset.actorId
const key = target.dataset.key
game.actors.get(actorId)?.rollAttribut(key)
}
/* -------------------------------------------- */
static #onActorDelete(event, target) {
const actorId = target.closest("[data-actor-id]").dataset.actorId
this.settings.npcList = this.settings.npcList.filter(id => id !== actorId)
this.updateNPC()
}
}

View File

@@ -101,6 +101,13 @@ export class EcrymeUtility {
restricted: true
})
game.settings.register("fvtt-ecryme", "character-summary-data", {
scope: 'world',
config: false,
type: Object,
default: { npcList: [] }
})
this.buildSkillConfig()
}