This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
foundryvtt-beam-saber/module/blades-actor-sheet.js

118 lines
3.6 KiB
JavaScript
Raw Normal View History

import { BladesSheet } from "./blades-sheet.js";
import { BladesActiveEffect } from "./blades-active-effect.js";
2020-04-17 21:23:57 +00:00
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {BladesSheet}
2020-04-17 21:23:57 +00:00
*/
export class BladesActorSheet extends BladesSheet {
2020-04-17 21:23:57 +00:00
/** @override */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["beam-saber", "sheet", "actor", "pc"],
template: "systems/beam-saber/templates/actor-sheet.html",
2020-04-23 16:11:04 +00:00
width: 700,
height: 970,
tabs: [{navSelector: ".tabs", contentSelector: ".tab-content", initial: "abilities"}]
2020-04-17 21:23:57 +00:00
});
}
/* -------------------------------------------- */
/** @override */
2022-09-03 15:44:26 +00:00
async getData(options) {
const superData = super.getData( options );
const sheetData = superData.data;
sheetData.owner = superData.owner;
sheetData.editable = superData.editable;
sheetData.isGM = game.user.isGM;
2020-04-23 16:11:04 +00:00
2021-06-10 22:57:01 +00:00
// Prepare active effects
2022-09-03 15:44:26 +00:00
sheetData.effects = BladesActiveEffect.prepareActiveEffectCategories(this.actor.effects);
2021-06-10 22:57:01 +00:00
2020-04-23 16:11:04 +00:00
// Calculate Load
let loadout = 0;
2022-09-03 15:44:26 +00:00
sheetData.items.forEach(i => {loadout += (i.type === "item") ? parseInt(i.system.load) : 0});
2020-07-27 13:02:27 +00:00
//Sanity Check
if (loadout < 0) {
loadout = 0;
}
if (loadout > 10) {
loadout = 10;
}
2022-09-03 15:44:26 +00:00
sheetData.system.loadout = loadout;
// Encumbrance Levels
let load_level=["BITD.Light","BITD.Light","BITD.Light","BITD.Light","BITD.Normal","BITD.Normal","BITD.Heavy","BITD.Encumbered",
"BITD.Encumbered","BITD.Encumbered","BITD.OverMax"];
let mule_level=["BITD.Light","BITD.Light","BITD.Light","BITD.Light","BITD.Light","BITD.Light","BITD.Normal","BITD.Normal",
"BITD.Heavy","BITD.Encumbered","BITD.OverMax"];
let mule_present=0;
//look for Mule ability
// @todo - fix translation.
2022-09-03 15:44:26 +00:00
sheetData.items.forEach(i => {
if (i.type === "ability" && i.name === "(C) Mule") {
2020-07-27 13:02:27 +00:00
mule_present = 1;
}
});
//set encumbrance level
2020-07-27 13:02:27 +00:00
if (mule_present) {
2022-09-03 15:44:26 +00:00
sheetData.system.load_level=mule_level[loadout];
2020-07-27 13:02:27 +00:00
} else {
2022-09-03 15:44:26 +00:00
sheetData.system.load_level=load_level[loadout];
2020-07-27 13:02:27 +00:00
}
2022-09-03 15:44:26 +00:00
sheetData.system.load_levels = {"BITD.Light":"BITD.Light", "BITD.Normal":"BITD.Normal", "BITD.Heavy":"BITD.Heavy"};
sheetData.system.description = await TextEditor.enrichHTML(sheetData.system.description, {secrets: sheetData.owner, async: true});
2023-07-18 22:35:38 +00:00
// catch unmigrated actor data
for( const a in sheetData.system.attributes ) {
for( const s in sheetData.system.attributes[a].skills ) {
if( sheetData.system.attributes[a].skills[s].max === undefined ){
sheetData.system.attributes[a].skills[s].max = 4;
}
}
}
2022-09-03 15:44:26 +00:00
return sheetData;
2020-04-17 21:23:57 +00:00
}
/* -------------------------------------------- */
/** @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
2020-04-21 16:06:33 +00:00
html.find('.item-body').click(ev => {
const element = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(element.data("itemId"));
2020-04-17 21:23:57 +00:00
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click( async ev => {
2020-04-21 16:06:33 +00:00
const element = $(ev.currentTarget).parents(".item");
await this.actor.deleteEmbeddedDocuments("Item", [element.data("itemId")]);
2020-04-22 07:57:36 +00:00
element.slideUp(200, () => this.render(false));
2020-04-17 21:23:57 +00:00
});
2021-06-10 22:57:01 +00:00
// manage active effects
html.find(".effect-control").click(ev => BladesActiveEffect.onManageActiveEffect(ev, this.actor));
2020-04-17 21:23:57 +00:00
}
/* -------------------------------------------- */
}