Add the Aspect sheet and update some translation keys for the actor sheet

This commit is contained in:
Oliver-Akins 2023-12-15 23:55:47 -07:00
parent c0d677cd77
commit 763a0982d5
22 changed files with 1277 additions and 84 deletions

View file

@ -9,7 +9,8 @@ export const partials = [
export async function registerHandlebarsHelpers() {
Handlebars.registerHelper({
"dotdungeon-array": createArray
"dotdungeon-array": createArray,
"dotdungeon-toFriendlyDuration": toFriendlyDuration,
});
};
@ -33,4 +34,30 @@ export async function preloadHandlebarsTemplates() {
function createArray(...args) {
return args.slice(0, -1);
};
};
const secondsInAMinute = 60;
const secondsInAnHour = 60 * secondsInAMinute;
/**
* Converts a duration into a more human-friendly format
* @param {number} duration The length of time in seconds
* @returns The human-friendly time string
*/
function toFriendlyDuration(duration) {
let friendly = ``;
if (duration >= secondsInAnHour) {
let hours = Math.floor(duration / secondsInAnHour);
friendly += `${hours}h`;
duration -= hours * secondsInAnHour;
};
if (duration >= secondsInAMinute) {
let minutes = Math.floor(duration / secondsInAMinute);
friendly += `${minutes}m`;
duration -= minutes * secondsInAMinute;
};
if (duration > 0) {
friendly += `${duration}s`;
};
return friendly;
}

View file

@ -2,7 +2,6 @@ export class AspectItemData extends foundry.abstract.DataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
name: new fields.HTMLField({ nullable: true, blank: false, trim: true }),
used: new fields.BooleanField(),
/** The number of seconds that the effect of the aspect stays */
deactivateAfter: new fields.NumberField({ nullable: true }),

View file

@ -12,10 +12,20 @@ export class AspectSheet extends ItemSheet {
return opts;
};
activateListeners(html) {
super.activateListeners(html);
if (this.document.isEmbedded) return;
if (!this.isEditable) return;
console.debug(`.dungeon | Adding event listeners for Item: ${this.id}`);
};
getData() {
const ctx = super.getData();
const ctx = {};
const item = this.item.toObject(false);
ctx.name = super.name;
ctx.item = item;
ctx.system = item.system;
ctx.flags = item.flags;

View file

@ -13,6 +13,7 @@ export class PlayerSheet extends ActorSheet {
activateListeners(html) {
super.activateListeners(html);
if (this.document.isEmbedded) return;
if (!this.isEditable) return;
console.debug(`.dungeon | Adding event listeners for Actor: ${this.id}`);
@ -33,4 +34,4 @@ export class PlayerSheet extends ActorSheet {
console.groupEnd();
return ctx;
};
}
};