UNPKG

sprcl

Version:

Simple API client for Clash of Clans, Clash Royale, and Brawl Stars

305 lines (280 loc) 7.84 kB
class Achievement { constructor(name, stars, value, target, info, completionInfo, village) { this.name = name; this.stars = stars; this.value = value; this.target = target; this.info = info; this.completionInfo = completionInfo; this.village = village; } static fromJSON(json) { return new Achievement( json.name, json.stars, json.value, json.target, json.info, json.completionInfo, json.village ); } } class Label { constructor(id, name, iconUrls) { this.id = id; this.name = name; this.iconUrls = iconUrls; } static fromJSON(json) { return new Label( json.id, json.name, json.iconUrls ); } } class Troop { constructor(name, level, maxLevel, village, superTroopIsActive) { this.name = name; this.level = level; this.maxLevel = maxLevel; this.village = village; this.superTroopIsActive = superTroopIsActive || false; } static fromJSON(json) { return new Troop( json.name, json.level, json.maxLevel, json.village, json.superTroopIsActive ); } } class HeroEquipment { constructor(name, level, maxLevel, village) { this.name = name; this.level = level; this.maxLevel = maxLevel; this.village = village; } static fromJSON(json) { return new HeroEquipment( json.name, json.level, json.maxLevel, json.village ); } } class Hero { constructor(name, level, maxLevel, village, equipment) { this.name = name; this.level = level; this.maxLevel = maxLevel; this.village = village; this.equipment = equipment || []; } static fromJSON(json) { return new Hero( json.name, json.level, json.maxLevel, json.village, json.equipment ? json.equipment.map(HeroEquipment.fromJSON) : [] ); } } class Spell { constructor(name, level, maxLevel, village) { this.name = name; this.level = level; this.maxLevel = maxLevel; this.village = village; } static fromJSON(json) { return new Spell( json.name, json.level, json.maxLevel, json.village ); } } class PlayerHouseElement { constructor(type, id) { this.type = type; this.id = id; } static fromJSON(json) { return new PlayerHouseElement( json.type, json.id ); } } class SeasonResult { constructor(id, rank, trophies) { this.id = id; this.rank = rank; this.trophies = trophies; } static fromJSON(json) { return json ? new SeasonResult( json.id, json.rank, json.trophies ) : null; } } class LegendStatistics { constructor(legendTrophies, previousSeason, bestSeason, bestBuilderBaseSeason, currentSeason) { this.legendTrophies = legendTrophies; this.previousSeason = previousSeason; this.bestSeason = bestSeason; this.bestBuilderBaseSeason = bestBuilderBaseSeason; this.currentSeason = currentSeason; } static fromJSON(json) { return json ? new LegendStatistics( json.legendTrophies, SeasonResult.fromJSON(json.previousSeason), SeasonResult.fromJSON(json.bestSeason), SeasonResult.fromJSON(json.bestBuilderBaseSeason), SeasonResult.fromJSON(json.currentSeason)) : null; } } class League { constructor(id, name, iconUrls) { this.id = id; this.name = name; this.iconUrls = iconUrls; } static fromJSON(json) { return json ? new League( json.id, json.name, json.iconUrls ) : null; } } class Clan { constructor(tag, name, clanLevel, badgeUrls) { this.tag = tag; this.name = name; this.clanLevel = clanLevel; this.badgeUrls = badgeUrls; } static fromJSON(json) { return json ? new Clan( json.tag, json.name, json.clanLevel, json.badgeUrls ) : null; } } class Player { constructor( tag, name, townHallLevel, townHallWeaponLevel, expLevel, trophies, bestTrophies, warStars, attackWins, defenseWins, builderHallLevel, builderBaseTrophies, bestBuilderBaseTrophies, role, warPreference, donations, donationsReceived, clanCapitalContributions, clan, league, builderBaseLeague, legendStatistics, achievements, playerHouse, labels, troops, heroes, heroEquipment, spells ) { this.tag = tag; this.name = name; this.townHallLevel = townHallLevel; this.townHallWeaponLevel = townHallWeaponLevel; this.expLevel = expLevel; this.trophies = trophies; this.bestTrophies = bestTrophies; this.warStars = warStars; this.attackWins = attackWins; this.defenseWins = defenseWins; this.builderHallLevel = builderHallLevel; this.builderBaseTrophies = builderBaseTrophies; this.bestBuilderBaseTrophies = bestBuilderBaseTrophies; this.role = role; this.warPreference = warPreference; this.donations = donations; this.donationsReceived = donationsReceived; this.clanCapitalContributions = clanCapitalContributions; this.clan = clan; this.league = league; this.builderBaseLeague = builderBaseLeague; this.legendStatistics = legendStatistics; this.achievements = achievements; this.playerHouse = playerHouse; this.labels = labels; this.troops = troops; this.heroes = heroes; this.heroEquipment = heroEquipment; this.spells = spells; } static fromJSON(json) { return new Player( json.tag, json.name, json.townHallLevel, json.townHallWeaponLevel, json.expLevel, json.trophies, json.bestTrophies, json.warStars, json.attackWins, json.defenseWins, json.builderHallLevel, json.builderBaseTrophies, json.bestBuilderBaseTrophies, json.role, json.warPreference, json.donations, json.donationsReceived, json.clanCapitalContributions, Clan.fromJSON(json.clan), League.fromJSON(json.league), League.fromJSON(json.builderBaseLeague), LegendStatistics.fromJSON(json.legendStatistics), json.achievements ? json.achievements.map(Achievement.fromJSON) : [], json.playerHouse ? { elements: json.playerHouse.elements.map(PlayerHouseElement.fromJSON) } : null, json.labels ? json.labels.map(Label.fromJSON) : [], json.troops ? json.troops.map(Troop.fromJSON) : [], json.heroes ? json.heroes.map(Hero.fromJSON) : [], json.heroEquipment ? json.heroEquipment.map(HeroEquipment.fromJSON) : [], json.spells ? json.spells.map(Spell.fromJSON) : [] ); } toString() { return this.name; } } module.exports = { Player };