Set up the LevelLoader to load names instead of whole ThangTypes.

This commit is contained in:
Scott Erickson 2014-04-28 14:58:58 -07:00
parent 32ba4a8f75
commit b9f4093b08
6 changed files with 29 additions and 17 deletions

View file

@ -0,0 +1,11 @@
ThangType = require 'models/ThangType'
CocoCollection = require 'collections/CocoCollection'
module.exports = class ThangNamesCollection extends CocoCollection
url: '/db/thang.type/names'
model: ThangType
isCachable: false
constructor: (ids) ->
console.log 'data', {type:'POST', data:{ids:ids}}
super([], {type:'POST', data:{ids:ids}})

View file

@ -4,6 +4,7 @@ LevelSystem = require 'models/LevelSystem'
Article = require 'models/Article'
LevelSession = require 'models/LevelSession'
ThangType = require 'models/ThangType'
ThangNamesCollection = require 'collections/ThangNamesCollection'
CocoClass = require 'lib/CocoClass'
AudioPlayer = require 'lib/AudioPlayer'
@ -21,6 +22,7 @@ World = require 'lib/world/world'
module.exports = class LevelLoader extends CocoClass
constructor: (options) ->
@t0 = new Date().getTime()
super()
@supermodel = options.supermodel
@levelID = options.levelID
@ -98,12 +100,15 @@ module.exports = class LevelLoader extends CocoClass
articleVersions.push _.pick(article, ['original', 'majorVersion'])
objUniq = (array) -> _.uniq array, false, (arg) -> JSON.stringify(arg)
for thangID in _.uniq thangIDs
url = "/db/thang.type/#{thangID}/version"
url += "?project=true" if @headless and not @editorMode
res = @maybeLoadURL url, ThangType, 'thang'
@listenToOnce res.model, 'sync', @buildSpriteSheetsForThangType if res
thangNames = new ThangNamesCollection(thangIDs)
@supermodel.loadCollection thangNames, 'thang_names'
# for thangID in _.uniq thangIDs
# url = "/db/thang.type/#{thangID}/version"
# url += "?project=true" if @headless and not @editorMode
# res = @maybeLoadURL url, ThangType, 'thang'
# @listenToOnce res.model, 'sync', @buildSpriteSheetsForThangType if res
for obj in objUniq componentVersions
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
@maybeLoadURL url, LevelComponent, 'component'
@ -192,6 +197,7 @@ module.exports = class LevelLoader extends CocoClass
@world = new World @level.get('name')
serializedLevel = @level.serialize(@supermodel)
@world.loadFromLevel serializedLevel, false
console.log 'INITIALIZED!', (new Date().getTime() - @t0) / 1000
# Initial Sound Loading

View file

@ -695,5 +695,6 @@
opponent_session: "Opponent Session"
article: "Article"
user_names: "User Names"
thang_names: "Thang Names"
files: "Files"
top_simulators: "Top Simulators"

View file

@ -80,7 +80,6 @@ module.exports = class SuperModel extends Backbone.Model
return _.values @models
registerModel: (model) ->
console.log 'register model?', model, model.getURL
@models[model.getURL()] = model
getCollection: (collection) ->
@ -94,7 +93,7 @@ module.exports = class SuperModel extends Backbone.Model
@registerCollection(collection)
registerCollection: (collection) ->
@collections[collection.getURL()] = collection
@collections[collection.getURL()] = collection if collection.isCachable
# consolidate models
for model, i in collection.models
cachedModel = @getModelByURL(model.getURL())

View file

@ -83,7 +83,6 @@ module.exports = class PlayLevelView extends View
@sessionID = @getQueryVariable 'session'
$(window).on('resize', @onWindowResize)
@listenToOnce(@supermodel, 'error', @onLevelLoadError)
@saveScreenshot = _.throttle @saveScreenshot, 30000
if @isEditorPreview
@ -96,10 +95,6 @@ module.exports = class PlayLevelView extends View
@load()
application.tracker?.trackEvent 'Started Level Load', level: @levelID, label: @levelID
onLevelLoadError: (e) ->
# TODO NOW: remove this in favor of the supermodel handling it
application.router.navigate "/play?not_found=#{@levelID}", {trigger: true}
setLevel: (@level, @supermodel) ->
@god?.level = @level.serialize @supermodel
if @world

View file

@ -112,7 +112,7 @@ module.exports = class Handler
ids = ids.split(',') if _.isString ids
ids = _.uniq ids
project = {name:1}
project = {name:1, original:1}
sort = {'version.major':-1, 'version.minor':-1}
makeFunc = (id) =>
@ -120,8 +120,8 @@ module.exports = class Handler
criteria = {original:mongoose.Types.ObjectId(id)}
@modelClass.findOne(criteria, project).sort(sort).exec (err, document) ->
return done(err) if err
callback(null, document?.toObject() or {})
callback(null, document?.toObject() or null)
funcs = {}
for id in ids
return errors.badInput(res, "Given an invalid id: #{id}") unless Handler.isID(id)
@ -129,7 +129,7 @@ module.exports = class Handler
async.parallel funcs, (err, results) ->
return errors.serverError err if err
res.send results
res.send (d for d in _.values(results) when d)
res.end()
getPatchesFor: (req, res, id) ->