UNPKG

warframe-worldstate-parser

Version:

An Open parser for Warframe's Worldstate in Javascript

79 lines (78 loc) 2.47 kB
import { n as __decorateMetadata, t as __decorate } from "../../decorate-BCC26nnB.mjs"; import { WorldStateObject } from "./WorldStateObject.mjs"; import { IsBoolean, IsString } from "class-validator"; import { fromNow } from "warframe-worldstate-data/utilities"; //#region lib/models/EarthCycle.ts /** * Get the current Earth Day/Night Cycle * @returns {EarthCycle} The current Earth Day/Night Cycle */ function getCurrentEarthCycle() { const now = Date.now(); const cycleSeconds = Math.floor(now / 1e3) % 28800; const dayTime = cycleSeconds < 14400; let secondsLeft = 14400 - cycleSeconds % 14400; const millisLeft = secondsLeft * 1e3; const expiry = new Date(now + secondsLeft * 1e3); const minutesCoef = 1e3 * 60; const rounded = /* @__PURE__ */ new Date(Math.round((now + millisLeft) / minutesCoef) * minutesCoef); const timePieces = []; if (secondsLeft > 3600) { timePieces.push(`${Math.floor(secondsLeft / 3600)}h`); secondsLeft %= 3600; } if (secondsLeft > 60) { timePieces.push(`${Math.floor(secondsLeft / 60)}m`); secondsLeft %= 60; } timePieces.push(`${secondsLeft}s`); return { dayTime, timeLeft: timePieces.join(" "), expiry, expiresIn: millisLeft, rounded, state: dayTime ? "day" : "night", start: /* @__PURE__ */ new Date(expiry.getTime() - 1e3 * 60 * 60 * 4) }; } /** * Represents the current Earth Day/Night Cycle * @augments {WorldStateObject} */ var EarthCycle = class extends WorldStateObject { #ec = getCurrentEarthCycle(); /** * Whether or not this it's daytime */ isDay; /** * Current cycle state. One of `day`, `night` */ state; /** * Time remaining string */ timeLeft; constructor() { super({ _id: { $oid: "earthCycle0" } }); this.expiry = this.#ec.expiry; this.activation = this.#ec.start; this.isDay = this.#ec.dayTime; this.state = this.#ec.state; this.timeLeft = this.#ec.timeLeft; this.id = `earthCycle${this.#ec.rounded.getTime()}`; } /** * Get whether or not the event has expired * @returns {boolean} Whether or not the event has expired */ get expired() { return fromNow(this.expiry) < 0; } }; __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], EarthCycle.prototype, "isDay", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], EarthCycle.prototype, "state", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], EarthCycle.prototype, "timeLeft", void 0); //#endregion export { EarthCycle };