import { systemPath } from "../constants.mjs"; import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs"; import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs"; import { rollSpell, rollWeapon, rollSkill } from "./components/roll-actions.mjs"; import { M6ActorSheet } from "./actor-sheet.mjs"; const { api, sheets } = foundry.applications; /** * Extend the M6ActorSheet. */ export class M6CharacterSheet extends M6ActorSheet { /** @inheritdoc */ static get DEFAULT_OPTIONS() { return { ...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Options aus M6ActorSheet actions: { ...super.DEFAULT_OPTIONS.actions, // Kopiert alle bestehenden Actions aus M6ActorSheet cycleEquip: this.#cycleEquip, rollSkill: rollSkill, rollWeapon: rollWeapon, rollSpell: rollSpell, cycleEquip: this.#cycleEquip, addSpezialisierung: addSpezialisierung, editSepzialisierung: editSepzialisierung, }, }; } /* -------------------------------------------------- */ static TABS = { primary: { tabs: [ { id: "eigenschaften", icon: "fa-shield-halved", }, { id: "items", icon: "fa-suitcase", }, { id: "zauber", icon: "fa-hand-sparkles", }, { id: "hintergrund", icon: "fa-list", }, { id: "biographie", icon: "fa-feather-pointed", }, // { // id: "effects", // icon: "fa-bolt" // } ], initial: "eigenschaften", labelPrefix: "Midgard6.Sheets.Tabs", }, }; /* -------------------------------------------------- */ /** @inheritdoc */ static PARTS = { tabs: { template: systemPath("templates/shared/tabs.hbs"), }, header: { template: systemPath("templates/actor/header.hbs"), }, eigenschaften: { template: systemPath("templates/actor/eigenschaften.hbs"), scrollable: [""], }, zauber: { template: systemPath("templates/actor/zauber.hbs"), scrollable: [""], }, items: { template: systemPath("templates/actor/items.hbs"), scrollable: [""], }, hintergrund: { template: systemPath("templates/actor/hintergrund.hbs"), scrollable: [""], }, biographie: { template: systemPath("templates/actor/biographie.hbs"), scrollable: [""], }, // effects: { // template: systemPath("templates/shared/effects.hbs"), // scrollable: [""] // } }; /* -------------------------------------------------- */ /** @inheritdoc */ async _prepareContext(options) { const context = await super._prepareContext(options); Object.assign(context, { owner: this.document.isOwner, limited: this.document.limited, actor: this.actor, system: this.actor.system, skills: this.actor.system.skills, flags: this.actor.flags, config: CONFIG, }); context.itemTypes = await super._getItems(); return context; } /* -------------------------------------------------- */ /** @inheritdoc */ async _preparePartContext(partId, context) { switch (partId) { case "effects": context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects()); context.tab = context.tabs[partId]; break; case "eigenschaften": context.armor = await prepArmor(this.actor); context.skills = await this._getSkills(); context.resistenzen = await this._getResistenzen(); context.equippedWeapons = await prepWeapons(this.actor); context.equippedSpells = await prepSpells(this.actor); context.tab = context.tabs[partId]; break; case "items": context.gewicht = await prepWeight(this.actor); context.tab = context.tabs[partId]; break; case "zauber": context.tab = context.tabs[partId]; break; case "hintergrund": context.fields = await super._getFields(); context.tab = context.tabs[partId]; break; case "biographie": context.enrichedBeschreibung = await foundry.applications.ux.TextEditor.implementation.enrichHTML( this.actor.system.biographie.beschreibung, { // Whether to show secret blocks in the finished html secrets: this.document.isOwner, // Data to fill in for inline rolls rollData: this.actor.getRollData(), // Relative UUID resolution relativeTo: this.actor, }, ); context.tab = context.tabs[partId]; break; default: context.tab = context.tabs[partId]; } return context; } /* -------------------------------------------------- */ async _getSkills() { const doc = this.actor; const source = doc._source; const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.skills.fields; const fieldSets = []; // TODO: Find a clever way to handle enrichment for (const field of Object.values(systemFields ?? {})) { const path = `system.skills.${field.name}`; if (field instanceof foundry.data.fields.SchemaField) { const fieldset = { fieldset: true, legend: `Midgard6.Skills.gruppen.${field.label}`, fields: [], }; await this.#addSkillFields(fieldset, field.fields, source, path); fieldSets.push(fieldset); } else { fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } }); } } return fieldSets; } async #addSkillFields(fieldset, schema, source, _path = "system") { for (const field of Object.values(schema)) { const path = `${_path}.${field.name}`; if (field instanceof foundry.data.fields.SchemaField) { this.#addSkillFields(fieldset, field.fields, source, path); } else if (field.constructor.hasFormSupport) { fieldset.fields.push({ field, value: foundry.utils.getProperty(source, path), localizationName: "Midgard6.Skills." + field.label, bonuses: foundry.utils.getProperty(source, _path).bonuses, }); } } } /* -------------------------------------------------- */ async _getResistenzen() { const doc = this.actor; const source = doc._source; const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resistenzen; const fieldset = { fieldset: true, legend: `Midgard6.Attribute.${systemFields.label}`, fields: [], }; for (const field of Object.values(systemFields.fields ?? {})) { const path = `system.resistenzen.${field.name}`; fieldset.fields.push({ field, value: foundry.utils.getProperty(source, path), localizationName: "Midgard6.Resistenzen." + field.name, }); } return fieldset; } async _getResources() { const doc = this.actor; const source = doc._source; const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resources.fields; const fieldSets = []; // TODO: Find a clever way to handle enrichment for (const field of Object.values(systemFields ?? {})) { const path = `system.skills.${field.name}`; if (field instanceof foundry.data.fields.SchemaField) { const fieldset = { fieldset: true, legend: `Midgard6.resources.${field.label}`, fields: [], }; await this.#addSystemFields(fieldset, field.fields, source, path); fieldSets.push(fieldset); } else { fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } }); } } return fieldSets; } static async #cycleEquip(event, target) { const item = this.actor.items.get(target.dataset.itemId); item.update({ system: { equipped: !item.system.equipped, }, }); } /* -------------------------------------------------- */ /** * Recursively add system model fields to the fieldset. */ async #addSystemFields(fieldset, schema, source, _path = "system") { for (const field of Object.values(schema)) { const path = `${_path}.${field.name}`; if (field instanceof foundry.data.fields.SchemaField) { this.#addSystemFields(fieldset, field.fields, source, path); } else if (field.constructor.hasFormSupport) { fieldset.fields.push({ field, value: foundry.utils.getProperty(source, path), localizationName: "Midgard6.Skills." + field.label, }); } } } /* -------------------------------------------------- */ _getZauber() { return this.actor.items.filter((item) => item.type === "zauber"); } }