mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Set up the LevelLoader to load names instead of whole ThangTypes.
This commit is contained in:
parent
32ba4a8f75
commit
b9f4093b08
6 changed files with 29 additions and 17 deletions
11
app/collections/ThangNamesCollection.coffee
Normal file
11
app/collections/ThangNamesCollection.coffee
Normal 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}})
|
|
@ -4,6 +4,7 @@ LevelSystem = require 'models/LevelSystem'
|
||||||
Article = require 'models/Article'
|
Article = require 'models/Article'
|
||||||
LevelSession = require 'models/LevelSession'
|
LevelSession = require 'models/LevelSession'
|
||||||
ThangType = require 'models/ThangType'
|
ThangType = require 'models/ThangType'
|
||||||
|
ThangNamesCollection = require 'collections/ThangNamesCollection'
|
||||||
|
|
||||||
CocoClass = require 'lib/CocoClass'
|
CocoClass = require 'lib/CocoClass'
|
||||||
AudioPlayer = require 'lib/AudioPlayer'
|
AudioPlayer = require 'lib/AudioPlayer'
|
||||||
|
@ -21,6 +22,7 @@ World = require 'lib/world/world'
|
||||||
module.exports = class LevelLoader extends CocoClass
|
module.exports = class LevelLoader extends CocoClass
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
|
@t0 = new Date().getTime()
|
||||||
super()
|
super()
|
||||||
@supermodel = options.supermodel
|
@supermodel = options.supermodel
|
||||||
@levelID = options.levelID
|
@levelID = options.levelID
|
||||||
|
@ -99,11 +101,14 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
|
|
||||||
objUniq = (array) -> _.uniq array, false, (arg) -> JSON.stringify(arg)
|
objUniq = (array) -> _.uniq array, false, (arg) -> JSON.stringify(arg)
|
||||||
|
|
||||||
for thangID in _.uniq thangIDs
|
thangNames = new ThangNamesCollection(thangIDs)
|
||||||
url = "/db/thang.type/#{thangID}/version"
|
@supermodel.loadCollection thangNames, 'thang_names'
|
||||||
url += "?project=true" if @headless and not @editorMode
|
# for thangID in _.uniq thangIDs
|
||||||
res = @maybeLoadURL url, ThangType, 'thang'
|
# url = "/db/thang.type/#{thangID}/version"
|
||||||
@listenToOnce res.model, 'sync', @buildSpriteSheetsForThangType if res
|
# 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
|
for obj in objUniq componentVersions
|
||||||
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
|
url = "/db/level.component/#{obj.original}/version/#{obj.majorVersion}"
|
||||||
@maybeLoadURL url, LevelComponent, 'component'
|
@maybeLoadURL url, LevelComponent, 'component'
|
||||||
|
@ -192,6 +197,7 @@ module.exports = class LevelLoader extends CocoClass
|
||||||
@world = new World @level.get('name')
|
@world = new World @level.get('name')
|
||||||
serializedLevel = @level.serialize(@supermodel)
|
serializedLevel = @level.serialize(@supermodel)
|
||||||
@world.loadFromLevel serializedLevel, false
|
@world.loadFromLevel serializedLevel, false
|
||||||
|
console.log 'INITIALIZED!', (new Date().getTime() - @t0) / 1000
|
||||||
|
|
||||||
# Initial Sound Loading
|
# Initial Sound Loading
|
||||||
|
|
||||||
|
|
|
@ -695,5 +695,6 @@
|
||||||
opponent_session: "Opponent Session"
|
opponent_session: "Opponent Session"
|
||||||
article: "Article"
|
article: "Article"
|
||||||
user_names: "User Names"
|
user_names: "User Names"
|
||||||
|
thang_names: "Thang Names"
|
||||||
files: "Files"
|
files: "Files"
|
||||||
top_simulators: "Top Simulators"
|
top_simulators: "Top Simulators"
|
||||||
|
|
|
@ -80,7 +80,6 @@ module.exports = class SuperModel extends Backbone.Model
|
||||||
return _.values @models
|
return _.values @models
|
||||||
|
|
||||||
registerModel: (model) ->
|
registerModel: (model) ->
|
||||||
console.log 'register model?', model, model.getURL
|
|
||||||
@models[model.getURL()] = model
|
@models[model.getURL()] = model
|
||||||
|
|
||||||
getCollection: (collection) ->
|
getCollection: (collection) ->
|
||||||
|
@ -94,7 +93,7 @@ module.exports = class SuperModel extends Backbone.Model
|
||||||
@registerCollection(collection)
|
@registerCollection(collection)
|
||||||
|
|
||||||
registerCollection: (collection) ->
|
registerCollection: (collection) ->
|
||||||
@collections[collection.getURL()] = collection
|
@collections[collection.getURL()] = collection if collection.isCachable
|
||||||
# consolidate models
|
# consolidate models
|
||||||
for model, i in collection.models
|
for model, i in collection.models
|
||||||
cachedModel = @getModelByURL(model.getURL())
|
cachedModel = @getModelByURL(model.getURL())
|
||||||
|
|
|
@ -83,7 +83,6 @@ module.exports = class PlayLevelView extends View
|
||||||
@sessionID = @getQueryVariable 'session'
|
@sessionID = @getQueryVariable 'session'
|
||||||
|
|
||||||
$(window).on('resize', @onWindowResize)
|
$(window).on('resize', @onWindowResize)
|
||||||
@listenToOnce(@supermodel, 'error', @onLevelLoadError)
|
|
||||||
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
||||||
|
|
||||||
if @isEditorPreview
|
if @isEditorPreview
|
||||||
|
@ -96,10 +95,6 @@ module.exports = class PlayLevelView extends View
|
||||||
@load()
|
@load()
|
||||||
application.tracker?.trackEvent 'Started Level Load', level: @levelID, label: @levelID
|
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) ->
|
setLevel: (@level, @supermodel) ->
|
||||||
@god?.level = @level.serialize @supermodel
|
@god?.level = @level.serialize @supermodel
|
||||||
if @world
|
if @world
|
||||||
|
|
|
@ -112,7 +112,7 @@ module.exports = class Handler
|
||||||
ids = ids.split(',') if _.isString ids
|
ids = ids.split(',') if _.isString ids
|
||||||
ids = _.uniq ids
|
ids = _.uniq ids
|
||||||
|
|
||||||
project = {name:1}
|
project = {name:1, original:1}
|
||||||
sort = {'version.major':-1, 'version.minor':-1}
|
sort = {'version.major':-1, 'version.minor':-1}
|
||||||
|
|
||||||
makeFunc = (id) =>
|
makeFunc = (id) =>
|
||||||
|
@ -120,7 +120,7 @@ module.exports = class Handler
|
||||||
criteria = {original:mongoose.Types.ObjectId(id)}
|
criteria = {original:mongoose.Types.ObjectId(id)}
|
||||||
@modelClass.findOne(criteria, project).sort(sort).exec (err, document) ->
|
@modelClass.findOne(criteria, project).sort(sort).exec (err, document) ->
|
||||||
return done(err) if err
|
return done(err) if err
|
||||||
callback(null, document?.toObject() or {})
|
callback(null, document?.toObject() or null)
|
||||||
|
|
||||||
funcs = {}
|
funcs = {}
|
||||||
for id in ids
|
for id in ids
|
||||||
|
@ -129,7 +129,7 @@ module.exports = class Handler
|
||||||
|
|
||||||
async.parallel funcs, (err, results) ->
|
async.parallel funcs, (err, results) ->
|
||||||
return errors.serverError err if err
|
return errors.serverError err if err
|
||||||
res.send results
|
res.send (d for d in _.values(results) when d)
|
||||||
res.end()
|
res.end()
|
||||||
|
|
||||||
getPatchesFor: (req, res, id) ->
|
getPatchesFor: (req, res, id) ->
|
||||||
|
|
Loading…
Reference in a new issue