/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { RdDUtility } from "./rdd-utility.js";
export class RdDActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html",
width: 600,
height: 600,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
});
}
/* -------------------------------------------- */
_checkNull(items) {
if (items && items.length) {
return items;
}
return [];
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
data.itemsByType = {};
for (const item of data.items) {
let list = data.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
}
list.push(item);
}
// Competence per category
data.competenceByCategory = {};
if (data.itemsByType.competence) {
for (const item of data.itemsByType.competence) {
//console.log("Push...", item, item.data.categorie);
let list = data.competenceByCategory[item.data.categorie];
if (!list) {
list = [];
data.competenceByCategory[item.data.categorie] = list;
}
list.push(item);
}
}
// Force empty arme, at least for Esquive
if (data.itemsByType.arme == undefined ) data.itemsByType.arme = [];
for (const arme of data.itemsByType.arme) {
arme.data.niveau = 0; // Per default, TODO to be fixed
for ( const melee of data.competenceByCategory.melee ) {
if (melee.name == arme.data.competence )
arme.data.niveau = melee.data.niveau
}
}
// To avoid armour and so on...
data.data.armes_seules = duplicate( this._checkNull(data.itemsByType['arme']));
if (data.competenceByCategory && data.competenceByCategory.melee) {
//Specific case for Esquive and Corps à Corps
for ( const melee of data.competenceByCategory.melee ) {
if (melee.name == "Esquive")
data.itemsByType.arme.push( { name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, competence: "Esquive", dommages: 0} } );
if (melee.name == "Corps à corps")
data.itemsByType.arme.push( { name: "Corps à corps", data: { niveau: melee.data.niveau, description: "", force: 6, competence: "Corps à corps", dommages: data.data.attributs.plusdom.value } } );
}
}
data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.nbLegeres = RdDUtility.computeNbBlessures(data.data.blessures, "legeres" );
data.data.nbGraves = RdDUtility.computeNbBlessures(data.data.blessures, "graves" );
data.data.nbCritiques = RdDUtility.computeNbBlessures(data.data.blessures, "critiques" );
// low is normal, this the base used to compute the grid.
data.data.fatigueHTML = "
" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "
";
data.data.materiel = this._checkNull(data.itemsByType['objet']);
data.data.armes = this._checkNull(data.itemsByType['arme']);
data.data.armures = this._checkNull(data.itemsByType['armure']);
data.data.livres = this._checkNull(data.itemsByType['livre']);
data.data.potions = this._checkNull(data.itemsByType['potions']);
data.data.herbes = this._checkNull(data.itemsByType['herbes']);
data.data.sorts = this._checkNull(data.itemsByType['sort']);
data.data.queues = this._checkNull(data.itemsByType['queue']);
data.data.souffles = this._checkNull(data.itemsByType['souffle']);
data.data.ombres = this._checkNull(data.itemsByType['ombre']);
data.data.tetes = this._checkNull(data.itemsByType['tete']);
data.data.competenceByCategory = data.competenceByCategory;
//data.data.armes = data.itemsByType.arme;
//console.log(">>>>> data update");
return data;
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId"));
li.slideUp(200, () => this.render(false));
});
// Equip Inventory Item
html.find('.blessure-legere-control').click(ev => {
let index = event.currentTarget.attributes['data-blessure-index'].value;
let active = event.currentTarget.attributes['data-blessure-active'].value;
this.actor.manageBlessureLegere(index, active);
this.render(true);
});
// Equip Inventory Item
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equiperObjet(li.data("itemId"));
this.render(true);
});
// Roll Carac
html.find('.carac-label a').click((event) => {
let caracName = event.currentTarget.attributes.name.value;
this.actor.rollCarac( caracName.toLowerCase() );
});
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName);
});
// Roll Weapon
html.find('.arme-label a').click((event) => {
let armeName = event.currentTarget.text;
this.actor.rollArme( armeName);
});
// Display TMR, normal
html.find('.monte-tmr a').click((event) => {
this.actor.displayTMR( false );
});
// Display TMR, fast
html.find('.monte-tmr-rapide a').click((event) => {
this.actor.displayTMR( true );
});
// Display info about queue
html.find('.queuesouffle-label a').click((event) => {
let myID = event.currentTarget.attributes['data-id'].value;
const item = this.actor.getOwnedItem(myID);
item.sheet.render(true);
});
// Display info about queue
html.find('.sort-label a').click((event) => {
let myID = event.currentTarget.attributes['data-id'].value;
const item = this.actor.getOwnedItem(myID);
item.sheet.render(true);
});
// On carac change
html.find('.carac-value').change((event) => {
let caracName = event.currentTarget.name.replace(".value", "").replace("data.carac.", "");
//console.log("Value changed :", event, caracName);
this.actor.updateCarac( caracName, parseInt(event.target.value) );
} );
// On competence change
html.find('.competence-value').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
//console.log("Competence changed :", compName);
this.actor.updateCompetence( compName, parseInt(event.target.value) );
} );
// On pts de reve change
html.find('.pointsreve-value').change((event) => {
let reveValue = event.currentTarget.value;
let reve = duplicate( this.actor.data.data.reve.reve );
reve.value = reveValue;
this.actor.update("data.reve.reve", reve );
} );
// On competence change
html.find('.competence-xp').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCompetenceXP( compName, parseInt(event.target.value) );
} );
html.find('#vie-plus').click((event) => {
this.actor.santeIncDec("vie", 1);
this.render(true);
});
html.find('#vie-moins').click((event) => {
this.actor.santeIncDec("vie", -1);
this.render(true);
});
html.find('#endurance-plus').click((event) => {
this.actor.santeIncDec("endurance", 1);
this.render(true);
});
html.find('#endurance-moins').click((event) => {
this.actor.santeIncDec("endurance", -1);
this.render(true);
});
html.find('#fatigue-plus').click((event) => {
this.actor.santeIncDec("fatigue", 1);
this.render(true);
});
html.find('#fatigue-moins').click((event) => {
this.actor.santeIncDec("fatigue", -1);
this.render(true);
});
}
/* -------------------------------------------- */
/** @override */
setPosition(options={}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}