MCPcopy Index your code
hub / github.com/codecombat/codecombat / fillInDefaultComponentConfiguration

Method fillInDefaultComponentConfiguration

app/models/Level.js:418–454  ·  view source on GitHub ↗
(thangs, levelComponents)

Source from the content-addressed store, hash-verified

416 }
417
418 fillInDefaultComponentConfiguration (thangs, levelComponents) {
419 // This is slow, so I inserted some optimizations to speed it up by caching the eventual defaults of commonly-used Components.
420 if (this.defaultComponentConfigurations == null) { this.defaultComponentConfigurations = {} }
421 let cached = 0 // eslint-disable-line
422 let missed = 0
423 let cachedConfigs = 0 // eslint-disable-line
424 return Array.from(thangs != null ? thangs : []).map((thang) =>
425 (() => {
426 const result = []
427 for (const component of Array.from(thang.components || [])) {
428 let originalComponent
429 const defaultConfiguration = _.find(this.defaultComponentConfigurations[component.original], d => _.isEqual(component, d.originalComponent))
430 const isPhysical = component.original === LevelComponent.PhysicalID
431 if (!isPhysical && defaultConfiguration) {
432 component.config = defaultConfiguration.defaultedConfig
433 ++cached
434 continue
435 }
436 const lc = _.find(levelComponents, { original: component.original })
437 if (!lc) { continue }
438 if (!isPhysical) {
439 originalComponent = $.extend(true, {}, component)
440 }
441 if (component.config == null) { component.config = {} }
442 TreemaUtils.populateDefaults(component.config, lc.configSchema != null ? lc.configSchema : {}, tv4)
443 this.lastType = 'component'
444 this.lastOriginal = component.original
445 if (!isPhysical) {
446 if (this.defaultComponentConfigurations[component.original] == null) { this.defaultComponentConfigurations[component.original] = [] }
447 this.defaultComponentConfigurations[component.original].push({ originalComponent, defaultedConfig: component.config })
448 ++cachedConfigs
449 }
450 result.push(++missed)
451 }
452 return result
453 })())
454 }
455 // console.log 'cached', cached, 'missed', missed
456
457 fillInDefaultSystemConfiguration (levelSystems) {

Callers 1

serializeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected