(levelThang, supermodel, session, otherSession, thangTypesByOriginal)
| 117 | } |
| 118 | |
| 119 | denormalizeThang (levelThang, supermodel, session, otherSession, thangTypesByOriginal) { |
| 120 | let config, heroThangType, isHero, placeholderComponent, placeholders, placeholdersUsed, thangComponent |
| 121 | if (levelThang.components == null) { levelThang.components = [] } |
| 122 | if (utils.isCodeCombat) { |
| 123 | if (/Hero Placeholder/.test(levelThang.id)) { |
| 124 | isHero = this.usesSessionHeroInventory() |
| 125 | } |
| 126 | |
| 127 | if (isHero && otherSession) { |
| 128 | // If it's a hero and there's another session, find the right session for it. |
| 129 | // If there is no other session (playing against default code, or on single player), clone all placeholders. |
| 130 | // TODO: actually look at the teams on these Thangs to determine which session should go with which placeholder. |
| 131 | if ((levelThang.id === 'Hero Placeholder 1') && (session.get('team') === 'humans')) { |
| 132 | session = otherSession |
| 133 | } else if ((levelThang.id === 'Hero Placeholder') && (session.get('team') === 'ogres')) { |
| 134 | session = otherSession |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Empty out placeholder Components and store their values if we're the hero placeholder. |
| 139 | if (isHero) { |
| 140 | placeholders = {} |
| 141 | placeholdersUsed = {} |
| 142 | const placeholderThangType = thangTypesByOriginal[levelThang.thangType] |
| 143 | if (!placeholderThangType) { |
| 144 | console.error("Couldn't find placeholder ThangType for the hero!") |
| 145 | isHero = false |
| 146 | } else { |
| 147 | for (const defaultPlaceholderComponent of Array.from(placeholderThangType.get('components'))) { |
| 148 | placeholders[defaultPlaceholderComponent.original] = defaultPlaceholderComponent |
| 149 | } |
| 150 | for (thangComponent of Array.from(levelThang.components)) { |
| 151 | placeholders[thangComponent.original] = thangComponent |
| 152 | } |
| 153 | levelThang.components = [] // We have stored the placeholder values, so we can inherit everything else. |
| 154 | heroThangType = __guard__(session != null ? session.get('heroConfig') : undefined, x => x.thangType) |
| 155 | if (heroThangType) { |
| 156 | let juniorHeroReplacement |
| 157 | if (this.get('product', true) === 'codecombat-junior') { |
| 158 | // If we got into a codecombat-junior level with a codecombat hero, pick an equivalent codecombat-junior hero to use instead |
| 159 | juniorHeroReplacement = ThangTypeConstants.juniorHeroReplacements[_.invert(ThangTypeConstants.heroes)[heroThangType]] |
| 160 | } else { |
| 161 | // If we got into a codecombat level with a codecombat-junior hero, pick an equivalent codecombat hero to use instead |
| 162 | juniorHeroReplacement = _.invert(ThangTypeConstants.juniorHeroReplacements)[_.invert(ThangTypeConstants.heroes)[heroThangType]] |
| 163 | } |
| 164 | if (juniorHeroReplacement) { |
| 165 | heroThangType = ThangTypeConstants.heroes[juniorHeroReplacement] |
| 166 | } |
| 167 | levelThang.thangType = heroThangType |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | const thangType = thangTypesByOriginal[levelThang.thangType] |
| 174 | |
| 175 | const configs = {} |
| 176 | for (thangComponent of Array.from(levelThang.components)) { |
no test coverage detected