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

Method constructor

app/views/core/HeroSelectView.js:31–78  ·  view source on GitHub ↗
(options = {})

Source from the content-addressed store, hash-verified

29 }
30
31 constructor (options = {}) {
32 super(options)
33 let currentHeroOriginal, defaultHeroOriginal
34 this.options = options
35 if (utils.isCodeCombat) {
36 defaultHeroOriginal = ThangTypeConstants.heroes.captain
37 currentHeroOriginal = me.get('heroConfig')?.thangType || defaultHeroOriginal
38 } else {
39 defaultHeroOriginal = ThangTypeConstants.ozariaHeroes['hero-b']
40 currentHeroOriginal = me.get('ozariaUserOptions')?.isometricThangTypeOriginal || defaultHeroOriginal
41 }
42
43 this.debouncedRender = _.debounce(this.render, 0)
44
45 this.state = new State({
46 currentHeroOriginal,
47 selectedHeroOriginal: currentHeroOriginal
48 })
49
50 if (utils.isCodeCombat) {
51 api.thangTypes.getHeroes({ project: ['original', 'name', 'shortName', 'i18n', 'heroClass', 'slug', 'ozaria', 'poseImage'] }).then(heroes => {
52 if (this.destroyed) { return }
53 this.heroes = heroes.filter(function (hero) {
54 let clanHero
55 if (hero.ozaria) { return false }
56 if (clanHero = _.find(utils.clanHeroes, { thangTypeOriginal: hero.original })) {
57 let left, needle
58 if ((needle = clanHero.clanId, !(((left = me.get('clans')) != null ? left : [])).includes(needle))) { return false }
59 }
60 if (hero.original === ThangTypeConstants.heroes['code-ninja']) {
61 if (window.location.host !== 'coco.code.ninja') { return false }
62 }
63 return true
64 })
65 return this.debouncedRender()
66 })
67 } else {
68 // @heroes = new ThangTypes({}, { project: ['original', 'name', 'heroClass, 'slug''] })
69 // @supermodel.trackRequest @heroes.fetchHeroes()
70
71 api.thangTypes.getHeroes({ project: ['original', 'name', 'shortName', 'heroClass', 'slug', 'ozaria'] }).then(heroes => {
72 this.heroes = heroes.filter(h => !h.ozaria)
73 return this.debouncedRender()
74 })
75 }
76
77 this.listenTo(this.state, 'all', function () { return this.debouncedRender() })
78 }
79 // @listenTo @heroes, 'all', -> @debouncedRender()
80
81 onClickHeroOption (e) {

Callers

nothing calls this directly

Calls 2

filterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected