#122 Gestion d'acturs liés à une fiche de perso

This commit is contained in:
sladecraven 2021-01-11 16:29:41 +01:00
parent e54de9f080
commit d02b5ac88c
8 changed files with 234 additions and 64 deletions

View File

@ -123,6 +123,9 @@ export class RdDActorSheet extends ActorSheet {
data.data.caseSpeciales = data.itemsByType['casetmr']; data.data.caseSpeciales = data.itemsByType['casetmr'];
RdDUtility.buildArbreDeConteneur(this, data); RdDUtility.buildArbreDeConteneur(this, data);
data.data.surEncombrementMessage = (data.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : ""; data.data.surEncombrementMessage = (data.data.compteurs.surenc.value < 0) ? "Sur-Encombrement!" : "";
data.data.vehiculesList = this.actor.buildVehiculesList();
data.data.monturesList = this.actor.buildMonturesList();
data.data.suivantsList = this.actor.buildSuivantsList();
return data; return data;
} }
@ -135,47 +138,6 @@ export class RdDActorSheet extends ActorSheet {
} }
} }
/* -------------------------------------------- */
async confirmerSuppression(li) {
let itemId = li.data("item-id");
let objet = this.actor.items.find( item => item._id == itemId );
let msgTxt = "<p>Etes vous certain de vouloir supprimer cet objet ?";
let buttons = { delete: {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer l'objet",
callback: () => {
console.log("Delete : ", itemId);
this.actor.deleteOwnedItem( itemId );
li.slideUp(200, () => this.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
}
}
if ( objet.data.type == 'conteneur' && objet.data.data.contenu.length > 0) {
msgTxt += "<br>Cet objet est aussi un conteneur avec du contenu : choisissez l'option de suppression";
buttons['deleteall'] = {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer le conteneur et tout son contenu",
callback: () => {
console.log("Delete : ", itemId);
this.actor.deleteAllConteneur( itemId );
li.slideUp(200, () => this.render(false));
}
}
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirmer la suppression",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async createEmptyTache() { async createEmptyTache() {
await this.actor.createOwnedItem({ name: 'Nouvelle tache', type: 'tache' }, { renderSheet: true }); await this.actor.createOwnedItem({ name: 'Nouvelle tache', type: 'tache' }, { renderSheet: true });
@ -229,9 +191,13 @@ export class RdDActorSheet extends ActorSheet {
// Delete Inventory Item // 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");
this.confirmerSuppression(li); RdDUtility.confirmerSuppression(this, li);
}); });
html.find('.subacteur-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
RdDUtility.confirmerSuppressionSubacteur(this, li);
});
html.find('#encaisser-direct').click(ev => { html.find('#encaisser-direct').click(ev => {
this.actor.encaisser(); this.actor.encaisser();
}); });
@ -314,7 +280,15 @@ export class RdDActorSheet extends ActorSheet {
let meditationId = li.data('item-id'); let meditationId = li.data('item-id');
this.actor.rollMeditation(meditationId); this.actor.rollMeditation(meditationId);
}); });
html.find('.subacteur-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
let actorId = li.data('actor-id');
let actor = game.actors.get( actorId) ;
if ( actor ) {
actor.sheet.render(true);
}
});
// Points de reve actuel // Points de reve actuel
html.find('.ptreve-actuel a').click((event) => { html.find('.ptreve-actuel a').click((event) => {
this.actor.rollCarac('reve-actuel'); this.actor.rollCarac('reve-actuel');

View File

@ -74,12 +74,10 @@ export class RdDActorVehiculeSheet extends ActorSheet {
const item = this.actor.getOwnedItem(li.data("itemId")); const item = this.actor.getOwnedItem(li.data("itemId"));
item.sheet.render(true); item.sheet.render(true);
}); });
// Delete Inventory Item // 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");
this.actor.deleteOwnedItem(li.data("itemId")); RdDUtility.confirmerSuppression(this, li);
li.slideUp(200, () => this.render(false));
}); });
// Display info about queue // Display info about queue

View File

