Files
pokemon-foundry/modules/sheets/pokemonCharacterSheet.js
Nikolaj ce5c9534b4
2025-08-05 10:15:03 +02:00

106 lines
3.6 KiB
JavaScript

const api = foundry.applications.api;
const sheets = foundry.applications.sheets;
export default class pokemonCharacterSheet extends api.HandlebarsApplicationMixin(sheets.ActorSheetV2) {
sheetContext = {};
tab = "tab1";
static DEFAULT_OPTIONS = {
tag: "form",
classes: ["pokemon", "sheet", "characterSheet"],
tabs: [
{navSelector: ".tabs", contentSelector: ".content", initial: this.tab}
],
form: {
submitOnChange: true,
closeOnSubmit: false
},
position: {
width: 650
}
}
static PARTS = {
header: { template: "systems/pokemon/templates/sheets/character/header.hbs" },
sidebar: { template: "systems/pokemon/templates/sheets/character/sidebar.hbs" }
}
get title() {
return this.actor.name;
}
/** @override */
_configureRenderOptions(options) {
super._configureRenderOptions(options);
if (this.document.limited) options.parts = ["header"]
else options.parts = ["header", "sidebar"];
}
/** @override */
async _prepareContext(options) {
// #################################################################################################
// #################################################################################################
// ## ##
// ## Creates Basic Datamodel, which is used to fill the HTML together with Handelbars with Data. ##
// ## ##
// #################################################################################################
// #################################################################################################
const baseData = await super._prepareContext();
let context = {
// Set General Values
owner: baseData.document.isOwner,
editable: baseData.editable,
actor: baseData.document,
system: baseData.document.system,
items: baseData.document.items,
config: CONFIG.POKEMON,
isGM: baseData.user.isGM,
effects: baseData.document.effects,
types: ["normal", "fire", "water", "electric", "grass", "ice", "fighting", "poison", "ground", "flying", "psychic", "bug", "rock", "ghost", "dragon", "dark", "steel", "fairy"]
};
context = this.calculateDerivated(context)
this.sheetContext = context;
context.system.tab = this.tab;
return context;
}
calculateDerivated(context) {
context.system.phArmorClass = 10+context.system.stats.defense;
context.system.spArmorClass = 10+context.system.stats.defense;
if (context.system.defenseCategory == "Physical") {
context.system.phArmorClass += 2;
} else {
context.system.spArmorClass += 2;
}
context.defenses = ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"]
context.system.speed = 30+5*context.system.stats.speed;
return context;
}
/** @override */
_onRender(context, options) {
const tabs = new foundry.applications.ux.Tabs({navSelector: ".tabs", contentSelector: ".content", initial: this.tab});
tabs.bind(this.element);
// tabs.activate(this.tab);
tabs.callback = () => {
this.tab = tabs.active;
}
}
}