From 649381cfdd7895057a55b93a8ae7dddcfbdc8d50 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 24 Mar 2024 16:53:12 -0600 Subject: [PATCH] Make the friendly duration be a getter on the Aspect class --- module/documents/Item/Aspect.mjs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/module/documents/Item/Aspect.mjs b/module/documents/Item/Aspect.mjs index a1ab7b8..ea66b6c 100644 --- a/module/documents/Item/Aspect.mjs +++ b/module/documents/Item/Aspect.mjs @@ -1,5 +1,8 @@ import { DotDungeonItem } from "./GenericItem.mjs"; +const secondsInAMinute = 60; +const secondsInAnHour = 60 * secondsInAMinute; + export class Aspect extends DotDungeonItem { async _preCreate() { if (this.isEmbedded) { @@ -16,5 +19,24 @@ export class Aspect extends DotDungeonItem { return await this.actor?.preItemEmbed(this); }; - } + }; + + get friendlyDuration() { + let friendly = ``; + let duration = this.system.deactivateAfter; + 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; + }; };