MCPcopy Create free account
hub / github.com/codecombat/codecombat / calculateStatsForHeroConfig

Method calculateStatsForHeroConfig

app/models/ThangType.js:860–886  ·  view source on GitHub ↗
(heroConfig, callback)

Source from the content-addressed store, hash-verified

858 }
859
860 static calculateStatsForHeroConfig (heroConfig, callback) {
861 // Load enough information from the ThangTypes involved in a hero configuration to show various stats the hero will have.
862 // We don't rely on any supermodel caches, because this ThangType projection is useless anywhere else.
863 let original
864 const thisHeroConfigStats = {}
865 const heroOriginal = utils.showOzaria() ? ThangType.heroes['hero-b'] : heroConfig.thangType != null ? heroConfig.thangType : ThangType.heroes.captain
866 for (original of Array.from(_.values(heroConfig.inventory).concat([heroOriginal]))) {
867 thisHeroConfigStats[original] = ThangType.heroConfigStats[original] || 'loading'
868 }
869 for (original in thisHeroConfigStats) {
870 const stats = thisHeroConfigStats[original]
871 if (stats === 'loading') {
872 const url = `/db/thang.type/${original}/version?project=original,components,gems`
873 const tt = new ThangType().setURL(url);
874 (tt => {
875 return tt.on('sync', () => {
876 thisHeroConfigStats[tt.get('original')] = ThangType.heroConfigStats[tt.get('original')]
877 tt.off('sync')
878 tt.destroy()
879 return this.formatStatsForHeroConfig(thisHeroConfigStats, callback)
880 })
881 })(tt)
882 tt.fetch()
883 }
884 }
885 return this.formatStatsForHeroConfig(thisHeroConfigStats, callback)
886 }
887
888 static formatStatsForHeroConfig (heroConfigStats, callback) {
889 const heroConfigStatValues = _.values(heroConfigStats)

Callers 1

selectMethod · 0.80

Calls 5

setURLMethod · 0.80
getMethod · 0.45
destroyMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected