RC-69 | Add Generic Sheet into Heirarchy
This commit is contained in:
parent
387c14c06d
commit
5773c2e920
2 changed files with 87 additions and 30 deletions
64
module/Apps/ActorSheets/GenericActorSheet.mjs
Normal file
64
module/Apps/ActorSheets/GenericActorSheet.mjs
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue