mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Revert changes to LevelLoader and SuperModel
This commit is contained in:
parent
92dc72cce1
commit
9c12f6c957
2 changed files with 24 additions and 20 deletions
|
@ -54,7 +54,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
if @level.loaded
|
||||
@onLevelLoaded()
|
||||
else
|
||||
@level = @supermodel.loadModel(@level).model
|
||||
@level = @supermodel.loadModel(@level, 'level').model
|
||||
@listenToOnce @level, 'sync', @onLevelLoaded
|
||||
|
||||
onLevelLoaded: ->
|
||||
|
@ -86,12 +86,12 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
session = new LevelSession().setURL url
|
||||
session.project = ['creator', 'team', 'heroConfig', 'codeLanguage', 'submittedCodeLanguage', 'state'] if @headless
|
||||
@sessionResource = @supermodel.loadModel(session, {cache: false})
|
||||
@sessionResource = @supermodel.loadModel(session, 'level_session', {cache: false})
|
||||
@session = @sessionResource.model
|
||||
if @opponentSessionID
|
||||
opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}"
|
||||
opponentSession.project = session.project if @headless
|
||||
@opponentSessionResource = @supermodel.loadModel(opponentSession, {cache: false})
|
||||
@opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session', {cache: false})
|
||||
@opponentSession = @opponentSessionResource.model
|
||||
|
||||
if @session.loaded
|
||||
|
@ -130,7 +130,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
heroConfig.thangType ?= '529ffbf1cf1818f2be000001' # If all else fails, assign Tharin as the hero.
|
||||
session.set 'heroConfig', heroConfig unless _.isEqual heroConfig, session.get('heroConfig')
|
||||
url = "/db/thang.type/#{heroConfig.thangType}/version"
|
||||
if heroResource = @maybeLoadURL(url, ThangType)
|
||||
if heroResource = @maybeLoadURL(url, ThangType, 'thang')
|
||||
@worldNecessities.push heroResource
|
||||
else
|
||||
heroThangType = @supermodel.getModel url
|
||||
|
@ -139,7 +139,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
for itemThangType in _.values(heroConfig.inventory)
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original,rasterIcon,kind"
|
||||
if itemResource = @maybeLoadURL(url, ThangType)
|
||||
if itemResource = @maybeLoadURL(url, ThangType, 'thang')
|
||||
@worldNecessities.push itemResource
|
||||
else
|
||||
itemThangType = @supermodel.getModel url
|
||||
|
@ -218,16 +218,16 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
for obj in objUniq componentVersions
|
||||
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
|
||||
worldNecessities.push @maybeLoadURL(url, LevelComponent)
|
||||
worldNecessities.push @maybeLoadURL(url, LevelComponent, 'component')
|
||||
for obj in objUniq systemVersions
|
||||
url = "/db/level.system/#{obj.original}/version/#{obj.majorVersion}"
|
||||
worldNecessities.push @maybeLoadURL(url, LevelSystem)
|
||||
worldNecessities.push @maybeLoadURL(url, LevelSystem, 'system')
|
||||
for obj in objUniq articleVersions
|
||||
url = "/db/article/#{obj.original}/version/#{obj.majorVersion}"
|
||||
@maybeLoadURL url, Article
|
||||
@maybeLoadURL url, Article, 'article'
|
||||
if obj = @level.get 'nextLevel' # TODO: update to get next level from campaigns, not this old property
|
||||
url = "/db/level/#{obj.original}/version/#{obj.majorVersion}"
|
||||
@maybeLoadURL url, Level
|
||||
@maybeLoadURL url, Level, 'level'
|
||||
|
||||
@worldNecessities = @worldNecessities.concat worldNecessities
|
||||
|
||||
|
@ -250,7 +250,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
console.error "Some Thang had a blank required ThangType in components list:", components
|
||||
for thangType in extantRequiredThangTypes
|
||||
url = "/db/thang.type/#{thangType}/version?project=name,components,original,rasterIcon,kind,prerenderedSpriteSheetData"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType)
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
|
||||
onThangNamesLoaded: (thangNames) ->
|
||||
for thangType in thangNames.models
|
||||
|
@ -263,7 +263,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
return unless components = thangType.get('components')
|
||||
for component in components
|
||||
url = "/db/level.component/#{component.original}/version/#{component.majorVersion}"
|
||||
@worldNecessities.push @maybeLoadURL(url, LevelComponent)
|
||||
@worldNecessities.push @maybeLoadURL(url, LevelComponent, 'component')
|
||||
|
||||
onWorldNecessityLoaded: (resource) ->
|
||||
index = @worldNecessities.indexOf(resource)
|
||||
|
@ -297,7 +297,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
# thangType = nameModelMap[thangTypeName]
|
||||
# continue if not thangType or thangType.isFullyLoaded()
|
||||
# thangType.fetch()
|
||||
# thangType = @supermodel.loadModel(thangType).model
|
||||
# thangType = @supermodel.loadModel(thangType, 'thang').model
|
||||
# res = @supermodel.addSomethingResource 'sprite_sheet', 5
|
||||
# res.thangType = thangType
|
||||
# res.markLoading()
|
||||
|
@ -305,10 +305,10 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
@buildLoopInterval = setInterval @buildLoop, 5 if @spriteSheetsToBuild.length
|
||||
|
||||
maybeLoadURL: (url, Model) ->
|
||||
maybeLoadURL: (url, Model, resourceName) ->
|
||||
return if @supermodel.getModel(url)
|
||||
model = new Model().setURL url
|
||||
@supermodel.loadModel(model)
|
||||
@supermodel.loadModel(model, resourceName)
|
||||
|
||||
onSupermodelLoaded: ->
|
||||
return if @destroyed
|
||||
|
|
|
@ -27,7 +27,11 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
unfinished.push resource unless resource.isLoaded
|
||||
unfinished
|
||||
|
||||
loadModel: (model, fetchOptions, value=1) ->
|
||||
loadModel: (model, name, fetchOptions, value=1) ->
|
||||
# Deprecating name. Handle if name is not included
|
||||
value = fetchOptions if _.isNumber(fetchOptions)
|
||||
fetchOptions = name if _.isObject(name)
|
||||
|
||||
# hero-ladder levels need remote opponent_session for latest session data (e.g. code)
|
||||
# Can't apply to everything since other features rely on cached models being more recent (E.g. level_session)
|
||||
# E.g.#2 heroConfig isn't necessarily saved to db in world map inventory modal, so we need to load the cached session on level start
|
||||
|
@ -51,7 +55,7 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
# Deprecating name. Handle if name is not included
|
||||
value = fetchOptions if _.isNumber(fetchOptions)
|
||||
fetchOptions = name if _.isObject(name)
|
||||
|
||||
|
||||
url = collection.getURL()
|
||||
if cachedCollection = @collections[url]
|
||||
console.debug 'Collection cache hit', url, 'already loaded', cachedCollection.loaded
|
||||
|
@ -76,7 +80,7 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
res = @addModelResource(collection, name, fetchOptions, value)
|
||||
res.load() if not (res.isLoading or res.isLoaded)
|
||||
return res
|
||||
|
||||
|
||||
# replace or overwrite
|
||||
shouldSaveBackups: (model) -> false
|
||||
|
||||
|
@ -136,13 +140,13 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
# Tracking resources being loaded for this supermodel
|
||||
|
||||
finished: ->
|
||||
return (@progress is 1.0) or (not @denom) or @failed
|
||||
return (@progress is 1.0) or (not @denom) or @failed
|
||||
|
||||
addModelResource: (modelOrCollection, name, fetchOptions, value=1) ->
|
||||
# Deprecating name. Handle if name is not included
|
||||
value = fetchOptions if _.isNumber(fetchOptions)
|
||||
fetchOptions = name if _.isObject(name)
|
||||
|
||||
|
||||
modelOrCollection.saveBackups = modelOrCollection.saveBackups or @shouldSaveBackups(modelOrCollection)
|
||||
@checkName(name)
|
||||
res = new ModelResource(modelOrCollection, name, fetchOptions, value)
|
||||
|
@ -156,7 +160,7 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
# Deprecating name. Handle if name is not included
|
||||
value = jqxhrOptions if _.isNumber(jqxhrOptions)
|
||||
jqxhrOptions = name if _.isObject(name)
|
||||
|
||||
|
||||
@checkName(name)
|
||||
res = new RequestResource(name, jqxhrOptions, value)
|
||||
@storeResource(res, value)
|
||||
|
|
Loading…
Reference in a new issue