Merge branch 'v1.4-fix' into 'v1.4'
fix déplacement hors conteneurs See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!253
This commit is contained in:
commit
cf75fb82d0
@ -968,6 +968,7 @@ export class RdDActor extends Actor {
|
|||||||
contenu.splice(index, 1);
|
contenu.splice(index, 1);
|
||||||
index = contenu.indexOf(item.id);
|
index = contenu.indexOf(item.id);
|
||||||
}
|
}
|
||||||
|
item.data.estContenu = false;
|
||||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||||
delete objetVersConteneur[item.id];
|
delete objetVersConteneur[item.id];
|
||||||
}
|
}
|
||||||
@ -980,6 +981,7 @@ export class RdDActor extends Actor {
|
|||||||
if (conteneur?.isConteneur()) {
|
if (conteneur?.isConteneur()) {
|
||||||
let data2use = duplicate(Misc.data(conteneur));
|
let data2use = duplicate(Misc.data(conteneur));
|
||||||
data2use.data.contenu.push(item.id);
|
data2use.data.contenu.push(item.id);
|
||||||
|
item.data.estContenu = true;
|
||||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||||
objetVersConteneur[item.id] = conteneur.id;
|
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') */
|
/** Fonction de remise à plat de l'équipement (ie vide les champs 'contenu') */
|
||||||
async nettoyerConteneurs() {
|
async nettoyerConteneurs() {
|
||||||
let conteneurs = this.items.filter(it => it.type == 'conteneur');
|
const corrections = [];
|
||||||
let conteneurFixedList = [];
|
for (let item of this.items) {
|
||||||
for (let conteneur of conteneurs) {
|
let itemData = Misc.data(item);
|
||||||
if (Misc.templateData(conteneur).contenu.length > 0) {
|
if (itemData.estContenu) {
|
||||||
conteneurFixedList.push({ _id: conteneur._id, 'data.contenu': [] });
|
itemData.estContenu = undefined;
|
||||||
|
}
|
||||||
|
if (itemData.type == 'conteneur' && itemData.data.contenu.length > 0) {
|
||||||
|
corrections.push({ _id: itemData._id, 'data.contenu': [] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conteneurFixedList.length > 0)
|
if (corrections.length > 0) {
|
||||||
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
|
await this.updateEmbeddedDocuments('Item', corrections);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async processDropItem(event, dragData, objetVersConteneur) {
|
async processDropItem(event, dragData, objetVersConteneur) {
|
||||||
@ -1010,39 +1016,35 @@ export class RdDActor extends Actor {
|
|||||||
let result = true;
|
let result = true;
|
||||||
const destId = $(event.target).parents(".item").attr("data-item-id");
|
const destId = $(event.target).parents(".item").attr("data-item-id");
|
||||||
const item = this.getObjet(itemId);
|
const item = this.getObjet(itemId);
|
||||||
if (item?.isEquipement()) {
|
if (item?.isEquipement() && dragData.actorId == this.id) {
|
||||||
if (dragData.actorId == this.id) {
|
|
||||||
// rangement
|
// rangement
|
||||||
const srcId = objetVersConteneur[itemId];
|
const srcId = objetVersConteneur[itemId];
|
||||||
if (srcId != destId && itemId != destId) { // déplacement de l'objet
|
if (srcId != destId && itemId != destId) { // déplacement de l'objet
|
||||||
const dest = this.getObjet(destId);
|
const dest = this.getObjet(destId);
|
||||||
const src = this.getObjet(srcId);
|
const src = this.getObjet(srcId);
|
||||||
if (dest?.isConteneur()) {
|
// changer de conteneur
|
||||||
if (this.conteneurPeutContenir(dest, item)) {
|
if (this.conteneurPeutContenir(dest, item)) {
|
||||||
await this.enleverDeConteneur(item, src, objetVersConteneur);
|
await this.enleverDeConteneur(item, src, objetVersConteneur);
|
||||||
await this.ajouterDansConteneur(item, dest, 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)) {
|
else if (dest?.isEquipementSimilaire(item)) {
|
||||||
await this.regrouperEquipementsSimilaires(item, dest);
|
await this.regrouperEquipementsSimilaires(item, dest);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
await this.computeEncombrementTotalEtMalusArmure();
|
await this.computeEncombrementTotalEtMalusArmure();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
conteneurPeutContenir(dest, item) {
|
conteneurPeutContenir(dest, item) {
|
||||||
|
if (!dest) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!dest.isConteneur()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const destData = Misc.data(dest);
|
const destData = Misc.data(dest);
|
||||||
if (this._isConteneurContenu(item, 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} !`);
|
ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${destData.name} !`);
|
||||||
|
@ -85,7 +85,7 @@ export class RdDItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isMagique() {
|
isMagique() {
|
||||||
return Misc.templateData(this.object).magique;
|
return Misc.templateData(this).magique;
|
||||||
}
|
}
|
||||||
|
|
||||||
getEnc() {
|
getEnc() {
|
||||||
|
@ -610,14 +610,13 @@
|
|||||||
</li>
|
</li>
|
||||||
{{#each objets as |item id|}}
|
{{#each objets as |item id|}}
|
||||||
{{#unless item.estContenu}}
|
{{#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 }}
|
{{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-conteneur.html" item=item }}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#each conteneurs as |conteneur id|}}
|
|
||||||
{{buildConteneur this}}
|
|
||||||
{{/each}}
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<span class="item-name"><h4>Montures</h4></span>
|
<span class="item-name"><h4>Montures</h4></span>
|
||||||
|
Loading…
Reference in New Issue
Block a user