UNPKG

ddnet

Version:

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

80 lines 2.01 kB
/** * Represents a community server location */ export class CommunityServerLocation { /** * The region of this location. */ region; /** * The flag id of this location. */ flagId; /** * Reported server types and addresses for this location. */ types; /** * Construct a new {@link CommunityServerLocation} instance. */ constructor(data) { this.region = data.name; this.flagId = data.flagId; this.types = Object.entries(data.servers).map(entry => ({ name: entry[0], addresses: entry[1] })); } } /** * Represents a community. */ export class Community { /** * The id of this community. */ id; /** * The name of this community. */ name; /** * Wether to show finishes for maps. * * @remarks * According to https://discord.com/channels/252358080522747904/293493549758939136/1274386594270543954 * This values decides wether fnished maps have a flag next to them in the server browser on the ddnet client. */ hasFinishes; /** * The icon for this community. */ icon; /** * Server locations for this community along with their reported servers. */ serverLocations; /** * Construct a new {@link Community} instance. */ constructor(data) { this.id = data.id; this.name = data.name; this.hasFinishes = data.has_finishes; this.icon = { sha256: data.icon.sha256, url: data.icon.url }; this.serverLocations = data.icon.servers.map(s => new CommunityServerLocation(s)); } /** * Returns a list of all server addresses of this community. */ getAllServerAddresses() { return this.serverLocations.flatMap(l => l.types.flatMap(t => t.addresses)); } /** * Returns the name of the community. */ toString() { return this.name; } } //# sourceMappingURL=Community.js.map