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

Method serialize

app/models/Level.js:46–81  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

44 }
45
46 serialize (options) {
47 let cached, otherSession, session, supermodel;
48 ({ supermodel, session, otherSession, headless: this.headless, sessionless: this.sessionless, cached, isEditorPreview: this.isEditorPreview } = options)
49 if (cached == null) { cached = false }
50 const o = this.denormalize(supermodel, session, otherSession) // hot spot to optimize
51
52 // Figure out Components
53 o.levelComponents = cached ? this.getCachedLevelComponents(supermodel) : $.extend(true, [], (Array.from(supermodel.getModels(LevelComponent)).map((lc) => lc.attributes)))
54 this.sortThangComponents(o.thangs, o.levelComponents, 'Level Thang')
55 this.fillInDefaultComponentConfiguration(o.thangs, o.levelComponents) // hot spot to optimize
56
57 // Figure out Systems
58 const systemModels = $.extend(true, [], (Array.from(supermodel.getModels(LevelSystem)).map((ls) => ls.attributes)))
59 o.systems = this.sortSystems(o.systems, systemModels)
60 this.fillInDefaultSystemConfiguration(o.systems)
61
62 // Figure out ThangTypes' Components
63 const tmap = {}
64 for (const t of Array.from(o.thangs != null ? o.thangs : [])) { tmap[t.thangType] = true }
65 let sessionHeroes = [__guard__(session != null ? session.get('heroConfig') : undefined, x => x.thangType), __guard__(otherSession != null ? otherSession.get('heroConfig') : undefined, x1 => x1.thangType)]
66 if (this.isType('ladder')) {
67 sessionHeroes = [] // Don't load session heroes in straight ladder matches
68 }
69 o.thangTypes = []
70 for (const tt of Array.from(supermodel.getModels('ThangType'))) {
71 if (tmap[tt.get('original')] ||
72 ((tt.get('kind') !== 'Hero' && tt.get('kind') !== 'Junior Hero') && (tt.get('kind') != null) && tt.get('components') && !tt.notInLevel) ||
73 ((tt.get('kind') === 'Hero' || tt.get('kind') === 'Junior Hero') && (this.isType('course', 'course-ladder', 'game-dev') || Array.from(sessionHeroes).includes(tt.get('original'))))) {
74 o.thangTypes.push(({ original: tt.get('original'), name: tt.get('name'), components: $.extend(true, [], tt.get('components')), kind: tt.get('kind') }))
75 }
76 }
77 this.sortThangComponents(o.thangTypes, o.levelComponents, 'ThangType')
78 this.fillInDefaultComponentConfiguration(o.thangTypes, o.levelComponents)
79
80 return o
81 }
82
83 getCachedLevelComponents (supermodel) {
84 if (this.cachedLevelComponents == null) { this.cachedLevelComponents = {} }

Callers 8

worker_world.jsFile · 0.80
trySerializeFunction · 0.80
setupGodMethod · 0.80
onThangsChangedMethod · 0.80
setLevelMethod · 0.80
onLevelLoaderLoadedMethod · 0.80
setLevelMethod · 0.80
setupGodMethod · 0.80

Calls 9

denormalizeMethod · 0.95
sortThangComponentsMethod · 0.95
sortSystemsMethod · 0.95
isTypeMethod · 0.95
__guard__Function · 0.70
getMethod · 0.45

Tested by

no test coverage detected