Fix sortie de conteneur
This commit is contained in:
parent
6eb79c3ec7
commit
56c82d935a
@ -37,7 +37,8 @@ export class RdDActorCreatureSheet extends RdDActorSheet {
|
|||||||
formData.calc.surEncombrementMessage = (formData.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
|
formData.calc.surEncombrementMessage = (formData.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
|
||||||
|
|
||||||
RdDUtility.filterItemsPerTypeForSheet(formData);
|
RdDUtility.filterItemsPerTypeForSheet(formData);
|
||||||
RdDUtility.buildArbreDeConteneur(this, formData);
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||||
|
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
||||||
|
|
||||||
console.log("Creature : ", this.objetVersConteneur, formData);
|
console.log("Creature : ", this.objetVersConteneur, formData);
|
||||||
|
|
||||||
|
@ -112,7 +112,9 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
cacheTMR: this.actor.isTMRCache()
|
cacheTMR: this.actor.isTMRCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
RdDUtility.buildArbreDeConteneur(this, formData);
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||||
|
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
||||||
|
|
||||||
formData.subacteurs = {
|
formData.subacteurs = {
|
||||||
vehicules: this.actor.listeVehicules(),
|
vehicules: this.actor.listeVehicules(),
|
||||||
montures: this.actor.listeMontures(),
|
montures: this.actor.listeMontures(),
|
||||||
@ -130,10 +132,17 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
async _onDropActor(event, dragData) {
|
||||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
console.log("DRAG", this.actor.id, dragData);
|
||||||
if (toSuper) {
|
this.actor.addSubacteur(dragData.id || dragData.data._id);
|
||||||
super._onDrop(event);
|
super._onDropActor(event, dragData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
async _onDropItem(event, dragData) {
|
||||||
|
const callSuper = await this.actor.processDropItem(event, dragData, this.objetVersConteneur);
|
||||||
|
if (callSuper) {
|
||||||
|
await super._onDropItem(event, dragData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,14 +230,11 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
const item = this.actor.items.get(li.data("item-id"));
|
const item = this.actor.items.get(li.data("item-id"));
|
||||||
item.sheet.render(true);
|
item.sheet.render(true);
|
||||||
});
|
});
|
||||||
// Update Inventory Item
|
|
||||||
html.find('.rencontre-delete').click(ev => {
|
html.find('.rencontre-delete').click(ev => {
|
||||||
const li = $(ev.currentTarget).parents(".item");
|
const li = $(ev.currentTarget).parents(".item");
|
||||||
const rencontreKey = li.data("item-id");
|
const rencontreKey = li.data("item-id");
|
||||||
this.actor.deleteTMRRencontre(rencontreKey);
|
this.actor.deleteTMRRencontre(rencontreKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete Inventory Item
|
|
||||||
html.find('.item-delete').click(ev => {
|
html.find('.item-delete').click(ev => {
|
||||||
const li = $(ev.currentTarget).parents(".item");
|
const li = $(ev.currentTarget).parents(".item");
|
||||||
RdDUtility.confirmerSuppression(this, li);
|
RdDUtility.confirmerSuppression(this, li);
|
||||||
|
@ -52,7 +52,8 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RdDUtility.filterItemsPerTypeForSheet(formData);
|
RdDUtility.filterItemsPerTypeForSheet(formData);
|
||||||
RdDUtility.buildArbreDeConteneur(this, formData);
|
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||||
|
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
||||||
|
|
||||||
formData.options.isGM = game.user.isGM;
|
formData.options.isGM = game.user.isGM;
|
||||||
|
|
||||||
@ -67,10 +68,10 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
async _onDropItem(event, dragData) {
|
||||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
const callSuper = await this.actor.processDropItem(event, dragData, this.objetVersConteneur);
|
||||||
if ( toSuper) {
|
if (callSuper) {
|
||||||
super._onDrop(event);
|
await super._onDropItem(event, dragData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,28 +920,29 @@ export class RdDActor extends Actor {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
/** Supprime un item d'un conteneur, sur la base
|
/** Supprime un item d'un conteneur, sur la base
|
||||||
* de leurs ID */
|
* de leurs ID */
|
||||||
async enleverDeConteneur(itemId, conteneur) {
|
async enleverDeConteneur(item, conteneur, objetVersConteneur) {
|
||||||
if (conteneur?.isConteneur()) { // Si présent
|
if (conteneur?.isConteneur()) {
|
||||||
let data2use = duplicate(Misc.data(conteneur));
|
let data2use = duplicate(Misc.data(conteneur));
|
||||||
//console.log("Suppression du conteneur1", conteneurId, itemId, data2use.data.contenu);
|
|
||||||
let contenu = data2use.data.contenu;
|
let contenu = data2use.data.contenu;
|
||||||
let index = contenu.indexOf(itemId);
|
let index = contenu.indexOf(item.id);
|
||||||
while (index >= 0) { // Force cleanup, itemId is unique
|
while (index >= 0) { // Force cleanup, itemId is unique
|
||||||
contenu.splice(index, 1);
|
contenu.splice(index, 1);
|
||||||
index = contenu.indexOf(itemId);
|
index = contenu.indexOf(item.id);
|
||||||
}
|
}
|
||||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||||
|
delete objetVersConteneur[item.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
/** Ajoute un item dans un conteneur, sur la base
|
/** Ajoute un item dans un conteneur, sur la base
|
||||||
* de leurs ID */
|
* de leurs ID */
|
||||||
async ajouterDansConteneur(itemId, conteneur) {
|
async ajouterDansConteneur(item, conteneur, objetVersConteneur) {
|
||||||
if (conteneur?.isConteneur()) {
|
if (conteneur?.isConteneur()) {
|
||||||
let data2use = duplicate(Misc.data(conteneur));
|
let data2use = duplicate(Misc.data(conteneur));
|
||||||
data2use.data.contenu.push(itemId);
|
data2use.data.contenu.push(item.id);
|
||||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||||
|
objetVersConteneur[item.id] = conteneur.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -959,54 +960,52 @@ export class RdDActor extends Actor {
|
|||||||
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
|
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
async processDropItem(event, dragData, objetVersConteneur) {
|
||||||
async processItemDropEvent(event, objetVersConteneur) {
|
|
||||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
|
||||||
console.log("DRAG", this.id, dragData);
|
console.log("DRAG", this.id, dragData);
|
||||||
let itemId = dragData.id || dragData.data._id;
|
const droppedItemId = dragData.id || dragData.data._id;
|
||||||
if (dragData.type == 'Item') {
|
|
||||||
if (dragData.actorId && dragData.actorId != this.id) {
|
if (dragData.actorId && dragData.actorId != this.id) {
|
||||||
console.log("Moving objects", dragData);
|
console.log("Moving objects", dragData);
|
||||||
this.moveItemsBetweenActors(itemId, dragData.actorId);
|
this.moveItemsBetweenActors(droppedItemId, dragData.actorId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (dragData.actorId == this.id) {
|
|
||||||
// rangement
|
|
||||||
const destId = $(event.target).parents(".item").attr("data-item-id");
|
|
||||||
const srcId = objetVersConteneur[itemId];
|
|
||||||
if (srcId != destId && itemId != destId) { // déplacement de l'objet
|
|
||||||
const item = this.getObjet(itemId);
|
|
||||||
const dest = this.getObjet(destId);
|
|
||||||
const src = this.getObjet(srcId);
|
|
||||||
if (!dest) {
|
|
||||||
// on peut toujours vider son sac
|
|
||||||
await this.enleverDeConteneur(itemId, src);
|
|
||||||
}
|
|
||||||
else if (!dest.isConteneur()) {
|
|
||||||
// regrouper?
|
|
||||||
await this.regrouperEquipementsSimilaires(item, dest);
|
|
||||||
}
|
|
||||||
else if (this.conteneurPeutContenir(dest, item)) {
|
|
||||||
// déplacer?
|
|
||||||
await this.enleverDeConteneur(itemId, src);
|
|
||||||
await this.ajouterDansConteneur(itemId, dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.computeEncombrementTotalEtMalusArmure();
|
|
||||||
}
|
|
||||||
if (dragData.type == "Actor") {
|
|
||||||
this.addSubacteur(itemId);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let result = true;
|
||||||
|
const destId = $(event.target).parents(".item").attr("data-item-id");
|
||||||
|
const itemId = dragData.id || dragData.data._id;
|
||||||
|
const item = this.getObjet(itemId);
|
||||||
|
if (item.isEquipement()) {
|
||||||
|
if (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()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await this.computeEncombrementTotalEtMalusArmure();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/* -------------------------------------------- */
|
||||||
conteneurPeutContenir(dest, item) {
|
conteneurPeutContenir(dest, item) {
|
||||||
const destData = Misc.data(dest);
|
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;
|
|
||||||
}
|
|
||||||
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} !`);
|
||||||
return false; // Loop detected !
|
return false; // Loop detected !
|
||||||
@ -1061,11 +1060,9 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async regrouperEquipementsSimilaires(item, dest) {
|
async regrouperEquipementsSimilaires(item, dest) {
|
||||||
if (item.isEquipementSimilaire(dest)) {
|
|
||||||
await dest.quantiteIncDec(Misc.templateData(item).quantite);
|
await dest.quantiteIncDec(Misc.templateData(item).quantite);
|
||||||
await this.deleteEmbeddedDocuments('Item', [item.id]);
|
await this.deleteEmbeddedDocuments('Item', [item.id]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
detectSurEncombrement() {
|
detectSurEncombrement() {
|
||||||
@ -2348,7 +2345,7 @@ export class RdDActor extends Actor {
|
|||||||
// Mise à jour de la tache
|
// Mise à jour de la tache
|
||||||
rollData.tache = duplicate(rollData.tache);
|
rollData.tache = duplicate(rollData.tache);
|
||||||
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
|
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
|
||||||
if (rollData.rolled.isETotal){
|
if (rollData.rolled.isETotal) {
|
||||||
rollData.tache.data.difficulte--;
|
rollData.tache.data.difficulte--;
|
||||||
}
|
}
|
||||||
this.updateEmbeddedDocuments('Item', [rollData.tache]);
|
this.updateEmbeddedDocuments('Item', [rollData.tache]);
|
||||||
|
@ -63,9 +63,9 @@ export class Misc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static classify(items, classifier = it => it.type, transform = it => it) {
|
static classify(items, classifier = it => it.type) {
|
||||||
let itemsBy = {};
|
let itemsBy = {};
|
||||||
Misc.classifyInto(itemsBy, items, classifier, transform);
|
Misc.classifyInto(itemsBy, items, classifier);
|
||||||
return itemsBy;
|
return itemsBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ export class Misc {
|
|||||||
return itemsBy;
|
return itemsBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static classifyInto(itemsBy, items, classifier = it => it.type, transform = it => it) {
|
static classifyInto(itemsBy, items, classifier = it => it.type) {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const classification = classifier(item);
|
const classification = classifier(item);
|
||||||
let list = itemsBy[classification];
|
let list = itemsBy[classification];
|
||||||
@ -88,11 +88,8 @@ export class Misc {
|
|||||||
list = [];
|
list = [];
|
||||||
itemsBy[classification] = list;
|
itemsBy[classification] = list;
|
||||||
}
|
}
|
||||||
list.push(transform(item));
|
list.push(item);
|
||||||
}
|
}
|
||||||
for (const [key, list] of Object.entries(itemsBy)) {
|
|
||||||
list.sort();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static rollOneOf(array) {
|
static rollOneOf(array) {
|
||||||
|
@ -296,30 +296,34 @@ export class RdDUtility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static buildArbreDeConteneur(actorSheet, formData) {
|
static buildArbreDeConteneurs(conteneurs, objets) {
|
||||||
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
let objetVersConteneur = {};
|
||||||
// Attribution des objets aux conteneurs
|
// Attribution des objets aux conteneurs
|
||||||
for (let conteneur of formData.conteneurs) {
|
for (let conteneur of conteneurs) {
|
||||||
conteneur.subItems = [];
|
conteneur.subItems = [];
|
||||||
if (!conteneur.data.encTotal) conteneur.data.encTotal = 0;
|
if (!conteneur.data.encTotal)
|
||||||
|
conteneur.data.encTotal = 0;
|
||||||
//conteneur.data.encTotal = ; Deja calculé
|
//conteneur.data.encTotal = ; Deja calculé
|
||||||
if (conteneur.data.contenu) {
|
if (conteneur.data.contenu) {
|
||||||
for (let id of conteneur.data.contenu) {
|
for (let id of conteneur.data.contenu) {
|
||||||
let objet = formData.objets.find(objet => (id == objet._id));
|
let objet = objets.find(objet => (id == objet._id));
|
||||||
if (objet) {
|
if (objet) {
|
||||||
if (!objet.data.encombrement) objet.data.encombrement = 0; // Auto-fix
|
if (!objet.data.encombrement)
|
||||||
|
objet.data.encombrement = 0; // Auto-fix
|
||||||
objet.estContenu = true; // Permet de filtrer ce qifui est porté dans le template
|
objet.estContenu = true; // Permet de filtrer ce qifui est porté dans le template
|
||||||
actorSheet.objetVersConteneur[id] = conteneur._id;
|
objetVersConteneur[id] = conteneur._id;
|
||||||
conteneur.data.encTotal += Number(objet.data.encombrement) * Number(((objet.data.quantite) ? objet.data.quantite : 1));
|
conteneur.data.encTotal += Number(objet.data.encombrement) * Number(((objet.data.quantite) ? objet.data.quantite : 1));
|
||||||
conteneur.subItems.push(objet);
|
conteneur.subItems.push(objet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return objetVersConteneur;
|
||||||
|
}
|
||||||
|
|
||||||
// Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur)
|
// Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur)
|
||||||
let newConteneurs = formData.conteneurs.filter(function (conteneur, index, arr) { return !conteneur.estContenu });
|
static conteneursRacine(conteneurs) {
|
||||||
formData.conteneurs = newConteneurs;
|
return conteneurs.filter( (conteneur, index, arr) => !conteneur.estContenu);
|
||||||
//console.log(newConteneurs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user