RC-69 | Add Generic Sheet into Heirarchy

This commit is contained in:
Oliver-Akins 2024-12-30 20:53:58 -07:00
parent 387c14c06d
commit 5773c2e920
2 changed files with 87 additions and 30 deletions

View file

@ -0,0 +1,64 @@
import { localizer } from "../../utils/Localizer.mjs";
import { Logger } from "../../utils/Logger.mjs";
const { Roll } = foundry.dice;
/**
* A mixin that takes the class from HandlebarsApplicationMixin and
*/
export function GenericSheetMixin(HandlebarsSheet) {
class GenericRipCryptSheet extends HandlebarsSheet {
// #region Options
static DEFAULT_OPTIONS = {
classes: [
`ripcrypt`,
],
actions: {
roll: this.rollDice,
},
};
// #endregion
// #region Lifecycle
async _preparePartContext(partId, ctx, opts) {
ctx = await super._preparePartContext(partId, ctx, opts);
delete ctx.document;
delete ctx.fields;
ctx.meta ??= {};
ctx.meta.idp = this.document.uuid;
ctx.meta.limited = this.actor.limited;
ctx.meta.editable = ctx.editable;
delete ctx.editable;
ctx.actor = this.document;
return ctx;
};
// #endregion
// #region Actions
/** @this {GenericRipCryptSheet} */
static async rollDice(_$e, el) {
const data = el.dataset;
const formula = data.formula;
Logger.debug(`Attempting to roll formula: ${formula}`);
let flavor;
if (data.flavor) {
flavor = localizer(
data.flavor,
);
}
const roll = new Roll(formula);
await roll.evaluate();
await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor,
});
};
// #endregion
};
return GenericRipCryptSheet;
};

View file

@ -1,18 +1,20 @@
import { filePath } from "../../consts.mjs"; import { filePath } from "../../consts.mjs";
import { gameTerms } from "../../gameTerms.mjs"; import { gameTerms } from "../../gameTerms.mjs";
import { GenericSheetMixin } from "./GenericActorSheet.mjs";
import { localizer } from "../../utils/Localizer.mjs"; import { localizer } from "../../utils/Localizer.mjs";
import { Logger } from "../../utils/Logger.mjs"; import { Logger } from "../../utils/Logger.mjs";
const { HandlebarsApplicationMixin } = foundry.applications.api; const { HandlebarsApplicationMixin } = foundry.applications.api;
const { ActorSheetV2 } = foundry.applications.sheets; const { ActorSheetV2 } = foundry.applications.sheets;
const { Roll } = foundry.dice; // const { Roll } = foundry.dice;
export class HeroSummaryCardV1 extends HandlebarsApplicationMixin(ActorSheetV2) { export class HeroSummaryCardV1 extends GenericSheetMixin(HandlebarsApplicationMixin(ActorSheetV2)) {
// #region Options // #region Options
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
classes: [ classes: [
`ripcrypt`, // `ripcrypt`,
`ripcrypt--actor`, `ripcrypt--actor`,
`ripcrypt--HeroSummaryCardV1`, `ripcrypt--HeroSummaryCardV1`,
`ripcrypt-theme--dark`, `ripcrypt-theme--dark`,
@ -25,7 +27,7 @@ export class HeroSummaryCardV1 extends HandlebarsApplicationMixin(ActorSheetV2)
resizable: false, resizable: false,
}, },
actions: { actions: {
roll: this.rollDice, // roll: this.rollDice,
}, },
form: { form: {
submitOnChange: true, submitOnChange: true,
@ -43,15 +45,6 @@ export class HeroSummaryCardV1 extends HandlebarsApplicationMixin(ActorSheetV2)
// #region Lifecycle // #region Lifecycle
async _preparePartContext(partId, ctx, opts) { async _preparePartContext(partId, ctx, opts) {
ctx = await super._preparePartContext(partId, ctx, opts); ctx = await super._preparePartContext(partId, ctx, opts);
delete ctx.document;
delete ctx.fields;
ctx.meta ??= {};
ctx.meta.idp = this.document.uuid;
ctx.meta.limited = this.actor.limited;
ctx.meta.editable = ctx.editable;
delete ctx.editable;
ctx.actor = this.document; ctx.actor = this.document;
ctx = await HeroSummaryCardV1.prepareGuts(ctx); ctx = await HeroSummaryCardV1.prepareGuts(ctx);
@ -134,24 +127,24 @@ export class HeroSummaryCardV1 extends HandlebarsApplicationMixin(ActorSheetV2)
// #endregion // #endregion
// #region Actions // #region Actions
static async rollDice(_$e, el) { // static async rollDice(_$e, el) {
const data = el.dataset; // const data = el.dataset;
const formula = data.formula; // const formula = data.formula;
Logger.debug(`Attempting to roll formula: ${formula}`); // Logger.debug(`Attempting to roll formula: ${formula}`);
let flavor; // let flavor;
if (data.flavor) { // if (data.flavor) {
flavor = localizer( // flavor = localizer(
data.flavor, // data.flavor,
); // );
} // }
const roll = new Roll(formula); // const roll = new Roll(formula);
await roll.evaluate(); // await roll.evaluate();
await roll.toMessage({ // await roll.toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }), // speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor, // flavor,
}); // });
}; // };
// #endregion // #endregion
}; };