diff --git a/app/lib/LevelLoader.coffee b/app/lib/LevelLoader.coffee index 2aa40edc6..afddc8720 100644 --- a/app/lib/LevelLoader.coffee +++ b/app/lib/LevelLoader.coffee @@ -61,7 +61,6 @@ module.exports = class LevelLoader extends CocoClass # Session Loading loadSession: -> - return if @headless if @sessionID url = "/db/level.session/#{@sessionID}" else @@ -71,6 +70,11 @@ module.exports = class LevelLoader extends CocoClass session = new LevelSession().setURL url @sessionResource = @supermodel.loadModel(session, 'level_session', {cache: false}) @session = @sessionResource.model + if @opponentSessionID + opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}" + @opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session') + @opponentSession = @opponentSessionResource.model + if @session.loaded @session.setURL '/db/level.session/' + @session.id @loadDependenciesForSession @session @@ -78,11 +82,7 @@ module.exports = class LevelLoader extends CocoClass @listenToOnce @session, 'sync', -> @session.setURL '/db/level.session/' + @session.id @loadDependenciesForSession @session - - if @opponentSessionID - opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}" - @opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session') - @opponentSession = @opponentSessionResource.model + if @opponentSession if @opponentSession.loaded @loadDependenciesForSession @opponentSession else @@ -92,11 +92,13 @@ module.exports = class LevelLoader extends CocoClass if session is @session Backbone.Mediator.publish 'level:session-loaded', level: @level, session: @session @consolidateFlagHistory() if @opponentSession?.loaded - else + else if session is @opponentSession @consolidateFlagHistory() if @session.loaded return unless @level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop'] + @sessionDependenciesRegistered ?= {} heroConfig = session.get('heroConfig') - heroConfig ?= me.get('heroConfig') if session is @session + heroConfig ?= me.get('heroConfig') if session is @session and not @headless + console.error @level.get('name'), session.get('team'), session.get('creatorName'), 'had hero', heroConfig.thangType heroConfig ?= {inventory: {}, 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" @@ -115,6 +117,9 @@ module.exports = class LevelLoader extends CocoClass itemThangType = @supermodel.getModel url @loadDefaultComponentsForThangType itemThangType @loadThangsRequiredByThangType itemThangType + @sessionDependenciesRegistered[session.id] = true + if _.size(@sessionDependenciesRegistered) is 2 and not (r for r in @worldNecessities when r?).length + @onWorldNecessitiesLoaded() consolidateFlagHistory: -> state = @session.get('state') ? {} @@ -172,7 +177,7 @@ module.exports = class LevelLoader extends CocoClass url = "/db/level/#{obj.original}/version/#{obj.majorVersion}" @maybeLoadURL url, Level, 'level' - unless @headless + unless @headless or @level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop'] wizard = ThangType.loadUniversalWizard() @supermodel.loadModel wizard, 'thang' @@ -216,9 +221,10 @@ module.exports = class LevelLoader extends CocoClass return unless index >= 0 @worldNecessities.splice(index, 1) @worldNecessities = (r for r in @worldNecessities when r?) - @onWorldNecessitiesLoaded() if @worldNecessities.length is 0 + if @worldNecessities.length is 0 and (not @sessionDependenciesRegistered or @sessionDependenciesRegistered[@session.id] and (not @opponentSession or @sessionDependenciesRegistered[@opponentSession.id])) + @onWorldNecessitiesLoaded() - onWorldNecessitiesLoaded: => + onWorldNecessitiesLoaded: -> @initWorld() @supermodel.clearMaxProgress() @trigger 'world-necessities-loaded' diff --git a/app/lib/simulator/Simulator.coffee b/app/lib/simulator/Simulator.coffee index eef6edae0..0ca70cb89 100644 --- a/app/lib/simulator/Simulator.coffee +++ b/app/lib/simulator/Simulator.coffee @@ -45,7 +45,7 @@ module.exports = class Simulator extends CocoClass @supermodel ?= new SuperModel() @supermodel.resetProgress() @stopListening @supermodel, 'loaded-all' - @levelLoader = new LevelLoader supermodel: @supermodel, levelID: @task.getLevelName(), sessionID: @task.getFirstSessionID(), headless: true + @levelLoader = new LevelLoader supermodel: @supermodel, levelID: @task.getLevelName(), sessionID: @task.getFirstSessionID(), opponentSessionID: @task.getSecondSessionID(), headless: true if @supermodel.finished() @simulateSingleGame() @@ -165,7 +165,7 @@ module.exports = class Simulator extends CocoClass @supermodel ?= new SuperModel() @supermodel.resetProgress() @stopListening @supermodel, 'loaded-all' - @levelLoader = new LevelLoader supermodel: @supermodel, levelID: levelID, sessionID: @task.getFirstSessionID(), headless: true + @levelLoader = new LevelLoader supermodel: @supermodel, levelID: levelID, sessionID: @task.getFirstSessionID(), opponentSessionID: @task.getSecondSessionID(), headless: true if @supermodel.finished() @simulateGame() else @@ -189,11 +189,13 @@ module.exports = class Simulator extends CocoClass @world = @levelLoader.world @task.setWorld(@world) @level = @levelLoader.level + @session = @levelLoader.session + @otherSession = @levelLoader.opponentSession @levelLoader.destroy() @levelLoader = null setupGod: -> - @god.setLevel @level.serialize @supermodel, @task.getSessions()[0], @task.getSessions()[1] + @god.setLevel @level.serialize(@supermodel, @session, @otherSession) @god.setLevelSessionIDs (session.sessionID for session in @task.getSessions()) @god.setWorldClassMap @world.classMap @god.setGoalManager new GoalManager(@world, @level.get 'goals') @@ -424,6 +426,8 @@ class SimulationTask getFirstSessionID: -> @rawData.sessions[0].sessionID + getSecondSessionID: -> @rawData.sessions[1].sessionID + getTaskID: -> @rawData.taskID getReceiptHandle: -> @rawData.receiptHandle diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index 82982f08b..f41bc5bd1 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -78,7 +78,8 @@ class CocoModel extends Backbone.Model thisTV4.addSchema('metaschema', require('schemas/metaschema')) TreemaNode.utils.populateDefaults(clone, @schema(), thisTV4) @attributesWithDefaults = clone - console.debug "Populated defaults for #{@attributes.name or @type()} in #{new Date() - t0}ms" + duration = new Date() - t0 + console.debug "Populated defaults for #{@attributes.name or @type()} in #{duration}ms" if duration > 10 loadFromBackup: -> return unless @saveBackups diff --git a/app/models/Level.coffee b/app/models/Level.coffee index 6d91b9334..2e72342f2 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -58,7 +58,6 @@ module.exports = class Level extends CocoModel # If it's a hero and there's another session, find the right session for it. # If there is no other session (playing against default code, or on single player), clone all placeholders. # TODO: actually look at the teams on these Thangs to determine which session should go with which placeholder. - console.error 'There is no session but there is a hero and an otherSession?', session, otherSession unless session?.get if levelThang.id is 'Hero Placeholder 1' and session.get('team') is 'humans' session = otherSession else if levelThang.id is 'Hero Placeholder' and session.get('team') is 'ogres' diff --git a/app/models/SuperModel.coffee b/app/models/SuperModel.coffee index 7f43c03a9..dbff4d2d3 100644 --- a/app/models/SuperModel.coffee +++ b/app/models/SuperModel.coffee @@ -121,7 +121,7 @@ module.exports = class SuperModel extends Backbone.Model if cachedModel clone = $.extend true, {}, model.attributes cachedModel.set(clone, {silent: true, fromMerge: true}) - console.debug "Updated cached model <#{cachedModel.get('name') or cachedModel.getURL()}> with new data" + #console.debug "Updated cached model <#{cachedModel.get('name') or cachedModel.getURL()}> with new data" else @registerModel(model) collection diff --git a/app/views/play/ladder/SimulateTabView.coffee b/app/views/play/ladder/SimulateTabView.coffee index 5993c2f22..616410d69 100644 --- a/app/views/play/ladder/SimulateTabView.coffee +++ b/app/views/play/ladder/SimulateTabView.coffee @@ -49,6 +49,7 @@ module.exports = class SimulateTabView extends CocoView fetchAndSimulateTaskOriginal = @simulator.fetchAndSimulateTask @simulator.fetchAndSimulateTask = => if @simulator.simulatedByYou >= 5 + console.log '------------------- Destroying Simulator and making a new one -----------------' @simulator.destroy() @simulator = null @simulateNextGame() diff --git a/server/queues/scoring.coffee b/server/queues/scoring.coffee index 13b3259e8..fd7dbc984 100644 --- a/server/queues/scoring.coffee +++ b/server/queues/scoring.coffee @@ -124,7 +124,7 @@ module.exports.getTwoGames = (req, res) -> #if userIsAnonymous req then return errors.unauthorized(res, 'You need to be logged in to get games.') humansGameID = req.body.humansGameID ogresGameID = req.body.ogresGameID - ladderGameIDs = ['greed', 'criss-cross', 'brawlwood', 'dungeon-arena', 'gold-rush', 'sky-span'] + ladderGameIDs = ['greed', 'criss-cross', 'brawlwood', 'dungeon-arena', 'gold-rush', 'sky-span', 'dueling-grounds', 'cavern-survival'] levelID = _.sample ladderGameIDs unless ogresGameID and humansGameID #fetch random games here diff --git a/test/app/lib/LevelLoader.spec.coffee b/test/app/lib/LevelLoader.spec.coffee index 4a9fc25b1..f177c703f 100644 --- a/test/app/lib/LevelLoader.spec.coffee +++ b/test/app/lib/LevelLoader.spec.coffee @@ -98,7 +98,7 @@ describe 'LevelLoader', -> levelLoader.loadDependenciesForSession(session) requests = jasmine.Ajax.requests.all() urls = (r.url for r in requests) - expect('/db/thang.type/gloves/version?project=name,components,original' in urls).toBeTruthy() + expect('/db/thang.type/gloves/version?project=name,components,original,rasterIcon,kind' in urls).toBeTruthy() expect('/db/thang.type/anya/version' in urls).toBeTruthy() it 'loads components for the hero in the heroConfig in the given session', -> @@ -141,7 +141,7 @@ describe 'LevelLoader', -> jasmine.Ajax.requests.sendResponses(responses) requests = jasmine.Ajax.requests.all() urls = (r.url for r in requests) - expect('/db/thang.type/mace/version?project=name,components,original' in urls).toBeTruthy() + expect('/db/thang.type/mace/version?project=name,components,original,rasterIcon,kind' in urls).toBeTruthy() it 'loads components which are inherited by level thangs from thang type default components', -> new LevelLoader({supermodel:new SuperModel(), sessionID: 'id', levelID: 'id'}) @@ -165,7 +165,7 @@ describe 'LevelLoader', -> jasmine.Ajax.requests.sendResponses(responses) requests = jasmine.Ajax.requests.all() urls = (r.url for r in requests) - expect('/db/thang.type/wand/version?project=name,components,original' in urls).toBeTruthy() + expect('/db/thang.type/wand/version?project=name,components,original,rasterIcon,kind' in urls).toBeTruthy() it 'loads components for item thang types which are inherited by level thangs from thang type default equips component configs', -> new LevelLoader({supermodel:new SuperModel(), sessionID: 'id', levelID: 'id'}) @@ -173,7 +173,7 @@ describe 'LevelLoader', -> responses = '/db/level/id': levelWithShaman '/db/thang.type/names': [thangTypeShamanWithWandEquipped] - '/db/thang.type/wand/version?project=name,components,original': thangTypeWand + '/db/thang.type/wand/version?project=name,components,original,rasterIcon,kind': thangTypeWand jasmine.Ajax.requests.sendResponses(responses) requests = jasmine.Ajax.requests.all() diff --git a/test/app/views/play/level/tome/Problem.spec.coffee b/test/app/views/play/level/tome/Problem.spec.coffee index cf663225c..27ec88c8b 100644 --- a/test/app/views/play/level/tome/Problem.spec.coffee +++ b/test/app/views/play/level/tome/Problem.spec.coffee @@ -10,7 +10,7 @@ describe 'Problem', -> addMarker: -> } } - aether = { + aether = { raw: "this.say('hi');\nthis.sad('bye');" language: { id: 'javascript' } } @@ -27,7 +27,8 @@ describe 'Problem', -> } levelID = 'awesome' - it 'save user code problem', -> + # TODO: Problems are no longer saved when creating Problems; instead it's in SpellView. Update tests? + xit 'save user code problem', -> new Problem aether, aetherProblem, ace, false, true, levelID expect(jasmine.Ajax.requests.count()).toBe(1) @@ -46,7 +47,7 @@ describe 'Problem', -> expect(params.language).toEqual(aether.language.id) expect(params.levelID).toEqual(levelID) - it 'save user code problem no range', -> + xit 'save user code problem no range', -> aetherProblem.range = null new Problem aether, aetherProblem, ace, false, true, levelID expect(jasmine.Ajax.requests.count()).toBe(1) @@ -68,7 +69,7 @@ describe 'Problem', -> expect(params.codeSnippet).toBeUndefined() expect(params.errRange).toBeUndefined() - it 'save user code problem multi-line snippet', -> + xit 'save user code problem multi-line snippet', -> aether.raw = "this.say('hi');\nthis.sad\n('bye');" aetherProblem.range = [ { row: 1 }, { row: 2 } ]