(spriteNames)
| 354 | const spriteNamesToThangTypes = {} |
| 355 | const thangTypesToSpriteNames = {} |
| 356 | async function loadThangTypes (spriteNames) { |
| 357 | // Need at least one promise in loadingPromises to prevent empty array Promise bug. |
| 358 | const loadingPromises = [Promise.resolve()] |
| 359 | const uniqueSpriteNames = _.uniq(spriteNames) |
| 360 | for (const spriteName of uniqueSpriteNames) { |
| 361 | let thangType = spriteNamesToThangTypes[spriteName] |
| 362 | if (!thangType) { |
| 363 | const slug = _.string.slugify(spriteName) |
| 364 | const fetchOptions = { |
| 365 | headers: { 'content-type': 'application/json' }, |
| 366 | credentials: 'same-origin' |
| 367 | } |
| 368 | const origin = window?.location?.origin || 'https://codecombat.com' |
| 369 | const thangTypePromise = fetch(`${origin}/db/thang.type/${slug}?project=original,components`, fetchOptions).then(async function (response) { |
| 370 | try { |
| 371 | thangType = await response.json() |
| 372 | spriteNamesToThangTypes[spriteName] = thangType |
| 373 | thangTypesToSpriteNames[thangType.original] = spriteName |
| 374 | } catch (err) {} |
| 375 | }) |
| 376 | loadingPromises.push(thangTypePromise) |
| 377 | } |
| 378 | } |
| 379 | await Promise.all(loadingPromises) |
| 380 | } |
| 381 | |
| 382 | // thangs: c.array({title: 'Thangs', description: 'An array of Thangs that make up the level.' }, LevelThangSchema), |
| 383 | generateProperty('thangs', async function (level, parameters) { |
no test coverage detected