diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 21c172db..e5ac0586 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -26,7 +26,6 @@ export class RdDActorSheet extends ActorSheet { classes: ["rdd", "sheet", "actor"], template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html", width: 640, - //height: 720, tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }], dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }], editCaracComp: false, @@ -132,13 +131,15 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async _onDropActor(event, dragData) { - console.log("DRAG", this.actor.id, dragData); + console.log("_onDropActor", 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(RdDSheetUtility.extractItemDropParameters(event, dragData, this.actor, this.objetVersConteneur)); + const destItemId = RdDSheetUtility.getItemId(event); + const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor.id, dragData, this.objetVersConteneur); + const callSuper = await this.actor.processDropItem(dropParams); if (callSuper) { await super._onDropItem(event, dragData) } diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 8413933b..8b2f6096 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -70,7 +70,9 @@ export class RdDActorVehiculeSheet extends ActorSheet { /* -------------------------------------------- */ async _onDropItem(event, dragData) { - const callSuper = await this.actor.processDropItem(RdDSheetUtility.extractItemDropParameters(event, dragData, this.actor, this.objetVersConteneur)); + const destItemId = RdDSheetUtility.getItemId(event); + const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor.id, dragData, this.objetVersConteneur); + const callSuper = await this.actor.processDropItem(dropParams); if (callSuper) { await super._onDropItem(event, dragData) } diff --git a/module/actor.js b/module/actor.js index b05ea40c..f2535015 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1159,7 +1159,7 @@ export class RdDActor extends Actor { data2use.data.contenu.push(item.id); item.data.estContenu = true; await this.updateEmbeddedDocuments('Item', [data2use]); - onAjouterDansConteneur(conteneur.id); + onAjouterDansConteneur(item.id, conteneur.id); } } @@ -1181,7 +1181,7 @@ export class RdDActor extends Actor { } } - async processDropItem(params, onEnleverConteneur, onAjouterDansConteneur) { + async processDropItem(params) { const targetActorId = this.id; const sourceActorId = params.sourceActorId; const itemId = params.itemId; @@ -1899,6 +1899,7 @@ export class RdDActor extends Actor { case 'nourritureboisson': return await this.actionNourritureboisson(item, onActionItem); case 'potion': return await this.consommerPotion(item, onActionItem); case 'livre': return await this.actionLire(item); + case 'conteneur': return await item.sheet.render(true); } } diff --git a/module/item-sheet.js b/module/item-sheet.js index 2a312b3d..2863e30c 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -23,10 +23,10 @@ export class RdDItemSheet extends ItemSheet { template: "systems/foundryvtt-reve-de-dragon/templates/item-sheet.html", width: 550, height: 550 - //tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}] }); } + /* -------------------------------------------- */ _getHeaderButtons() { let buttons = super._getHeaderButtons(); @@ -130,6 +130,11 @@ export class RdDItemSheet extends ItemSheet { activateListeners(html) { super.activateListeners(html); + if (this.object.type == 'conteneur') { + this.form.ondragstart = (event) => this._onDragStart(event); + this.form.ondrop = (event) => this._onDrop(event); + } + let itemSheetDialog = this; HtmlUtility._showControlWhen($(".item-cout"), ReglesOptionelles.isUsing('afficher-prix-joueurs') || game.user.isGM || !this.object.isOwned); @@ -221,7 +226,6 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ get template() { - //console.log(this); let type = this.object.data.type; return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`; } @@ -230,12 +234,56 @@ export class RdDItemSheet extends ItemSheet { /** @override */ _updateObject(event, formData) { // Deprecated en v0.8 à clarifier - //console.log("UPDATE !", formData); // Données de bonus de cases ? formData = RdDItemSort.buildBonusCaseStringFromFormData(formData); return this.object.update(formData); } + async _onDragStart(event) { + console.log("_onDragStart", event); + if ( event.target.classList.contains("entity-link") ) return; + + const itemId = event.srcElement?.attributes["data-item-id"].value; + const item = this.actor.items.get(itemId); + // Create drag data + const dragData = { + actorId: this.actor.id, + type: "Item", + data: item.data + }; + + event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); + } + + async _onDrop(event) { + // Try to extract the data + let data; + try { + data = JSON.parse(event.dataTransfer.getData('text/plain')); + } catch (err) { + return false; + } + + const allowed = Hooks.call("dropActorSheetData", this.actor, this, data); + if ( allowed === false ) return; + + // Handle different data types + switch ( data.type ) { + case "Item": + return this._onDropItem(event, data); + } + return super._onDrop(event); + } + + /* -------------------------------------------- */ + async _onDropItem(event, dragData) { + if (this.actor) { + const dropParams = RdDSheetUtility.prepareItemDropParameters(this.object.id, this.actor.id, dragData, this.objetVersConteneur); + await this.actor.processDropItem(dropParams); + await this.render(true); + } + } + } diff --git a/module/item.js b/module/item.js index 7e4d27eb..bf68714d 100644 --- a/module/item.js +++ b/module/item.js @@ -104,14 +104,15 @@ export class RdDItem extends Item { prepareDerivedData() { super.prepareDerivedData(); - if (this.isEquipement(this)) { + if (this.isEquipement()) { this._calculsEquipement(); + + if (this.isPotion()) { + this.prepareDataPotion() + } + const itemData = Misc.data(this); + itemData.data.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); } - if (this.isPotion()) { - this.prepareDataPotion() - } - const itemData = Misc.data(this); - itemData.data.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); } prepareDataPotion() { @@ -139,7 +140,7 @@ export class RdDItem extends Item { getActionPrincipale(options = { warnIfNot: true }) { const itemData = Misc.data(this); - if ((itemData.data.quantite ?? 0) <= 0) { + if (itemData.type != 'conteneur' && (itemData.data.quantite ?? 0) <= 0) { if (options.warnIfNot) { ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`); } @@ -149,9 +150,10 @@ export class RdDItem extends Item { case 'nourritureboisson': return itemData.data.boisson ? 'Boire' : 'Manger'; case 'potion': return 'Boire'; case 'livre': return 'Lire'; + case 'conteneur': return 'Ouvrir'; } if (options.warnIfNot) { - ui.notifications.warn(`Impossible d'utilise un ${itemData.name}, aucune action associée définie.`); + ui.notifications.warn(`Impossible d'utiliser un ${itemData.name}, aucune action associée définie.`); } return undefined; @@ -200,7 +202,7 @@ export class RdDItem extends Item { .filter(([key, value]) => value != otherTplData[key]); if (differences.length > 0) { let message = `Impossible de regrouper les ${itemData.type} ${itemData.name}: `; - for (const [key, value] of differences){ + for (const [key, value] of differences) { message += `
${key}: ${value} vs ${otherTplData[key]}`; } ui.notifications.info(message) @@ -236,7 +238,7 @@ export class RdDItem extends Item { } /* -------------------------------------------- */ - async postItem( modeOverride ) { + async postItem(modeOverride) { console.log(this); let chatData = duplicate(Misc.data(this)); const properties = this.getProprietes(); @@ -568,11 +570,11 @@ export class RdDItem extends Item { `Dommages: ${tplData.dommages}` ] if (tplData.remedesconnus) { - properties.push(`Remedes: ${tplData.remedes}` ) + properties.push(`Remedes: ${tplData.remedes}`) } } else { properties = [ - `Inconnue` ] + `Inconnue`] } return properties; } diff --git a/module/rdd-sheet-utility.js b/module/rdd-sheet-utility.js index 5f38157b..d1d9548b 100644 --- a/module/rdd-sheet-utility.js +++ b/module/rdd-sheet-utility.js @@ -20,18 +20,16 @@ export class RdDSheetUtility { return $(event.currentTarget)?.parents(".item"); } - static extractItemDropParameters(event, dragData, actor, objetVersConteneur) { - console.log("extractItemDropParameters", actor.id, dragData); + static prepareItemDropParameters(destItemId, actorId, dragData, objetVersConteneur) { const itemId = dragData.id || dragData.data._id; - const destItemId = $(event.target).parents(".item").attr("data-item-id"); return { - sourceActorId: dragData.actorId, - targetActorId: actor.id, - itemId: itemId, destId: destItemId, + targetActorId: actorId, + itemId: itemId, + sourceActorId: dragData.actorId, srcId: objetVersConteneur[itemId], onEnleverConteneur: () => { delete objetVersConteneur[itemId]; }, - onAjouterDansConteneur: (conteneurId) => { objetVersConteneur[itemId] = conteneurId; } + onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; } } } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index d13454fc..53dbf002 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -225,7 +225,7 @@ export class RdDUtility { Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str)); Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args)); Handlebars.registerHelper('buildConteneur', (objet) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet)); }); - Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); }); + Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); }); Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); Handlebars.registerHelper('typeTmr-name', coord => TMRUtility.typeTmrName(coord)); @@ -272,7 +272,7 @@ export class RdDUtility { } /* -------------------------------------------- */ - static async selectObjetType( actorSheet) { + static async selectObjetType(actorSheet) { let typeObjets = RdDItem.getTypeObjetsEquipement(); let options = `Selectionnez le type d'équipement`; for (let typeName of typeObjets) { @@ -313,7 +313,7 @@ export class RdDUtility { } }); d.render(true); - } + } /* -------------------------------------------- */ static buildListOptions(min, max) { @@ -378,7 +378,7 @@ export class RdDUtility { formData.maladies = this.checkNull(formData.itemsByType['maladie']); formData.poisons = this.checkNull(formData.itemsByType['poison']); formData.possessions = this.checkNull(formData.itemsByType['possession']); - formData.maladiesPoisons = formData.maladies.concat( formData.poisons); + formData.maladiesPoisons = formData.maladies.concat(formData.poisons); formData.competences = (formData.itemsByType.competence ?? []).concat(formData.itemsByType.competencecreature ?? []); } @@ -440,11 +440,11 @@ export class RdDUtility { .map(id => Misc.data(objets.find(it => (id == it._id)))) .filter(it => it); let enc = Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); - for (let itemData of contenuDatas){ + for (let itemData of contenuDatas) { if (itemData.type == 'conteneur') { - enc += RdDUtility.calculEncContenu(itemData, objets); + enc += RdDUtility.calculEncContenu(itemData, objets); } - else{ + else { enc += Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); } } @@ -692,8 +692,8 @@ export class RdDUtility { // gestion bouton tchat Acheter html.on("click", '.defense-possession', event => { - let actorId = event.currentTarget.attributes['data-defenderId'].value; - let possessionId = event.currentTarget.attributes['data-possessionId'].value; + let actorId = event.currentTarget.attributes['data-defenderId'].value; + let possessionId = event.currentTarget.attributes['data-possessionId'].value; RdDPossession.onDefensePossession(actorId, possessionId); }); @@ -850,7 +850,7 @@ export class RdDUtility { let itemId = li.data("item-id"); let objet = actorSheet.actor.getObjet(itemId); - if ( objet.type == 'monnaie' && Monnaie.isSystemMonnaie(objet) ) { + if (objet.type == 'monnaie' && Monnaie.isSystemMonnaie(objet)) { ui.notifications.warn("Suppression des monnaies de base impossible"); return; } @@ -896,7 +896,7 @@ export class RdDUtility { /* -------------------------------------------- */ static afficherHeuresChanceMalchance(heureNaissance) { - if ( game.user.isGM) { + if (game.user.isGM) { let heure = game.system.rdd.calendrier.findHeure(heureNaissance); if (heureNaissance && heure) { let ajustement = game.system.rdd.calendrier.getAjustementAstrologique(heureNaissance); @@ -907,7 +907,7 @@ export class RdDUtility { }); } else if (heureNaissance) { - ui.notifications.warn(heureNaissance+" ne correspond pas à une heure de naissance"); + ui.notifications.warn(heureNaissance + " ne correspond pas à une heure de naissance"); } else { ui.notifications.warn("Pas d'heure de naissance selectionnée"); diff --git a/templates/actor-sheet-inventaire-conteneur.html b/templates/actor-sheet-inventaire-conteneur.html index bc58f94c..b206db08 100644 --- a/templates/actor-sheet-inventaire-conteneur.html +++ b/templates/actor-sheet-inventaire-conteneur.html @@ -1,4 +1,4 @@ -
  • +
  • {{#if (eq item.type 'conteneur')}} diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 2fc58ae1..142268df 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -648,31 +648,31 @@
    Encombrement total/max : {{numberFormat calc.encTotal decimals=2}} / {{data.attributs.encombrement.value}} {{calc.surEncombrementMessage}} - Estimation de l'équipement : {{numberFormat calc.prixTotalEquipement decimals=2}} Sols -
    +
    Créer un objet {{#if options.isGM}} - Vider tout les conteneurs {{/if}} -
    -