ddnet
Version:
A typescript npm package for interacting with data from ddnet.org
97 lines • 2.51 kB
JavaScript
import { Tile, Type, splitMappers } from '../../util.js';
import { Map } from '../maps/Map.js';
import { Mapper } from '../maps/Mapper.js';
/**
* Represents a map release.
*/
export class Release {
/**
* The name of this map.
*/
name;
/**
* The type of this map.
*/
type;
/**
* The url of this map on ddnet.org
*/
url;
/**
* The direct url of this map's thumbnail image.
*/
thumbnailUrl;
/**
* The url to the interactive web preview of this map.
*/
webPreviewUrl;
/**
* Amount of points awarded for completing this map.
*/
points;
/**
* Star difficulty of this map.
*/
difficulty;
/**
* Authors of this map.
*/
mappers;
/**
* Release timestamp of this map.
*/
releasedTimestamp;
/**
* The width of this map.
*/
width;
/**
* The height of this map.
*/
height;
/**
* Array of tiles used in this map.
*/
tiles;
/**
* Construct a new {@link Release} instance.
*/
constructor(data) {
this.name = data.name;
this.type = !Object.values(Type).includes(data.type) ? Type.unknown : data.type;
this.url = data.website;
this.thumbnailUrl = data.thumbnail;
this.webPreviewUrl = data.web_preview;
this.points = data.points;
this.difficulty = data.difficulty;
this.mappers = splitMappers(data.mapper).map(mapperName => new Mapper({ name: mapperName.trim() }));
this.releasedTimestamp = isNaN(data.releaseTimestamp) ? null : data.releaseTimestamp;
this.width = data.width;
this.height = data.height;
this.tiles = data.tiles.map(tile => {
const values = Object.values(Tile).filter(t => t !== Tile.UNKNOWN_TILE);
return !values.includes(tile) ? Tile.UNKNOWN_TILE : tile;
});
}
/**
* Returns a new {@link Map} object from the {@link name} of this release.
*/
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.name, rankSource, force);
}
/**
* Returns the name and url of this release in markdown format.
*/
toString() {
return `[${this.name}](${this.url})`;
}
}
//# sourceMappingURL=Release.js.map