mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-17 19:12:33 -05:00
LevelLoader and Simulator fixes for simulating hero-ladder matches. Commented out some logging that hasn't been very useful. Fixed some tests.
This commit is contained in:
parent
1fb48f2b85
commit
08d9e39764
9 changed files with 38 additions and 26 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 } ]
|
||||
|
||||
|
|
Loading…
Reference in a new issue