Gestion des signes draconiques #455
@ -37,7 +37,8 @@ export class RdDActorCreatureSheet extends RdDActorSheet {
|
||||
formData.calc.surEncombrementMessage = (formData.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
|
||||
|
||||
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);
|
||||
|
||||
|
@ -112,7 +112,9 @@ export class RdDActorSheet extends ActorSheet {
|
||||
cacheTMR: this.actor.isTMRCache()
|
||||
}
|
||||
|
||||
RdDUtility.buildArbreDeConteneur(this, formData);
|
||||
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
|
||||
|
||||
formData.subacteurs = {
|
||||
vehicules: this.actor.listeVehicules(),
|
||||
montures: this.actor.listeMontures(),
|
||||
@ -130,10 +132,17 @@ export class RdDActorSheet extends ActorSheet {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
||||
if (toSuper) {
|
||||
super._onDrop(event);
|
||||
async _onDropActor(event, dragData) {
|
||||
console.log("DRAG", this.actor.id, dragData);
|
||||
this.actor.addSubacteur(dragData.id || dragData.data._id);
|
||||
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"));
|
||||
item.sheet.render(true);
|
||||
});
|
||||
// Update Inventory Item
|
||||
html.find('.rencontre-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
const rencontreKey = li.data("item-id");
|
||||
this.actor.deleteTMRRencontre(rencontreKey);
|
||||
});
|
||||
|
||||
// Delete Inventory Item
|
||||
html.find('.item-delete').click(ev => {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
RdDUtility.confirmerSuppression(this, li);
|
||||
|
@ -52,7 +52,8 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
@ -67,10 +68,10 @@ export class RdDActorVehiculeSheet extends ActorSheet {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async _onDrop(event) {
|
||||
let toSuper = await this.actor.processItemDropEvent(event, this.objetVersConteneur);
|
||||
if ( toSuper) {
|
||||
super._onDrop(event);
|
||||
async _onDropItem(event, dragData) {
|
||||
const callSuper = await this.actor.processDropItem(event, dragData, this.objetVersConteneur);
|
||||
if (callSuper) {
|
||||
await super._onDropItem(event, dragData)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -920,28 +920,29 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
/** Supprime un item d'un conteneur, sur la base
|
||||
* de leurs ID */
|
||||
async enleverDeConteneur(itemId, conteneur) {
|
||||
if (conteneur?.isConteneur()) { // Si présent
|
||||
async enleverDeConteneur(item, conteneur, objetVersConteneur) {
|
||||
if (conteneur?.isConteneur()) {
|
||||
let data2use = duplicate(Misc.data(conteneur));
|
||||
//console.log("Suppression du conteneur1", conteneurId, itemId, 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
|
||||
contenu.splice(index, 1);
|
||||
index = contenu.indexOf(itemId);
|
||||
index = contenu.indexOf(item.id);
|
||||
}
|
||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||
delete objetVersConteneur[item.id];
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Ajoute un item dans un conteneur, sur la base
|
||||
* de leurs ID */
|
||||
async ajouterDansConteneur(itemId, conteneur) {
|
||||
async ajouterDansConteneur(item, conteneur, objetVersConteneur) {
|
||||
if (conteneur?.isConteneur()) {
|
||||
let data2use = duplicate(Misc.data(conteneur));
|
||||
data2use.data.contenu.push(itemId);
|
||||
data2use.data.contenu.push(item.id);
|
||||
await this.updateEmbeddedDocuments('Item', [data2use]);
|
||||
objetVersConteneur[item.id] = conteneur.id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -959,54 +960,52 @@ export class RdDActor extends Actor {
|
||||
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processItemDropEvent(event, objetVersConteneur) {
|
||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||
async processDropItem(event, dragData, objetVersConteneur) {
|
||||
console.log("DRAG", this.id, dragData);
|
||||
let itemId = dragData.id || dragData.data._id;
|
||||
if (dragData.type == 'Item') {
|
||||
if (dragData.actorId && dragData.actorId != this.id) {
|
||||
console.log("Moving objects", dragData);
|
||||
this.moveItemsBetweenActors(itemId, dragData.actorId);
|
||||
return false;
|
||||
}
|
||||
const droppedItemId = dragData.id || dragData.data._id;
|
||||
if (dragData.actorId && dragData.actorId != this.id) {
|
||||
console.log("Moving objects", dragData);
|
||||
this.moveItemsBetweenActors(droppedItemId, dragData.actorId);
|
||||
return false;
|
||||
}
|
||||
|
||||
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 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);
|
||||
if (dest?.isConteneur()) {
|
||||
if (this.conteneurPeutContenir(dest, item)) {
|
||||
await this.enleverDeConteneur(item, src, objetVersConteneur);
|
||||
await this.ajouterDansConteneur(item, dest, objetVersConteneur);
|
||||
}
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.computeEncombrementTotalEtMalusArmure();
|
||||
await this.computeEncombrementTotalEtMalusArmure();
|
||||
}
|
||||
if (dragData.type == "Actor") {
|
||||
this.addSubacteur(itemId);
|
||||
}
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
conteneurPeutContenir(dest, item) {
|
||||
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)) {
|
||||
ui.notifications.warn(`Impossible de déplacer un conteneur parent (${item.name}) dans un de ses contenus ${destData.name} !`);
|
||||
return false; // Loop detected !
|
||||
@ -1061,10 +1060,8 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
async regrouperEquipementsSimilaires(item, dest) {
|
||||
if (item.isEquipementSimilaire(dest)) {
|
||||
await dest.quantiteIncDec(Misc.templateData(item).quantite);
|
||||
await this.deleteEmbeddedDocuments('Item', [item.id]);
|
||||
}
|
||||
await dest.quantiteIncDec(Misc.templateData(item).quantite);
|
||||
await this.deleteEmbeddedDocuments('Item', [item.id]);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -2348,7 +2345,7 @@ export class RdDActor extends Actor {
|
||||
// Mise à jour de la tache
|
||||
rollData.tache = duplicate(rollData.tache);
|
||||
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
|
||||
if (rollData.rolled.isETotal){
|
||||
if (rollData.rolled.isETotal) {
|
||||
rollData.tache.data.difficulte--;
|
||||
}
|
||||
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 = {};
|
||||
Misc.classifyInto(itemsBy, items, classifier, transform);
|
||||
Misc.classifyInto(itemsBy, items, classifier);
|
||||
return itemsBy;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ export class Misc {
|
||||
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) {
|
||||
const classification = classifier(item);
|
||||
let list = itemsBy[classification];
|
||||
@ -88,11 +88,8 @@ export class Misc {
|
||||
list = [];
|
||||
itemsBy[classification] = list;
|
||||
}
|
||||
list.push(transform(item));
|
||||
list.push(item);
|
||||
}
|
||||
for (const [key, list] of Object.entries(itemsBy)) {
|
||||
list.sort();
|
||||
};
|
||||
}
|
||||
|
||||
static rollOneOf(array) {
|
||||
|
@ -296,30 +296,34 @@ export class RdDUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildArbreDeConteneur(actorSheet, formData) {
|
||||
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
||||
static buildArbreDeConteneurs(conteneurs, objets) {
|
||||
let objetVersConteneur = {};
|
||||
// Attribution des objets aux conteneurs
|
||||
for (let conteneur of formData.conteneurs) {
|
||||
for (let conteneur of conteneurs) {
|
||||
conteneur.subItems = [];
|
||||
if (!conteneur.data.encTotal) conteneur.data.encTotal = 0;
|
||||
if (!conteneur.data.encTotal)
|
||||
conteneur.data.encTotal = 0;
|
||||
//conteneur.data.encTotal = ; Deja calculé
|
||||
if (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.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
|
||||
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.subItems.push(objet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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 });
|
||||
formData.conteneurs = newConteneurs;
|
||||
//console.log(newConteneurs);
|
||||
return objetVersConteneur;
|
||||
}
|
||||
|
||||
// Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur)
|
||||
static conteneursRacine(conteneurs) {
|
||||
return conteneurs.filter( (conteneur, index, arr) => !conteneur.estContenu);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user