Support de plusieurs actors

This commit is contained in:
Vincent Vandemeulebrouck
2022-12-28 23:36:48 +01:00
parent 6adeb790a0
commit 2062ff0777
11 changed files with 518 additions and 334 deletions

View File

@ -12,13 +12,15 @@ import { RdDSheetUtility } from "./rdd-sheet-utility.js";
import { STATUSES } from "./settings/status-effects.js";
import { Monnaie } from "./item-monnaie.js";
import { MAINS_DIRECTRICES } from "./actor.js";
import { RdDBaseActorSheet } from "./actor/base-actor-sheet.js";
import { RdDItem } from "./item.js";
/* -------------------------------------------- */
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class RdDActorSheet extends ActorSheet {
export class RdDActorSheet extends RdDBaseActorSheet {
/** @override */
static get defaultOptions() {
@ -36,42 +38,28 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */
async getData() {
let formData = await super.getData();
mergeObject(formData,
{
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
effects: this.actor.effects.map(e => foundry.utils.deepClone(e)),
limited: this.actor.limited,
owner: this.actor.isOwner,
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
biographie: await TextEditor.enrichHTML(this.object.system.biographie, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
notesmj: await TextEditor.enrichHTML(this.object.system.notesmj, { async: true }),
});
mergeObject(formData.calc, {
surenc: this.actor.computeMalusSurEncombrement(),
surprise: RdDBonus.find(this.actor.getSurprise(false)).descr,
resumeBlessures: this.actor.computeResumeBlessure(this.actor.system.blessures),
caracTotal: RdDCarac.computeTotal(this.actor.system.carac, this.actor.system.beaute),
surEncombrementMessage: this.actor.getMessageSurEncombrement(),
})
this.timerRecherche = undefined;
this.actor.computeEtatGeneral();
let formData = {
title: this.title,
id: this.actor.id,
type: this.actor.type,
img: this.actor.img,
name: this.actor.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
system: foundry.utils.deepClone(this.actor.system),
effects: this.actor.effects.map(e => foundry.utils.deepClone(e)),
limited: this.actor.limited,
options: this.options,
owner: this.actor.isOwner,
description: await TextEditor.enrichHTML(this.object.system.description, { async: true }),
biographie: await TextEditor.enrichHTML(this.object.system.biographie, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
notesmj: await TextEditor.enrichHTML(this.object.system.notesmj, { async: true }),
calc: {
fortune: Monnaie.getFortuneSolsDeniers(this.actor),
encTotal: await this.actor.computeEncombrementTotalEtMalusArmure(),
surenc: this.actor.computeMalusSurEncombrement(),
prixTotalEquipement: this.actor.computePrixTotalEquipement(),
surprise: RdDBonus.find(this.actor.getSurprise(false)).descr,
resumeBlessures: this.actor.computeResumeBlessure(this.actor.system.blessures),
caracTotal: RdDCarac.computeTotal(this.actor.system.carac, this.actor.system.beaute),
surEncombrementMessage: this.actor.getMessageSurEncombrement(),
},
}
formData.options.isGM = game.user.isGM;
RdDUtility.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
formData.conteneurs = RdDUtility.conteneursRacine(formData.conteneurs);
if (formData.type == 'personnage') {
formData.options.mainsDirectrices = MAINS_DIRECTRICES;
@ -125,22 +113,14 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /** @override */
activateListeners(html) {
super.activateListeners(html);
this.html = html;
HtmlUtility._showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue"));
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
this.html.find('.item-split').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
RdDSheetUtility.splitItem(item, this.actor);
});
this.html.find('.item-edit').click(async event => RdDSheetUtility.getItem(event, this.actor)?.sheet.render(true))
this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor)));
this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente());
this.html.find('.item-montrer').click(async event => RdDSheetUtility.getItem(event, this.actor)?.postItem());
this.html.find('.item-action').click(async event => RdDSheetUtility.getItem(event, this.actor)?.actionPrincipale(this.actor));
this.html.find('.subacteur-delete').click(async event => {
const li = RdDSheetUtility.getEventElement(event);
const actorId = li.data("actor-id");
@ -174,14 +154,8 @@ export class RdDActorSheet extends ActorSheet {
this.html.find('.creer-tache').click(async event => {
this.createEmptyTache();
});
this.html.find('.creer-un-objet').click(async event => {
RdDUtility.selectObjetType(this);
});
this.html.find('.creer-une-oeuvre').click(async event => {
RdDUtility.selectTypeOeuvre(this);
});
this.html.find('.nettoyer-conteneurs').click(async event => {
this.actor.nettoyerConteneurs();
this.selectTypeOeuvreToCreate();
});
// Blessure control
@ -325,10 +299,6 @@ export class RdDActorSheet extends ActorSheet {
await this.actor.removeEffects();
}
});
this.html.find('.conteneur-name a').click(async event => {
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
this.render(true);
});
this.html.find('.carac-xp-augmenter').click(async event => {
let caracName = event.currentTarget.name.replace("augmenter.", "");
this.actor.updateCaracXPAuto(caracName);
@ -418,19 +388,12 @@ export class RdDActorSheet extends ActorSheet {
this.actor.setPointsDeSeuil(event.currentTarget.value);
});
this.html.find('#attribut-protection-edit').change(async event => {
this.actor.updateAttributeValue(event.currentTarget.attributes.name.value, parseInt(event.target.value));
});
// On stress change
this.html.find('.compteur-edit').change(async event => {
let fieldName = event.currentTarget.attributes.name.value;
this.actor.updateCompteurValue(fieldName, parseInt(event.target.value));
});
this.html.find('#ethylisme').change(async event => {
this.actor.setEthylisme(parseInt(event.target.value));
});
this.html.find('.stress-test').click(async event => {
this.actor.transformerStress();
});
@ -454,13 +417,6 @@ export class RdDActorSheet extends ActorSheet {
this.actor.jetEndurance();
});
this.html.find('.monnaie-plus').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), 1);
});
this.html.find('.monnaie-moins').click(async event => {
this.actor.monnaieIncDec(RdDSheetUtility.getItemId(event), -1);
});
this.html.find('.vie-plus').click(async event => {
this.actor.santeIncDec("vie", 1);
});
@ -499,25 +455,30 @@ export class RdDActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
async _onDropItem(event, dragData) {
const destItemId = this.html.find(event.target)?.closest('.item').attr('data-item-id')
const dropParams = RdDSheetUtility.prepareItemDropParameters(destItemId, this.actor, dragData, this.objetVersConteneur)
if (dropParams) {
const callSuper = await this.actor.processDropItem(dropParams)
if (callSuper) {
await super._onDropItem(event, dragData)
}
async selectTypeOeuvreToCreate() {
let typeObjets = RdDItem.getTypesOeuvres();
let content = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
for (let typeName of typeObjets) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
}
}
/* -------------------------------------------- */
async createItem(name, type) {
await this.actor.createEmbeddedDocuments('Item', [{ name: name, type: type }], { renderSheet: true });
content += '</select>';
let dialog = new Dialog({
title: "Créer une oeuvre",
content: content,
buttons: {
create: {
icon: '<i class="fas fa-check"></i>',
label: "Créer l'oeuvre",
callback: () => this.actor.createItem($(".item-type").val())
}
}
});
dialog.render(true);
}
/* -------------------------------------------- */
async createEmptyTache() {
await this.createItem('Nouvelle tache', 'tache');
await this.actor.createItem('tache', 'Nouvelle tache');
}
_optionRecherche(target) {