UNPKG

warframe-worldstate-parser

Version:

An Open parser for Warframe's Worldstate in Javascript

94 lines (93 loc) 2.84 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, timeDeltaToString } from "warframe-worldstate-data/utilities"; //#region lib/models/CetusCycle.ts const nightTime = 3e3; const maximums = { day: 6e6, night: 3e6 }; /** * Represents the current Earth Day/Night Cycle * @augments {WorldStateObject} */ var CetusCycle = class extends WorldStateObject { /** * The end of the Ostron bounties timer (marks the end of night) */ #bountiesEndDate; /** * The current cetus cycle, for calculating the other fields */ #ec; /** * Whether it's daytime */ isDay; /** * Current cycle state. One of `day`, `night` */ state; /** * Time remaining string */ timeLeft; /** * Whether this is for Cetus Cycle */ isCetus; /** * @param bountiesEndDate The end date for Ostron bounties */ constructor(bountiesEndDate) { super({ _id: { $oid: "cetusCycle0" } }); this.#bountiesEndDate = bountiesEndDate; this.#ec = this.getCurrentCetusCycle(); this.expiry = this.#ec.expiry; this.activation = new Date(this.#ec.start); this.isDay = this.#ec.dayTime; this.state = this.#ec.state; this.timeLeft = this.#ec.timeLeft; this.isCetus = true; this.id = `cetusCycle${this.expiry.getTime()}`; } /** * Whether or not the event has expired */ get expired() { return fromNow(this.expiry) < 0; } /** * Short summary of the current state */ get shortString() { return `${this.timeLeft.replace(/\s\d*s/gi, "")} to ${this.isDay ? "Night" : "Day"}`; } getCurrentCetusCycle() { const now = Date.now(); const bountiesClone = this.#bountiesEndDate; bountiesClone.setSeconds(0); let millisLeft = fromNow(bountiesClone); const secondsToNightEnd = Number((millisLeft / 1e3).toFixed(0)); const dayTime = secondsToNightEnd > nightTime; millisLeft = (dayTime ? secondsToNightEnd - nightTime : secondsToNightEnd) * 1e3; const minutesCoef = 1e3 * 60; const expiry = /* @__PURE__ */ new Date(Math.round((now + millisLeft) / minutesCoef) * minutesCoef); const state = dayTime ? "day" : "night"; return { dayTime, timeLeft: timeDeltaToString(millisLeft), expiry, expiresIn: millisLeft, state, start: expiry.getTime() - maximums[state] }; } }; __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], CetusCycle.prototype, "isDay", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], CetusCycle.prototype, "state", void 0); __decorate([IsString(), __decorateMetadata("design:type", String)], CetusCycle.prototype, "timeLeft", void 0); __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], CetusCycle.prototype, "isCetus", void 0); //#endregion export { CetusCycle };