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

Function loadThangTypes

app/lib/level-generation.js:356–380  ·  view source on GitHub ↗
(spriteNames)

Source from the content-addressed store, hash-verified

354const spriteNamesToThangTypes = {}
355const thangTypesToSpriteNames = {}
356async 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),
383generateProperty('thangs', async function (level, parameters) {

Callers 1

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected