2020-12-04 20:52:04 +01:00
|
|
|
import { RdDItemSort } from "./item-sort.js";
|
2020-12-15 21:28:55 +01:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2021-01-01 21:11:56 +01:00
|
|
|
import { RdDItem } from "./item-rdd.js";
|
2021-01-07 20:04:10 +01:00
|
|
|
import { RdDAlchimie } from "./rdd-alchimie.js";
|
2021-01-08 22:23:50 +01:00
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2021-03-22 20:10:37 +01:00
|
|
|
import { Misc } from "./misc.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",
|
2021-01-03 01:24:49 +01:00
|
|
|
width: 550,
|
|
|
|
height: 550
|
2020-05-22 19:28:01 +02:00
|
|
|
//tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
|
2020-05-21 21:48:20 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-01 21:11:56 +01:00
|
|
|
_getHeaderButtons() {
|
|
|
|
let buttons = super._getHeaderButtons();
|
|
|
|
// Add "Post to chat" button
|
|
|
|
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
|
|
|
|
buttons.unshift(
|
|
|
|
{
|
|
|
|
class: "post",
|
|
|
|
icon: "fas fa-comment",
|
2021-03-22 20:10:37 +01:00
|
|
|
onclick: ev => new RdDItem(Misc.data(this.item)).postItem()
|
2021-01-01 21:11:56 +01:00
|
|
|
})
|
|
|
|
return buttons
|
|
|
|
}
|
2020-05-21 21:48:20 +02:00
|
|
|
|
2021-01-01 21:11:56 +01:00
|
|
|
/* -------------------------------------------- */
|
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
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-15 21:28:55 +01:00
|
|
|
async getData() {
|
2021-03-16 22:56:57 +01:00
|
|
|
let formData = super.getData();
|
|
|
|
formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences();
|
|
|
|
if ( formData.item.type == 'tache' || formData.item.type == 'livre' || formData.item.type == 'meditation' || formData.item.type == 'oeuvre') {
|
|
|
|
formData.caracList = duplicate(game.system.model.Actor.personnage.carac);
|
|
|
|
formData.competences = await RdDUtility.loadCompendiumNames( 'foundryvtt-reve-de-dragon.competences' );
|
2021-01-08 22:23:50 +01:00
|
|
|
}
|
2021-03-16 22:56:57 +01:00
|
|
|
if (formData.item.type == 'arme') {
|
|
|
|
formData.competences = await RdDUtility.loadCompendium( 'foundryvtt-reve-de-dragon.competences', it => RdDItemCompetence.isCompetenceArme(it));
|
2020-12-15 21:28:55 +01:00
|
|
|
}
|
2021-03-16 22:56:57 +01:00
|
|
|
if ( formData.item.type == 'recettealchimique' ) {
|
|
|
|
RdDAlchimie.processManipulation(formData.item, this.actor && this.actor._id );
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
2020-12-15 21:28:55 +01:00
|
|
|
if ( this.actor ) {
|
2021-03-16 22:56:57 +01:00
|
|
|
formData.isOwned = true;
|
|
|
|
formData.actorId = this.actor._id;
|
2020-12-15 08:37:52 +01:00
|
|
|
}
|
2021-03-16 22:56:57 +01:00
|
|
|
formData.bonusCaseList = RdDItemSort.getBonusCaseList(formData, true);
|
|
|
|
formData.isGM = game.user.isGM; // Pour verrouiller certaines éditions
|
2020-12-04 20:52:04 +01:00
|
|
|
|
2021-03-16 22:56:57 +01:00
|
|
|
return formData;
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2020-12-15 21:28:55 +01:00
|
|
|
|
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) );
|
2020-12-15 21:28:55 +01:00
|
|
|
|
2021-02-06 23:51:04 +01:00
|
|
|
html.find('#sheet-competence-xp').change((event) => {
|
|
|
|
if ( this.object.data.type == 'competence') {
|
|
|
|
RdDUtility.checkThanatosXP( this.object.data.name );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2020-12-15 21:28:55 +01:00
|
|
|
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 );
|
|
|
|
});
|
2021-01-07 20:04:10 +01:00
|
|
|
|
|
|
|
html.find('.alchimie-tache a').click((event) => {
|
|
|
|
let actorId = event.currentTarget.attributes['data-actor-id'].value;
|
|
|
|
let recetteId = event.currentTarget.attributes['data-recette-id'].value;
|
|
|
|
let tacheName = event.currentTarget.attributes['data-alchimie-tache'].value;
|
|
|
|
let tacheData = event.currentTarget.attributes['data-alchimie-data'].value;
|
|
|
|
let actor = game.actors.get( actorId );
|
|
|
|
if ( actor ) {
|
|
|
|
actor.effectuerTacheAlchimie(recetteId, tacheName, tacheData);
|
|
|
|
} else {
|
2021-06-07 23:41:04 +02:00
|
|
|
ui.notifications.info("Impossible de trouver un acteur pour réaliser cette tâche alchimique.");
|
2021-01-07 20:04:10 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2021-03-17 01:21:37 +01:00
|
|
|
let level = RdDItemCompetence.getNiveauBase(event.currentTarget.value);
|
2020-05-22 19:28:01 +02:00
|
|
|
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 );
|
2021-01-14 15:29:47 +01:00
|
|
|
|
2020-05-21 21:48:20 +02:00
|
|
|
return this.object.update(formData);
|
|
|
|
}
|
|
|
|
}
|