Create PlayerSheet

This commit is contained in:
Oliver-Akins 2025-06-29 00:47:05 -06:00
parent e0578d425d
commit e224f819a3
11 changed files with 252 additions and 0 deletions

View file

@ -0,0 +1,86 @@
import { __ID__, filePath } from "../consts.mjs";
const { HandlebarsApplicationMixin } = foundry.applications.api;
const { ActorSheetV2 } = foundry.applications.sheets;
export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
// #region Options
static DEFAULT_OPTIONS = {
classes: [
__ID__,
`PlayerSheet`,
],
position: {
width: 400,
height: 500,
},
window: {
resizable: true,
},
form: {
submitOnChange: true,
closeOnSubmit: false,
},
actions: {},
};
static PARTS = {
header: { template: filePath(`templates/PlayerSheet/header.hbs`) },
attributes: { template: filePath(`templates/PlayerSheet/attributes.hbs`) },
content: { template: filePath(`templates/PlayerSheet/content.hbs`) },
};
// #endregion Options
// #region Lifecycle
// #endregion Lifecycle
// #region Data Prep
async _preparePartContext(partID) {
let ctx = {
actor: this.actor,
system: this.actor.system,
editable: this.isEditable,
};
switch (partID) {
case `attributes`: {
await this._prepareAttributes(ctx);
break;
};
case `content`: {
await this._prepareContent(ctx);
break;
};
};
return ctx;
};
async _prepareAttributes(ctx) {
ctx.hasAttributes = this.actor.system.hasAttributes;
const attrs = [];
for (const [id, data] of Object.entries(this.actor.system.attr)) {
attrs.push({
...data,
id,
path: `system.attr.${id}`,
});
};
ctx.attrs = attrs.toSorted((a, b) => a.name.localeCompare(b.name));
};
async _prepareContent(ctx) {
const TextEditor = foundry.applications.ux.TextEditor.implementation;
ctx.enriched = {
system: {
content: await TextEditor.enrichHTML(this.actor.system.content),
},
};
};
// #endregion Data Prep
// #region Actions
// #endregion Actions
};