fix déplacement hors conteneurs #470

Merged
vincent.vandeme merged 1 commits from v1.4-fix into v1.4 2021-05-25 23:46:53 +02:00
2 changed files with 37 additions and 36 deletions
Showing only changes of commit 1624f9292c - Show all commits

View File

@ -968,6 +968,7 @@ export class RdDActor extends Actor {
contenu.splice(index, 1);
index = contenu.indexOf(item.id);
}
item.data.estContenu = false;
await this.updateEmbeddedDocuments('Item', [data2use]);
delete objetVersConteneur[item.id];
}
@ -980,6 +981,7 @@ export class RdDActor extends Actor {
if (conteneur?.isConteneur()) {
let data2use = duplicate(Misc.data(conteneur));
data2use.data.contenu.push(item.id);
item.data.estContenu = true;
await this.updateEmbeddedDocuments('Item', [data2use]);
objetVersConteneur[item.id] = conteneur.id;
}
@ -988,15 +990,19 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
/** Fonction de remise à plat de l'équipement (ie vide les champs 'contenu') */
async nettoyerConteneurs() {
let conteneurs = this.items.filter(it => it.type == 'conteneur');
let conteneurFixedList = [];
for (let conteneur of conteneurs) {
if (Misc.templateData(conteneur).contenu.length > 0) {
conteneurFixedList.push({ _id: conteneur._id, 'data.contenu': [] });
const corrections = [];
for (let item of this.items) {
let itemData = Misc.data(item);
if (itemData.estContenu) {
itemData.estContenu = undefined;
}
if (itemData.type == 'conteneur' && itemData.data.contenu.length > 0) {
corrections.push({ _id: itemData._id, 'data.contenu': [] });
}
}
if (conteneurFixedList.length > 0)
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
if (corrections.length > 0) {
await this.updateEmbeddedDocuments('Item', corrections);
}
}
async processDropItem(event, dragData, objetVersConteneur) {
@ -1010,39 +1016,35 @@ export class RdDActor extends Actor {
let result = true;
const destId = $(event.target).parents(".item").attr("data-item-id");
const item = this.getObjet(itemId);
if (item?.isEquipement()) {
if (dragData.actorId == this.id) {
if (item?.isEquipement() && dragData.actorId == this.id) {
// rangement
const srcId = objetVersConteneur[itemId];
if (srcId != destId && itemId != destId) { // déplacement de l'objet
const dest = this.getObjet(destId);
const src = this.getObjet(srcId);
if (dest?.isConteneur()) {
// changer de conteneur
if (this.conteneurPeutContenir(dest, item)) {
await this.enleverDeConteneur(item, src, objetVersConteneur);
await this.ajouterDansConteneur(item, dest, objetVersConteneur);
}
}
else {
if (src?.isConteneur() && !item?.isConteneur()) {
await this.enleverDeConteneur(item, src, objetVersConteneur);
// simuler la re-création
dragData.actorId = null;
await this.deleteEmbeddedDocuments('Item', [item.id]);
}
else if (dest?.isEquipementSimilaire(item)) {
await this.regrouperEquipementsSimilaires(item, dest);
result = false;
}
}
}
}
}
await this.computeEncombrementTotalEtMalusArmure();
return result;
}
/* -------------------------------------------- */
conteneurPeutContenir(dest, item) {
if (!dest) {
return true;
}
if (!dest.isConteneur()) {
return false;
}
const destData = Misc.data(dest);
if (this._isConteneurContenu(item, dest)) {
ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${destData.name} !`);

View File

@ -610,14 +610,13 @@
</li>
{{#each objets as |item id|}}
{{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}}
{{#if (eq item.type 'conteneur')}}
{{buildConteneur this}}
{{else}}
{{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-conteneur.html" item=item }}
{{/if}}
{{/unless}}
{{/each}}
{{#each conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</ul>
<span class="item-name"><h4>Montures</h4></span>