UNPKG

ddnet

Version:

A typescript npm package for interacting with data from ddnet.org

112 lines 2.86 kB
import { timeString } from '../../util.js'; import { Map } from '../maps/Map.js'; /** * Base class representing a player's map stats. */ export class MapStatsBase { /** * The map name. */ mapName; /** * The server type of this map. */ mapType; /** * The amount of points awarded for completing this map. */ points; constructor(data) { this.mapName = data.mapName; this.mapType = data.mapType; this.points = data.pointsReward; } /** * Returns a new {@link Map} object from the {@link mapName} of this finish. */ async toMap( /** * The region to pull ranks from in the `toMap` function from the returned value. Omit for global ranks. */ rankSource, /** * Wether to bypass the cache. */ force = false) { return await Map.new(this.mapName, rankSource, force); } } /** * Represents a player's unfinished map stats. */ export class UncompletedMapStats extends MapStatsBase { /** * The amount of finishes on this map. * * @remarks This will always be 0. */ finishCount; /** * Construct a new {@link UncompletedMapStats} instance. */ constructor(data) { super(data); this.finishCount = 0; } } /** * Represents a player's finished map stats. */ export class CompletedMapStats extends MapStatsBase { /** * The placement obtained on this map. */ placement; /** * Timestamp for the first ever finish on this map. */ firstFinishTimestamp; /** * Best finish time for this map in seconds. */ bestTimeSeconds; /** * The string formatted best finish time for this map. * * @example "03:23" */ bestTimeString; /** * The amount of finishes on this map. */ finishCount; /** * The team rank obtained on this map. */ teamRank; /** * Construct a new {@link CompletedMapStats} instance. */ constructor(data) { super(data); this.placement = data.rank; this.firstFinishTimestamp = data.firstFinishTimestamp; this.bestTimeSeconds = data.bestTimeSeconds; this.bestTimeString = timeString(this.bestTimeSeconds); this.finishCount = data.finishCount; this.teamRank = data.teamRank ?? null; } } /** * Helper function to assert if a given map stats object is {@link CompletedMapStats}. */ export function isCompletedMapStats(stats) { return stats instanceof CompletedMapStats && stats.finishCount > 0; } /** * Helper function to assert if a given map stats object is {@link UncompletedMapStats}. */ export function isUncompletedMapStats(stats) { return stats instanceof UncompletedMapStats && stats.finishCount === 0; } //# sourceMappingURL=MapStats.js.map