Drop sur un objet met dans le conteneur parent #559
@ -1123,15 +1123,11 @@ export class RdDActor extends Actor {
|
||||
* de leurs ID */
|
||||
async enleverDeConteneur(item, conteneur, onEnleverDeConteneur) {
|
||||
if (conteneur?.isConteneur()) {
|
||||
let data2use = duplicate(conteneur);
|
||||
let contenu = data2use.system.contenu;
|
||||
let index = contenu.indexOf(item.id);
|
||||
while (index >= 0) { // Force cleanup, itemId is unique
|
||||
contenu.splice(index, 1);
|
||||
index = contenu.indexOf(item.id);
|
||||
}
|
||||
item.system.estContenu = false;
|
||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||
item.estContenu = false;
|
||||
await this.updateEmbeddedDocuments('Item', [{
|
||||
_id: conteneur.id,
|
||||
'system.contenu': conteneur.system.contenu.filter(id => id != item.id)
|
||||
}]);
|
||||
onEnleverDeConteneur();
|
||||
}
|
||||
}
|
||||
@ -1140,11 +1136,16 @@ export class RdDActor extends Actor {
|
||||
/** Ajoute un item dans un conteneur, sur la base
|
||||
* de leurs ID */
|
||||
async ajouterDansConteneur(item, conteneur, onAjouterDansConteneur) {
|
||||
if (conteneur?.isConteneur()) {
|
||||
let data2use = duplicate(conteneur);
|
||||
data2use.system.contenu.push(item.id);
|
||||
item.system.estContenu = true;
|
||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||
if (!conteneur) {
|
||||
// TODO: afficher
|
||||
item.estContenu = false;
|
||||
}
|
||||
else if (conteneur.isConteneur()) {
|
||||
item.estContenu = true;
|
||||
await this.updateEmbeddedDocuments('Item', [{
|
||||
_id: conteneur.id,
|
||||
'system.contenu': [...conteneur.system.contenu, item.id]
|
||||
}]);
|
||||
onAjouterDansConteneur(item.id, conteneur.id);
|
||||
}
|
||||
}
|
||||
@ -1182,23 +1183,39 @@ export class RdDActor extends Actor {
|
||||
if (item?.isEquipement() && sourceActorId == targetActorId) {
|
||||
// rangement
|
||||
if (srcId != destId && itemId != destId) { // déplacement de l'objet
|
||||
const dest = this.getObjet(destId);
|
||||
const src = this.getObjet(srcId);
|
||||
// changer de conteneur
|
||||
if (this.conteneurPeutContenir(dest, item)) {
|
||||
await this.enleverDeConteneur(item, src, params.onEnleverConteneur);
|
||||
await this.ajouterDansConteneur(item, dest, params.onAjouterDansConteneur);
|
||||
}
|
||||
else if (dest?.isEquipementSimilaire(item)) {
|
||||
const dest = this.getObjet(destId);
|
||||
const cible = this.getContenantOrParent(dest);
|
||||
const messageEquipementDifferent = item.messageEquipementDifferent(dest);
|
||||
if (dest && !messageEquipementDifferent) {
|
||||
await this.regrouperEquipementsSimilaires(item, dest);
|
||||
result = false;
|
||||
}
|
||||
// changer de conteneur
|
||||
else if (!cible || this.conteneurPeutContenir(cible, item)) {
|
||||
await this.enleverDeConteneur(item, src, params.onEnleverConteneur);
|
||||
await this.ajouterDansConteneur(item, cible, params.onAjouterDansConteneur);
|
||||
}
|
||||
else {
|
||||
ui.notifications.info(messageEquipementDifferent);
|
||||
}
|
||||
}
|
||||
}
|
||||
await this.computeEncombrementTotalEtMalusArmure();
|
||||
return result;
|
||||
}
|
||||
|
||||
getContenantOrParent(dest) {
|
||||
if (!dest || dest.isConteneur()) {
|
||||
return dest;
|
||||
}
|
||||
return this.getContenant(dest);
|
||||
}
|
||||
|
||||
getContenant(item) {
|
||||
return this.itemTypes['conteneur'].find(it => it.system.contenu.includes(item.id));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
conteneurPeutContenir(dest, item) {
|
||||
if (!dest) {
|
||||
|
@ -198,8 +198,9 @@ export class RdDItem extends Item {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// détermine si deux équipements sont similaires: de même type, et avec les même champs hormis la quantité
|
||||
isEquipementSimilaire(other) {
|
||||
if (!this.isEquipement()) return false;
|
||||
messageEquipementDifferent(other) {
|
||||
if (!other || !this.isEquipement()) return undefined;
|
||||
|
||||
let message = undefined;
|
||||
if (this.type != other.type) {
|
||||
message = `Impossible de regrouper ${this.type} avec ${other.type}`;
|
||||
@ -220,11 +221,7 @@ export class RdDItem extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message){
|
||||
ui.notifications.info(message)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return message;
|
||||
}
|
||||
|
||||
async proposerVente() {
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,52 +0,0 @@
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
<span class="sheet-competence-img conteneur-name">
|
||||
{{#if vide}}
|
||||
<i class="far fa-square"></i>
|
||||
{{else}}
|
||||
<a data-item-id="{{item._id}}">
|
||||
{{#if ouvert}}
|
||||
<i class="far fa-minus-square"></i>
|
||||
<!-- <i class="far fa-caret-square-down"></i> -->
|
||||
{{else}}
|
||||
<i class="far fa-plus-square"></i>
|
||||
<!-- <i class="fas fa-caret-square-right"></i> -->
|
||||
{{/if}}
|
||||
</a>
|
||||
{{/if}}
|
||||
</span>
|
||||
<span class="item-name conteneur-name flex-grow">
|
||||
<a data-item-id="{{item._id}}">
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
{{item.name}}
|
||||
</a>
|
||||
</span>
|
||||
{{else}}
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
<span class="item-name flex-grow">{{item.name}}</span>
|
||||
{{/if}}
|
||||
<span class="item-quantite">{{item.system.quantite}}
|
||||
{{#if (gt item.system.quantite 1)}}
|
||||
<a class="item-control item-split" title="Séparer"><i class="fas fa-unlink"></i></a>
|
||||
{{/if}}
|
||||
</span>
|
||||
<span class="item-quantite">{{numberFormat item.system.encTotal decimals=2}}</span>
|
||||
<div class="item-controls flex-grow">
|
||||
{{#unless item.estContenu}}
|
||||
{{#if (ne item.type 'conteneur')}}
|
||||
<a class="item-control item-equip" title="Equiper">{{#if item.system.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="far fa-hand-paper"></i>{{/if}}</a>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
{{#if (or (eq item.type 'arme') (eq item.type 'conteneur') item.system.quantite)}}
|
||||
|
||||
<a class="item-control item-vendre" title="Vendre ou donner"><i class="fas fa-comments-dollar"></i></a>
|
||||
{{/if}}
|
||||
<a class="item-control item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
|
||||
{{#if item.system.actionPrincipale}}
|
||||
<a class="item-name item-action">{{item.system.actionPrincipale}}</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
</li>
|
||||
|
@ -1,24 +1,16 @@
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
|
||||
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
{{#if vide}}
|
||||
<i class="far fa-square"></i>
|
||||
{{else}}
|
||||
<a data-item-id="{{item._id}}">
|
||||
{{#if ouvert}}
|
||||
<i class="far fa-minus-square"></i>
|
||||
{{else}}
|
||||
<i class="far fa-plus-square"></i>
|
||||
<a>
|
||||
<i class="{{~#if vide}}far fa-square
|
||||
{{else if ouvert}}far fa-minus-square
|
||||
{{else}}far fa-plus-square
|
||||
{{/if~}}"></i>
|
||||
{{/if}}
|
||||
</a>
|
||||
{{/if}}
|
||||
<a data-item-id="{{item._id}}">
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
<span>{{item.name}}</span>
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
</a>
|
||||
{{else}}
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
<span>{{item.name}}</span>
|
||||
{{/if}}
|
||||
</span>
|
||||
<span class="equipement-detail">{{item.system.quantite}}
|
||||
|
@ -13,12 +13,6 @@
|
||||
<span class="equipement-detail item-controls">
|
||||
<a class="monnaie-plus"><i class="fas fa-plus-square"></i></a>
|
||||
</span>
|
||||
|
||||
<!-- <span class="equipement-detail">
|
||||
<span class="flex-shrink"><a class="monnaie-moins"><i class="fas fa-minus-square"></i></a></span>
|
||||
<span>{{piece.system.quantite}}</span>
|
||||
<span class="flex-shrink"><a class="monnaie-plus"><i class="fas fa-plus-square"></i></a></span>
|
||||
</span> -->
|
||||
<span class="equipement-actions item-controls">
|
||||
<a class="item-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||
<a class="item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
|
Loading…
Reference in New Issue
Block a user