ddnet
Version:
A typescript npm package for interacting with data from ddnet.org
227 lines (226 loc) • 5.58 kB
TypeScript
import { LatestFinishesFilters, ServerRegion, Tile } from '../../util.js';
import { Finish } from '../other/Finish.js';
import { Player } from '../players/Player.js';
import { ServerType } from '../players/Servers.js';
import { Mapper } from './Mapper.js';
import { MaxFinish } from './MaxFinish.js';
/**
* Represents a DDNet map.
*
* @example
* ```ts
* const myFavMap = await Map.new('Kobra 4');
*
* console.log(myFavMap.webPreviewUrl); // "https://ddnet.org/mappreview/?map=Kobra+4"
* console.log(myFavMap.difficulty); // 4
* console.log(myFavMap.maxFinishes[0]);
* // MapMaxFinish {
* // rank: 1,
* // player: 'nameless tee',
* // count: 659,
* // timeSeconds: 1754617.6977539062,
* // timeString: '487:23:37',
* // minTimestamp: 1438545584000,
* // maxTimestamp: 1714287869000
* // }
* ```
*/
export declare class Map {
#private;
/**
* Map responses cache. (24h default TTL)
*/
private static cache;
/**
* Sets the TTL (Time-To-Live) for objects in cache.
*/
static setTTL: (ttlMS?: number) => void;
/**
* Clears the {@link Map.cache}.
*/
static clearCache: () => Promise<void>;
/**
* The name of this map.
*/
name: string;
/**
* The url of this map on ddnet.org
*/
url: string;
/**
* The direct url of this map's thumbnail image.
*/
thumbnailUrl: string;
/**
* The url to the interactive web preview of this map.
*/
webPreviewUrl: string;
/**
* The type of this map.
*/
type: ServerType;
/**
* Amount of points awarded for completing this map.
*/
points: number;
/**
* Star difficulty of this map.
*/
difficulty: number;
/**
* Authors of this map.
*/
mappers: Mapper[];
/**
* Release timestamp of this map.
*/
releasedTimestamp: number | null;
/**
* Biggest team to ever finish this map.
*/
biggestTeam: number;
/**
* The width of this map.
*/
width: number;
/**
* The height of this map.
*/
height: number;
/**
* Array of tiles used in this map.
*/
tiles: Tile[];
/**
* The region from which ranks are pulled. `null` for global ranks.
*/
rankSource: ServerRegion | null;
/**
* Team finishes for this map.
*/
teamFinishes: Finish[];
/**
* Ranks for this map.
*/
finishes: Finish[];
/**
* Top of most amount of finishes on this map.
*/
maxFinishes: MaxFinish[];
/**
* The average finish time of this map in seconds.
*/
medianTimeSeconds: number;
/**
* String formatted average finish time.
*
* @example "03:23"
*/
medianTimeString: string;
/**
* Timestamp for the first recorded finish on this map.
*/
firstFinishTimestamp: number | null;
/**
* Timestamp for the last recorded finish on this map.
*/
lastFinishTimestamp: number | null;
/**
* The total amount of times this map has been finished by any player.
*/
finishCount: number;
/**
* The total amount of players that have ever finished this map.
*/
finishersCount: number;
/**
* Create a new instance of {@link Map} from API data.
* Not intended to be used, use {@link new Map.new} instead.
*/
private constructor();
/**
* Fetch, parse and construct a new {@link Map} instance.
*/
static new(
/**
* The name or ddnet.org url of this map.
*/
nameOrUrl: string,
/**
* The region to pull ranks from. Omit for global ranks.
*
* @remarks
* Ignored if map url is used instead of map name.
*/
rankSource?: ServerRegion | null,
/**
* Wether to bypass the map data cache.
*/
bypassCache?: boolean): Promise<Map>;
/**
* Parse an object using the {@link _Schema_maps_json map raw data zod schema}.
*/
private static parseObject;
/**
* Fetch the map data from the API.
*/
private static makeRequest;
/**
* Populate the object with the raw map data.
*/
private populate;
/**
* Refresh the data for this map.
*/
refresh(): Promise<this>;
/**
* Returns the name and url of this map in markdown format.
*/
toString(): string;
/**
* Search for a map.
*/
static search(
/**
* The value to search for.
*/
value: string,
/**
* The region to pull ranks from in the `toMap` function from the returned value. Omit for global ranks.
*/
rankSource?: ServerRegion | null,
/**
* Wether to bypass the cache.
*/
force?: boolean): Promise<{
mappers: {
name: string;
toMapper: () => Mapper;
toPlayer: () => Promise<Player>;
}[];
type: ServerType;
name: string;
toMap: () => Promise<Map>;
latestFinishes: (filters: LatestFinishesFilters) => Promise<Finish[]>;
}[] | null>;
/**
* Get latest finishes, filtered for this map.
*/
getLatestFinishes(
/**
* Filtering options for latest finishes.
*/
filters?: LatestFinishesFilters): Promise<Finish[]>;
/**
* Get latest finishes, filtered for a specific map.
*/
static getLatestFinishes(
/**
* The name of the map.
*/
mapName: string,
/**
* Filtering options for latest finishes.
*/
filters?: LatestFinishesFilters): Promise<Finish[]>;
}