foundryvtt-reve-de-dragon/module/item-sheet.js

96 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-12-04 20:52:04 +01:00
import { RdDItemSort } from "./item-sort.js";
import { RdDUtility } from "./rdd-utility.js";
2020-12-04 20:52:04 +01:00
2020-05-21 21:48:20 +02:00
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
*/
2020-05-22 00:48:43 +02:00
export class RdDItemSheet extends ItemSheet {
2020-05-21 21:48:20 +02:00
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
2020-05-22 19:28:01 +02:00
classes: ["foundryvtt-reve-de-dragon", "sheet", "item"],
template: "systems/foundryvtt-reve-de-dragon/templates/item-sheet.html",
2020-05-21 21:48:20 +02:00
width: 520,
2020-05-22 19:28:01 +02:00
height: 480
//tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
2020-05-21 21:48:20 +02:00
});
}
/* -------------------------------------------- */
/** @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;
}
2020-12-04 20:52:04 +01:00
/* -------------------------------------------- */
async getData() {
2020-12-04 20:52:04 +01:00
let data = super.getData();
if ( data.item.type == 'tache' || data.item.type == 'livre') {
data.caracList = duplicate(game.system.model.Actor.personnage.carac);
data.competenceList = await RdDUtility.getCompetenceList( 'foundryvtt-reve-de-dragon.competences' );
}
if ( this.actor ) {
data.isOwned = true;
data.actorId = this.actor._id;
}
2020-12-04 20:52:04 +01:00
data.bonusCaseList = RdDItemSort.getBonusCaseList(data, true);
data.isGM = game.user.isGM; // Pour vérouiller certaines éditions
2020-12-04 20:52:04 +01:00
return data;
}
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
2020-05-22 19:28:01 +02:00
// Select competence categorie
html.find("#categorie").on("click", this._onClickSelectCategorie.bind(this) );
html.find('#creer-tache-livre').click((event) => {
let actorId = event.currentTarget.attributes['data-actor-id'].value;
let actor = game.actors.get( actorId );
actor.creerTacheDepuisLivre( this.item );
});
2020-05-21 21:48:20 +02:00
}
2020-05-22 19:28:01 +02:00
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
2020-05-22 19:28:01 +02:00
async _onClickSelectCategorie(event) {
2020-05-21 21:48:20 +02:00
event.preventDefault();
2020-05-22 19:28:01 +02:00
const category = event.currentTarget.value;
let level = CONFIG.RDD.level_category[category];
this.object.data.data.base = level;
$("#base").val( level );
}
2020-05-21 21:48:20 +02:00
2020-05-22 19:28:01 +02:00
/* -------------------------------------------- */
get template()
{
let type = this.item.type;
return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`;
2020-05-21 21:48:20 +02:00
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
2020-12-04 20:52:04 +01:00
// Données de bonus de cases ?
formData = RdDItemSort.buildBonusCaseStringFromFormData( formData );
2020-05-21 21:48:20 +02:00
return this.object.update(formData);
}
}