mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Projected models can now update their projections and re-fetch. Hero ThangTypes now do this.
This commit is contained in:
parent
6eab4ff7a6
commit
e48b218533
6 changed files with 35 additions and 24 deletions
|
@ -31,7 +31,6 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@opponentSessionID = options.opponentSessionID
|
||||
@team = options.team
|
||||
@headless = options.headless
|
||||
@inLevelEditor = options.inLevelEditor
|
||||
@spectateMode = options.spectateMode ? false
|
||||
|
||||
@worldNecessities = []
|
||||
|
@ -89,8 +88,6 @@ module.exports = class LevelLoader extends CocoClass
|
|||
for itemThangType in _.values(heroConfig.inventory)
|
||||
url = "/db/thang.type/#{itemThangType}/version?project=name,components,original"
|
||||
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
|
||||
@populateHero() if @level?.loaded
|
||||
|
||||
# Supermodel (Level) Loading
|
||||
|
||||
loadLevel: ->
|
||||
|
@ -103,7 +100,6 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
onLevelLoaded: ->
|
||||
@populateLevel()
|
||||
@populateHero() if @session?.loaded
|
||||
|
||||
populateLevel: ->
|
||||
thangIDs = []
|
||||
|
@ -158,15 +154,6 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
@worldNecessities = @worldNecessities.concat worldNecessities
|
||||
|
||||
populateHero: ->
|
||||
return
|
||||
return if @inLevelEditor
|
||||
return unless @level.get('type') is 'hero' and hero = _.find @level.get('thangs'), id: 'Hero Placeholder'
|
||||
heroConfig = @session.get('heroConfig')
|
||||
hero.thangType = heroConfig.thangType # Will mutate the level, but we're okay showing the last-used Hero here
|
||||
#hero.id = ... ? # What do we want to do about this?
|
||||
# Actually, swapping out inventory and placeholder Components is done in Level's denormalizeThang
|
||||
|
||||
loadItemThangsEquippedByLevelThang: (levelThang) ->
|
||||
return unless levelThang.components
|
||||
for component in levelThang.components
|
||||
|
@ -225,8 +212,7 @@ module.exports = class LevelLoader extends CocoClass
|
|||
|
||||
for thangTypeName in thangsToLoad
|
||||
thangType = nameModelMap[thangTypeName]
|
||||
console.log 'found ThangType', thangType, 'for', thangTypeName, 'of nameModelMap', nameModelMap unless thangType
|
||||
continue if thangType.isFullyLoaded()
|
||||
continue if not thangType or thangType.isFullyLoaded()
|
||||
thangType.fetch()
|
||||
thangType = @supermodel.loadModel(thangType, 'thang').model
|
||||
res = @supermodel.addSomethingResource 'sprite_sheet', 5
|
||||
|
|
|
@ -82,6 +82,7 @@ module.exports = CocoSprite = class CocoSprite extends CocoClass
|
|||
if @thangType.isFullyLoaded()
|
||||
@setupSprite()
|
||||
else
|
||||
@thangType.setProjection null
|
||||
@thangType.fetch() unless @thangType.loading
|
||||
@listenToOnce(@thangType, 'sync', @setupSprite)
|
||||
|
||||
|
|
|
@ -22,8 +22,17 @@ class CocoModel extends Backbone.Model
|
|||
@on 'error', @onError, @
|
||||
@on 'add', @onLoaded, @
|
||||
@saveBackup = _.debounce(@saveBackup, 500)
|
||||
|
||||
setProjection: (@project) ->
|
||||
|
||||
setProjection: (project) ->
|
||||
return if project is @project
|
||||
url = @getURL()
|
||||
url += '&project=' unless /project=/.test url
|
||||
url = url.replace '&', '?' unless /\?/.test url
|
||||
url = url.replace /project=[^&]*/, "project=#{project?.join(',') or ''}"
|
||||
url = url.replace /[&?]project=&/, '&' unless project?.length
|
||||
url = url.replace /[&?]project=$/, '' unless project?.length
|
||||
@setURL url
|
||||
@project = project
|
||||
|
||||
type: ->
|
||||
@constructor.className
|
||||
|
@ -61,7 +70,7 @@ class CocoModel extends Backbone.Model
|
|||
CocoModel.backedUp[@id] = @
|
||||
|
||||
saveBackup: -> @saveBackupNow()
|
||||
|
||||
|
||||
saveBackupNow: ->
|
||||
storage.save(@id, @attributes)
|
||||
CocoModel.backedUp[@id] = @
|
||||
|
@ -220,7 +229,7 @@ class CocoModel extends Backbone.Model
|
|||
return false
|
||||
for key, value of newAttributes
|
||||
delete newAttributes[key] if _.isEqual value, @attributes[key]
|
||||
|
||||
|
||||
@set newAttributes
|
||||
return true
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ module.exports = class Level extends CocoModel
|
|||
placeholders[thangComponent.original] = thangComponent
|
||||
levelThang.components = []
|
||||
heroThangType = session?.get('heroConfig')?.thangType
|
||||
console.log "got thang type", heroThangType
|
||||
levelThang.thangType = heroThangType if heroThangType
|
||||
|
||||
configs = {}
|
||||
|
|
|
@ -47,7 +47,7 @@ module.exports = class LevelEditView extends RootView
|
|||
super options
|
||||
@supermodel.shouldSaveBackups = (model) ->
|
||||
model.constructor.className in ['Level', 'LevelComponent', 'LevelSystem', 'ThangType']
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, headless: true, inLevelEditor: true
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, headless: true
|
||||
@level = @levelLoader.level
|
||||
@files = new DocumentFiles(@levelLoader.level)
|
||||
@supermodel.loadCollection(@files, 'file_names')
|
||||
|
|
|
@ -22,7 +22,24 @@ describe 'CocoModel', ->
|
|||
b.fetch()
|
||||
request = jasmine.Ajax.requests.mostRecent()
|
||||
expect(decodeURIComponent(request.url).indexOf('project=number,object')).toBeGreaterThan(-1)
|
||||
|
||||
|
||||
it 'can update its projection', ->
|
||||
baseURL = '/db/bland/test?filter-creator=Mojambo&project=number,object&ignore-evil=false'
|
||||
unprojectedURL = baseURL.replace /&project=number,object/, ''
|
||||
b = new BlandClass({})
|
||||
b.setURL baseURL
|
||||
expect(b.getURL()).toBe baseURL
|
||||
b.setProjection ['number', 'object']
|
||||
expect(b.getURL()).toBe baseURL
|
||||
b.setProjection ['number']
|
||||
expect(b.getURL()).toBe baseURL.replace /,object/, ''
|
||||
b.setProjection []
|
||||
expect(b.getURL()).toBe unprojectedURL
|
||||
b.setProjection null
|
||||
expect(b.getURL()).toBe unprojectedURL
|
||||
b.setProjection ['object', 'number']
|
||||
expect(b.getURL()).toBe unprojectedURL + '&project=object,number'
|
||||
|
||||
describe 'save', ->
|
||||
|
||||
it 'saves to db/<urlRoot>', ->
|
||||
|
@ -95,7 +112,7 @@ describe 'CocoModel', ->
|
|||
xdescribe 'Achievement polling', ->
|
||||
NewAchievementCollection = require 'collections/NewAchievementCollection'
|
||||
EarnedAchievement = require 'models/EarnedAchievement'
|
||||
|
||||
|
||||
# TODO: Figure out how to do debounce in tests so that this test doesn't need to use keepDoingUntil
|
||||
|
||||
it 'achievements are polled upon saving a model', (done) ->
|
||||
|
@ -133,4 +150,3 @@ describe 'CocoModel', ->
|
|||
else return ready false
|
||||
|
||||
request.response {status:200, responseText: JSON.stringify me}
|
||||
|
||||
|
|
Loading…
Reference in a new issue