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

Method preloadLevel

app/views/play/CampaignView.js:1831–1854  ·  view source on GitHub ↗
(levelSlug)

Source from the content-addressed store, hash-verified

1829 }
1830
1831 preloadLevel (levelSlug) {
1832 const levelURL = `/db/level/${levelSlug}`
1833 const level = new Level().setURL(levelURL)
1834 this.supermodel.loadModel(level, null, 0)
1835
1836 // Note that this doesn't just preload the level. For sessions which require the
1837 // campaign to be included, it also creates the session. If this code is changed,
1838 // make sure to accommodate campaigns with free-in-certain-campaign-contexts levels,
1839 // such as game dev levels in game-dev-hoc.
1840 let sessionURL = `/db/level/${levelSlug}/session?campaign=${this.campaign.id}`
1841 const courseID = this.course?.get('_id')
1842 if (courseID) {
1843 sessionURL += `&course=${courseID}`
1844 if (this.courseInstanceID) {
1845 sessionURL += `&courseInstance=${this.courseInstanceID}`
1846 }
1847 }
1848
1849 this.preloadedSession = new LevelSession().setURL(sessionURL)
1850 this.listenToOnce(this.preloadedSession, 'sync', this.onSessionPreloaded)
1851 this.listenToOnce(this.preloadedSession, 'error', this.onSessionPreloadError)
1852 this.preloadedSession = this.supermodel.loadModel(this.preloadedSession, { cache: false }).model
1853 this.preloadedSession.levelSlug = levelSlug
1854 }
1855
1856 onSessionPreloaded (session) {
1857 session.url = function () { return '/db/level.session/' + this.id }

Callers 1

onClickLevelMethod · 0.95

Calls 2

setURLMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected