()
| 162 | } |
| 163 | |
| 164 | loadAILeagueStats () { |
| 165 | let arena |
| 166 | this.randomAILeagueBannerHero = _.sample(['anya', 'ida', 'okar']) |
| 167 | if (this.aiLeagueStats == null) { this.aiLeagueStats = {} } |
| 168 | const age = utils.ageToBracket(me.age()) |
| 169 | this.ageBracketDisplay = $.i18n.t(`ladder.bracket_${(age != null ? age : 'open').replace(/-/g, '_')}`) |
| 170 | |
| 171 | const fetches = [] |
| 172 | if (__guard__(me.get('clans'), x => x.length)) { |
| 173 | fetches.push(clansApi.getMyClans()) |
| 174 | } |
| 175 | |
| 176 | const myArenaSessionsCollections = {} |
| 177 | this.activeArenas = utils.activeArenas() |
| 178 | for (arena of Array.from(this.activeArenas)) { |
| 179 | arena.ended = new Date() > arena.end |
| 180 | const sessions = new LevelSessions() |
| 181 | myArenaSessionsCollections[arena.levelOriginal] = sessions |
| 182 | fetches.push(sessions.fetchForLevelSlug(arena.slug)) |
| 183 | } |
| 184 | |
| 185 | return Promise.all(fetches).then(results => { |
| 186 | let clan, levelOriginal, session |
| 187 | if (this.destroyed) { return } |
| 188 | if (__guard__(me.get('clans'), x1 => x1.length)) { |
| 189 | this.myClans = this.removeRedundantClans(results.shift()) // Generic Objects, not Clan models |
| 190 | for (clan of Array.from(this.myClans)) { |
| 191 | if (clan.displayName && !/[a-z]/.test(clan.displayName)) { |
| 192 | clan.displayName = utils.titleize(clan.displayName) |
| 193 | } |
| 194 | } // Convert any all-uppercase clan names to title-case |
| 195 | } else { |
| 196 | this.myClans = [] |
| 197 | } |
| 198 | this.myArenaSessions = {} |
| 199 | for (levelOriginal in myArenaSessionsCollections) { |
| 200 | const sessionsCollection = myArenaSessionsCollections[levelOriginal] |
| 201 | session = sessionsCollection.models[0] |
| 202 | if (session) { // Should only be zero or one; pick first one if multiple |
| 203 | this.myArenaSessions[levelOriginal] = session |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return (() => { |
| 208 | const result = [] |
| 209 | for (clan of Array.from([null].concat(this.myClans))) { |
| 210 | if (clan && ((clan.members != null ? clan.members.length : undefined) <= 1)) { continue } // Skip one-person clans to reduce fetches and useless data. |
| 211 | result.push((clan => { |
| 212 | // TODO: differentiate codePoints by age once more users have age set |
| 213 | leaderboardApi.getCodePointsPlayerCount(clan != null ? clan._id : undefined, {}).then(count => { |
| 214 | if (this.destroyed) { return } |
| 215 | this.setAILeagueStat('codePoints', (clan != null ? clan._id : undefined) != null ? (clan != null ? clan._id : undefined) : '_global', 'playerCount', count) |
| 216 | return this.sortMyClans() |
| 217 | }) |
| 218 | if (__guard__(me.get('stats'), x2 => x2.codePoints)) { |
| 219 | leaderboardApi.getCodePointsRankForUser(clan != null ? clan._id : undefined, me.get('_id'), {}).then(rank => { |
| 220 | if (this.destroyed) { return } |
| 221 | return this.setAILeagueStat('codePoints', (clan != null ? clan._id : undefined) != null ? (clan != null ? clan._id : undefined) : '_global', 'rank', rank) |
no test coverage detected