ddnet
Version:
A typescript npm package for interacting with data from ddnet.org
92 lines • 2.14 kB
JavaScript
import { formatStringList, timeString } from '../../util.js';
import { Map } from '../maps/Map.js';
import { Player } from '../players/Player.js';
/**
* Represents a finish.
*/
export class Finish {
/**
* The timestamp of this finish.
*/
timestamp;
/**
* The name of the finished map.
*/
mapName;
/**
* The time of this finish in seconds.
*/
timeSeconds;
/**
* The string formatted time of this finish.
*
* @example "03:23"
*/
timeString;
/**
* The rank obtained.
*/
rank;
/**
* The region of this finish.
*/
region;
/**
* The finish player(s).
*/
players;
/**
* Construct a new {@link Finish} instance.
*/
constructor(data) {
this.timestamp = data.timestamp;
this.mapName = data.mapName;
this.timeSeconds = data.timeSeconds;
this.timeString = timeString(this.timeSeconds);
this.rank = data.rank;
this.region = data.region;
this.players = data.players.map(p => ({
name: p,
toPlayer: async () => await Player.new(p)
}));
}
/**
* 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);
}
/**
* Returns the names of the players and their finish time.
*
* @example "Sans3108 | 03:23"
*/
toString() {
return `${formatStringList(this.players.map(p => p.name))} | ${this.timeString}`;
}
}
/**
* Represents a player recent finish.
*/
export class RecentFinish extends Finish {
/**
* The type of the map.
*/
mapType;
/**
* Construct a new {@link RecentFinish} instance.
*/
constructor(data) {
super(data);
this.mapType = data.mapType;
}
}
//# sourceMappingURL=Finish.js.map