@ -2506,6 +2506,77 @@ export class RdDActor extends Actor {
_alchimieResult(rollData) { _alchimieResult(rollData) {
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-alchimie.html'); RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-alchimie.html');
} }
/* -------------------------------------------- */
buildVehiculesList() {
let myArray = [];
for (let vehiculeLink of this.data.data.subacteurs.vehicules) {
let vehicule = game.actors.get( vehiculeLink.id );
myArray.push( { id: vehiculeLink.id, name: vehicule.data.name, categorie: vehicule.data.data.categorie,
structure: vehicule.data.data.structure, img: vehicule.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
buildSuivantsList() {
let myArray = [];
for (let suivantLink of this.data.data.subacteurs.suivants) {
let suivant = game.actors.get( suivantLink.id );
myArray.push( { id: suivantLink.id, name: suivant.data.name, img: suivant.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
buildMonturesList() {
let myArray = [];
for (let montureLink of this.data.data.subacteurs.montures) {
let monture = game.actors.get( montureLink.id );
myArray.push( { id: montureLink.id, name: monture.data.name, img: monture.data.img } );
}
return myArray;
}
/* -------------------------------------------- */
async pushSubacteur( actor, dataArray, dataPath, dataName ) {
let alreadyPresent = dataArray.find( attached => attached.id == actor.data._id);
if ( !alreadyPresent ) {
let newArray = duplicate(dataArray);
newArray.push( { id: actor.data._id });
await this.update( { [dataPath]: newArray });
} else {
ui.notifications.warn(dataName+" est déja attaché à ce Personnage.");
}
}
/* -------------------------------------------- */
addSubacteur( actorId ) {
let actor = game.actors.get( actorId );
//console.log("Ajout acteur : ", actor, this);
if (actor && actor.owner ) {
if (actor.data.type == 'vehicule') {
this.pushSubacteur( actor, this.data.data.subacteurs.vehicules, 'data.subacteurs.vehicules', 'Ce Véhicule' );
} else if (actor.data.type == 'creature') {
this.pushSubacteur( actor, this.data.data.subacteurs.montures, 'data.subacteurs.montures', 'Cette Monture' );
} else if (actor.data.type == 'personnage') {
this.pushSubacteur( actor, this.data.data.subacteurs.suivants, 'data.subacteurs.suivants', 'Ce Suivant' );
}
} else {
ui.notifications.warn("Vous n'avez pas les droits sur l'acteur que vous attachez.")
}
}
/* -------------------------------------------- */
async removeSubacteur( actorId ) {
let newVehicules = this.data.data.subacteurs.vehicules.filter(function(obj, index, arr){ return obj.id != actorId } );
let newSuivants = this.data.data.subacteurs.suivants.filter(function(obj, index, arr){ return obj.id != actorId } );
let newMontures = this.data.data.subacteurs.montures.filter(function(obj, index, arr){ return obj.id != actorId } );
await this.update( { 'data.subacteurs.vehicules': newVehicules });
await this.update( { 'data.subacteurs.suivants': newSuivants });
await this.update( { 'data.subacteurs.montures': newMontures });
}
} }

View File

@ -269,20 +269,24 @@ export class RdDUtility {
console.log(dragData, actorSheet.actor._id); console.log(dragData, actorSheet.actor._id);
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
let objetId = dragData.id || dragData.data._id; let objetId = dragData.id || dragData.data._id;
if ( dropID ) { // Dropped over an item !!! if ( dragData.type == 'Item') {
if (actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) { if ( dropID ) { // Dropped over an item !!!
if (actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID)) { if (actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) {
await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]); if (actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID)) {
await actorSheet.actor.ajouterAConteneur(objetId, dropID); await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]);
await actorSheet.actor.ajouterAConteneur(objetId, dropID);
}
} }
} }
if (dragData.actorId && dragData.actorId != actorSheet.actor._id ) { // Un acteur est à l'origine de l'item -> deplacement
console.log("Moving objects");
actorSheet.actor.moveItemsBetweenActors( objetId, dragData.actorId);
return false;
}
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
} else if ( dragData.type == "Actor" ) {
actorSheet.actor.addSubacteur( objetId );
} }
if (dragData.actorId && dragData.actorId != actorSheet.actor._id ) { // Un acteur est à l'origine de l'item -> deplacement
console.log("Moving objects");
actorSheet.actor.moveItemsBetweenActors( objetId, dragData.actorId);
return false;
}
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
return true; return true;
} }
@ -836,6 +840,77 @@ export class RdDUtility {
chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper); chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper);
} }
return chatData; return chatData;
} }
/* -------------------------------------------- */
static confirmerSuppressionSubacteur(actorSheet, li ) {
let actorId = li.data("actor-id");
let actor = game.actors.get( actorId );
let msgTxt = "<p>Etes vous certain de vouloir supprimer le lien vers ce véhicule/monture/suivant : " + actor.data.name +" ?</p>";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer le lien",
callback: () => {
console.log("Delete : ", actorId);
actorSheet.actor.removeSubacteur( actorId );
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
}
}
let d = new Dialog({
title: "Confirmer la suppression du lien",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
/* -------------------------------------------- */
static async confirmerSuppression(actorSheet, li) {
let itemId = li.data("item-id");
let objet = actorSheet.actor.items.find( item => item._id == itemId );
let msgTxt = "<p>Etes vous certain de vouloir supprimer cet objet ?";
let buttons = { delete: {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer l'objet",
callback: () => {
console.log("Delete : ", itemId);
actorSheet.actor.deleteOwnedItem( itemId );
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
}
}
if ( objet.data.type == 'conteneur' && objet.data.data.contenu.length > 0) {
msgTxt += "<br>Cet objet est aussi un conteneur avec du contenu : choisissez l'option de suppression";
buttons['deleteall'] = {
icon: '<i class="fas fa-check"></i>',
label: "Supprimer le conteneur et tout son contenu",
callback: () => {
console.log("Delete : ", itemId);
actorSheet.actor.deleteAllConteneur( itemId );
li.slideUp(200, () => actorSheet.render(false));
}
}
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirmer la suppression",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
} }

View File

@ -647,6 +647,7 @@ ul, li {
.competence-label, .competence-label,
.astrologie-label, .astrologie-label,
.tache-label, .tache-label,
.subacteur-label,
.description-label { .description-label {
flex-grow: 2; flex-grow: 2;
} }

View File

@ -2,10 +2,10 @@
"name": "foundryvtt-reve-de-dragon", "name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon", "title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT", "description": "Rêve de Dragon RPG for FoundryVTT",
"version": "1.2.12", "version": "1.2.15",
"minimumCoreVersion": "0.7.5", "minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.8", "compatibleCoreVersion": "0.7.8",
"templateVersion": 81, "templateVersion": 83,
"author": "LeRatierBretonnien", "author": "LeRatierBretonnien",
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"styles": ["styles/simple.css"], "styles": ["styles/simple.css"],

View File

@ -6,6 +6,13 @@
"description": "Description ...", "description": "Description ...",
"notesmj": "Notes du MJ" "notesmj": "Notes du MJ"
}, },
"subacteurs": {
"subacteurs": {
"suivants": [],
"montures": [],
"vehicules": []
}
},
"background": { "background": {
"biographie": "Histoire personnelle...", "biographie": "Histoire personnelle...",
"notes": "Notes", "notes": "Notes",
@ -541,7 +548,7 @@
} }
}, },
"personnage": { "personnage": {
"templates": [ "background", "common"] "templates": [ "background", "common", "subacteurs" ]
}, },
"creature": { "creature": {
"templates": [ "creature", "description" ] "templates": [ "creature", "description" ]

View File

@ -660,7 +660,7 @@
{{!-- Equipment Tab --}} {{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items"> <div class="tab items" data-group="primary" data-tab="items">
<span class="item-name">Argent et Monnaies</b></span> - <span class="item-name"><h4>Argent et Monnaies</h4></span>
<ul class="item-list alterne-list"> <ul class="item-list alterne-list">
{{#each data.monnaie as |piece id|}} {{#each data.monnaie as |piece id|}}
<li class="item flexrow list-item" data-item-id="{{piece._id}}"> <li class="item flexrow list-item" data-item-id="{{piece._id}}">
@ -675,6 +675,8 @@
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
<span class="item-name"><h4>Equipement porté</h4></span>
<span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> - <span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> -
<span class="item-name"><a id="creer-un-objet">Créer un objet</a></span> <span class="item-name"><a id="creer-un-objet">Créer un objet</a></span>
{{#if data.isGM}} {{#if data.isGM}}
@ -704,11 +706,53 @@
</li> </li>
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/each}} {{/each}}
{{#each data.conteneurs as |conteneur id|}} {{#each data.conteneurs as |conteneur id|}}
{{buildConteneur this}} {{buildConteneur this}}
{{/each}} {{/each}}
</ul> </ul>
<span class="item-name"><h4>Montures</h4></span>
<ul class="item-list alterne-list">
{{#each data.monturesList as |monture id|}}
<li class="item flexrow list-item" data-actor-id="{{monture.id}}">
<img class="sheet-competence-img" src="{{monture.img}}" title="{{monture.name}}"/>
<span class="competence-title subacteur-label"><a>{{monture.name}}</a></span>
<div class="item-controls">
<a class="item-control subacteur-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
<span class="item-name"><h4>Véhicules</h4></span>
<ul class="item-list alterne-list">
{{#each data.vehiculesList as |vehicule id|}}
<li class="item flexrow list-item" data-actor-id="{{vehicule.id}}">
<img class="sheet-competence-img" src="{{vehicule.img}}" title="{{vehicule.name}}"/>
<span class="competence-title subacteur-label"><a>{{vehicule.name}}</a></span>
<span class="competence-title">{{vehicule.categorie}}</span>
<span class="competence-title">{{vehicule.structure}}</span>
<div class="item-controls">
<a class="item-control subacteur-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
<span class="item-name"><h4>Suivants</h4></span>
<ul class="item-list alterne-list">
{{#each data.suivantsList as |suivant id|}}
<li class="item flexrow list-item" data-actor-id="{{suivant.id}}">
<img class="sheet-competence-img" src="{{suivant.img}}" title="{{suivant.name}}"/>
<span class="competence-title subacteur-label"><a>{{suivant.name}}</a></span>
<div class="item-controls">
<a class="item-control subacteur-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
</div> </div>
{{!-- Biography Tab --}} {{!-- Biography Tab --}}