Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
4 changed files with 43 additions and 41 deletions
Showing only changes of commit 3152d87078 - Show all commits

View File

@ -161,7 +161,7 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onDrop(event) { async _onDrop(event) {
let toSuper = await RdDUtility.processItemDropEvent(this, event); let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
if (toSuper) { if (toSuper) {
super._onDrop(event); super._onDrop(event);
} }

View File

@ -68,7 +68,7 @@ export class RdDActorVehiculeSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onDrop(event) { async _onDrop(event) {
let toSuper = await RdDUtility.processItemDropEvent(this, event); let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
if ( toSuper) { if ( toSuper) {
super._onDrop(event); super._onDrop(event);
} }

View File

@ -828,11 +828,12 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
validateConteneur(itemId, conteneurId) { validateConteneur(itemId, conteneurId) {
const dest = this.getObjet(conteneurId); const dest = this.getObjet(conteneurId);
if (dest?.type != 'conteneur') { const item = this.getObjet(itemId);
ui.notifications.warn(`Impossible de déplacer un objet (${item.name}) vers un ${dest.type} qui n'est pas un conteneur (${dest.name}) !`); const destData = Misc.data(dest);
if (destData?.type != 'conteneur') {
ui.notifications.warn(`Impossible de déplacer un objet (${item.name}) vers un ${destData.type} qui n'est pas un conteneur (${dest.name}) !`);
return false; return false;
} }
const item = this.getObjet(itemId);
if (this._isConteneurContenu(item, conteneurId)) { if (this._isConteneurContenu(item, conteneurId)) {
ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${dest.name} !`); ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${dest.name} !`);
return false; // Loop detected ! return false; // Loop detected !
@ -841,7 +842,7 @@ export class RdDActor extends Actor {
} }
_isConteneurContenu(item, conteneurId) { _isConteneurContenu(item, conteneurId) {
if (item?.type == 'conteneur') { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant if (Misc.data(item)?.type == 'conteneur') { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant
for (let id of Misc.templateData(item).contenu) { for (let id of Misc.templateData(item).contenu) {
let subObjet = this.getObjet(id); let subObjet = this.getObjet(id);
if (subObjet?.id == conteneurId) { if (subObjet?.id == conteneurId) {
@ -972,6 +973,42 @@ export class RdDActor extends Actor {
await this.updateEmbeddedDocuments('Item', conteneurFixedList); await this.updateEmbeddedDocuments('Item', conteneurFixedList);
} }
/* -------------------------------------------- */
async processItemDropEvent(event, objetVersConteneur) {
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
console.log(dragData, this.id);
let objetId = dragData.id || dragData.data._id;
console.log("DRAG", dragData);
if (dragData.type == 'Item') {
if (dragData.actorId) {
if (dragData.actorId != this.id) {
console.log("Moving objects", dragData);
this.moveItemsBetweenActors(objetId, dragData.actorId);
return false;
}
else {
// rangement
const destId = $(event.target).parents(".item").attr("data-item-id");
const srcId = objetVersConteneur[objetId];
if (srcId != destId && objetId != destId && this.isConteneurSuffisant(objetId, destId)) {
if (srcId) {
await this.enleverDeConteneur(objetId, srcId);
}
if (destId) { // Dropped over an item !!!
await this.ajouterAConteneur(objetId, destId);
}
}
}
}
this.computeEncombrementTotalEtMalusArmure();
}
if (dragData.type == "Actor") {
this.addSubacteur(objetId);
}
return true;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async moveItemsBetweenActors(itemId, sourceActorId) { async moveItemsBetweenActors(itemId, sourceActorId) {
let itemsList = [] let itemsList = []

View File

@ -281,41 +281,6 @@ export class RdDUtility {
formData.competences = (formData.itemsByType.competence ?? []).concat(formData.itemsByType.competencecreature ?? []); formData.competences = (formData.itemsByType.competence ?? []).concat(formData.itemsByType.competencecreature ?? []);
} }
/* -------------------------------------------- */
static async processItemDropEvent(actorSheet, event) {
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
console.log(dragData, actorSheet.actor.id);
let objetId = dragData.id || dragData.data._id;
console.log("DRAG", dragData);
if (dragData.type == 'Item') {
if (dragData.actorId) {
if (dragData.actorId != actorSheet.actor.id) {
console.log("Moving objects", dragData);
actorSheet.actor.moveItemsBetweenActors(objetId, dragData.actorId);
return false;
}
else {
// rangement
const destId = $(event.target).parents(".item").attr("data-item-id");
const srcId = actorSheet.objetVersConteneur[objetId];
if (srcId != destId && objetId != destId && actorSheet.actor.isConteneurSuffisant(objetId, destId)) {
if (srcId) {
await actorSheet.actor.enleverDeConteneur(objetId, srcId);
}
if (destId) { // Dropped over an item !!!
await actorSheet.actor.ajouterAConteneur(objetId, destId);
}
}
}
}
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
} else if (dragData.type == "Actor") {
actorSheet.actor.addSubacteur(objetId);
}
return true;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildArbreDeConteneur(actorSheet, formData) { static buildArbreDeConteneur(actorSheet, formData) {
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant) actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)