Files
pokemon-foundry/modules/sheets/pokemonCharacterSheet.js
Nikolaj 5045bbfa2a
2025-08-05 11:16:34 +02:00

121 lines
5.9 KiB
JavaScript

const api = foundry.applications.api;
const sheets = foundry.applications.sheets;
export default class pokemonCharacterSheet extends api.HandlebarsApplicationMixin(sheets.ActorSheetV2) {
effectivenessChart = {
'Normal': {'Rock': '0.5', 'Ghost': '0', 'Steel': '0.5'}, 'Fire': {'Fire': '0.5', 'Water': '0.5', 'Grass': '2', 'Ice': '2', 'Bug': '2', 'Rock': '0.5', 'Dragon': '0.5', 'Steel': '2'}, 'Water': {'Fire': '2', 'Water': '0.5', 'Grass': '0.5', 'Ground': '2', 'Rock': '2', 'Dragon': '0.5'}, 'Electric': {'Water': '2', 'Electric': '0.5', 'Grass': '0.5', 'Ground': '0', 'Flying': '2', 'Dragon': '0.5'}, 'Grass': {'Fire': '0.5', 'Water': '2', 'Grass': '0.5', 'Poison': '0.5', 'Ground': '2', 'Flying': '0.5', 'Bug': '0.5', 'Rock': '2', 'Dragon': '0.5', 'Steel': '0.5'}, 'Ice': {'Fire': '0.5', 'Water': '0.5', 'Grass': '2', 'Ice': '0.5', 'Ground': '2', 'Flying': '2', 'Dragon': '2', 'Steel': '0.5'}, 'Fighting': {'Normal': '2', 'Ice': '2', 'Poison': '0.5', 'Flying': '0.5', 'Psychic': '0.5', 'Bug': '0.5', 'Rock': '2', 'Ghost': '0', 'Dark': '2', 'Steel': '2', 'Fairy': '0.5'}, 'Poison': {'Grass': '2', 'Poison': '0.5', 'Ground': '0.5', 'Rock': '0.5', 'Ghost': '0.5', 'Steel': '0', 'Fairy': '2'}, 'Ground': {'Fire': '2', 'Electric': '2', 'Grass': '0.5', 'Poison': '2', 'Flying': '0', 'Bug': '0.5', 'Rock': '2', 'Steel': '2'}, 'Flying': {'Electric': '0.5', 'Grass': '2', 'Fighting': '2', 'Bug': '2', 'Rock': '0.5', 'Steel': '0.5'}, 'Psychic': {'Fighting': '2', 'Poison': '2', 'Psychic': '0.5', 'Dark': '0', 'Steel': '0.5'}, 'Bug': {'Fire': '0.5', 'Grass': '2', 'Fighting': '0.5', 'Poison': '0.5', 'Flying': '0.5', 'Psychic': '2', 'Ghost': '0.5', 'Dark': '2', 'Steel': '0.5', 'Fairy': '0.5'}, 'Rock': {'Fire': '0.5', 'Ice': '2', 'Fighting': '0.5', 'Ground': '0.5', 'Flying': '2', 'Bug': '2', 'Steel': '0.5'}, 'Ghost': {'Normal': '0', 'Psychic': '2', 'Ghost': '2', 'Dark': '0.5'}, 'Dragon': {'Dragon': '2', 'Steel': '0.5', 'Fairy': '0'}, 'Dark': {'Fighting': '0.5', 'Psychic': '2', 'Ghost': '2', 'Dark': '0.5', 'Fairy': '0.5'}, 'Steel': {'Fire': '0.5', 'Water': '0.5', 'Electric': '0.5', 'Ice': '2', 'Rock': '2', 'Steel': '0.5', 'Fairy': '2'}, 'Fairy': {'Fire': '0.5', 'Fighting': '2', 'Poison': '0.5', 'Dragon': '2', 'Dark': '2', 'Steel': '0.5'}
};
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 = context.types.map(type => this.calcEffectiveness(context, type));
context.system.speed = 30+5*context.system.stats.speed;
return context;
}
calcEffectiveness(context, type) {
var effectiveness = 1
effectiveness *= this.effectivenessChart[type][context.system.type1] ?? 1;
if (context.system.type2 != "") {
effectiveness *= this.effectivenessChart[type][context.system.type2] ?? 1;
}
return effectiveness
}
/** @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;
}
}
}