fvtt-pegasus-rpg/modules/pegasus-npc-sheet.js

140 lines
4.5 KiB
JavaScript
Raw Normal View History

2021-12-02 07:38:59 +01:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { PegasusUtility } from "./pegasus-utility.js";
import { PegasusItemSheet } from "./pegasus-item-sheet.js";
/* -------------------------------------------- */
export class PegasusNPCSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["pegasus-rpg", "sheet", "actor"],
template: "systems/fvtt-pegasus-rpg/templates/npc-sheet.html",
width: 640,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
editScore: false
});
}
/* -------------------------------------------- */
async getData() {
const objectData = PegasusUtility.data(this.object);
this.actor.prepareTraitsAttributes();
let actorData = duplicate(PegasusUtility.templateData(this.object));
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: actorData,
effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)),
limited: this.object.limited,
equipments: this.actor.getEquipments(),
defenseBase: this.actor.getDefenseBase(),
bodyArmourBase: this.actor.getBodyArmour(),
headArmourBase: this.actor.getHeadArmour(),
weapons: this.actor.getWeapons(),
traits: this.actor.getTraits(),
optionsBase: FraggedKingdomUtility.createDirectOptionList(0, 20),
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
}
this.formData = formData;
console.log("NPC : ", formData, this.object);
return formData;
}
/* -------------------------------------------- */
/** @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");
let itemId = li.data("item-id");
const item = this.actor.items.get( itemId );
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
FraggedKingdomUtility.confirmDelete(this, li);
});
html.find('.trait-link').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
html.find('.competence-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const competenceId = li.data("item-id");
this.actor.rollSkill(competenceId);
});
html.find('.weapon-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armeId = li.data("item-id");
const statId = li.data("stat-id");
this.actor.rollWeapon(armeId, statId);
});
html.find('.npc-fight-roll').click((event) => {
this.actor.rollNPCFight();
});
html.find('.npc-skill-roll').click((event) => {
this.actor.rollGenericSkill();
});
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.getOwnedItem(itemId);
item.sheet.render(true);
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equipItem( li.data("item-id") );
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);
}
}