UNPKG

warframe-worldstate-parser

Version:

An Open parser for Warframe's Worldstate in Javascript

71 lines (70 loc) 2.09 kB
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs"; import { WorldStateObject } from "./WorldStateObject.mjs"; import { createHash } from "node:crypto"; import { IsBoolean, IsString } from "class-validator"; import { fromNow, timeDeltaToString } from "warframe-worldstate-data/utilities"; //#region lib/models/MidrathCycle.ts /** * Get the current Midrath cycle time */ function getCurrentMidrathCycle() { const dayDuration = 1920 * 1e3; const nightDuration = 960 * 1e3; const totalDuration = 288e4; const refPoint = Date.parse("2025-08-07T16:05:29Z"); const now = Date.now(); const elapsedInCycle = (now - refPoint) % totalDuration; const isDay = elapsedInCycle < dayDuration; let phase = { name: "night", remaining: totalDuration - elapsedInCycle, duration: nightDuration }; if (isDay) phase = { name: "day", remaining: dayDuration - elapsedInCycle, duration: dayDuration }; const activation = new Date(now - (phase.duration - phase.remaining)); return { activation, expiry: new Date(activation.getTime() + phase.duration), state: phase.name, isDay }; } var MidrathCycle = class extends WorldStateObject { #cycle = getCurrentMidrathCycle(); /** * Whether it's day or not */ isDay; /** * The current state */ state; constructor() { super({ _id: { $oid: "midrathCycle0" } }); this.activation = this.#cycle.activation; this.expiry = this.#cycle.expiry; this.isDay = this.#cycle.isDay; this.state = this.#cycle.state; this.id = createHash("md5").update(JSON.stringify(this.expiry), "utf8").digest("hex"); } /** * Get whether or not the event has expired */ get expired() { return fromNow(this.expiry) < 0; } /** * The amount of time left as a string */ get timeLeft() { return timeDeltaToString(fromNow(this.expiry)); } }; __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], MidrathCycle.prototype, "isDay", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], MidrathCycle.prototype, "state", void 0); //#endregion export { MidrathCycle };