Support drag-drop vers conteneur
This commit is contained in:
parent
009ec47709
commit
9de1e7dae5
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -104,15 +104,16 @@ 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 });
|
||||
}
|
||||
}
|
||||
|
||||
prepareDataPotion() {
|
||||
const tplData = Misc.templateData(this);
|
||||
@ -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 += `<br>${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 {
|
||||
`<b>Dommages</b>: ${tplData.dommages}`
|
||||
]
|
||||
if (tplData.remedesconnus) {
|
||||
properties.push(`<b>Remedes</b>: ${tplData.remedes}` )
|
||||
properties.push(`<b>Remedes</b>: ${tplData.remedes}`)
|
||||
}
|
||||
} else {
|
||||
properties = [
|
||||
`<b>Inconnue</b>` ]
|
||||
`<b>Inconnue</b>`]
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ export class RdDUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async selectObjetType( actorSheet) {
|
||||
static async selectObjetType(actorSheet) {
|
||||
let typeObjets = RdDItem.getTypeObjetsEquipement();
|
||||
let options = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
|
||||
for (let typeName of typeObjets) {
|
||||
@ -294,7 +294,7 @@ export class RdDUtility {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async selectTypeOeuvre( actorSheet) {
|
||||
static async selectTypeOeuvre(actorSheet) {
|
||||
let typeObjets = RdDItem.getTypesOeuvres();
|
||||
let options = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
|
||||
for (let typeName of typeObjets) {
|
||||
@ -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);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
enc += Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1);
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
|
@ -1,4 +1,4 @@
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}">
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
|
@ -27,7 +27,16 @@
|
||||
{{#if isOwned}}
|
||||
<div class="flexcol">
|
||||
<span><label>Contenu : </label></span>
|
||||
<ul class="item-list alterne-list">
|
||||
<li class="competence-header flexrow">
|
||||
<img class="sheet-competence-img" src="{{img}}" title="Equipement"/>
|
||||
<span class="competence-title flex-grow">Nom</span>
|
||||
<span class="competence-title">Q.</span>
|
||||
<span class="competence-title">Enc.</span>
|
||||
<span class="competence-title flex-grow">Equiper/Editer/Suppr.</span>
|
||||
</li>
|
||||
{{buildContenu this}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user