This commit is contained in:
George Saines 2014-08-25 20:27:54 -07:00
commit ea3ade5bbc
8 changed files with 41 additions and 30 deletions

View file

@ -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

View file

@ -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)

View file

@ -83,7 +83,7 @@ module.exports = class WizardSprite extends IndieSprite
@options.colorConfig = $.extend(true, {}, newColorConfig)
if shouldUpdate
@setupSprite()
@playAction(@currentAction)
@playAction(@currentAction) if @currentAction
onSpriteSelected: (e) ->
return unless @isSelf

View file

@ -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

View file

@ -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 = {}

View file

@ -37,7 +37,7 @@ class LiveEditingMarkup extends TreemaNode.nodeMap.ace
.click(=> filepicker.pick @onFileChosen)
)
)
addPreviewToggle: (valEl) ->
valEl.append($('<div class="toggle-preview-button"></div>').append(
$('<button>Toggle Preview</button>')
@ -223,7 +223,7 @@ codeLanguages =
class CodeLanguagesObjectTreema extends TreemaNode.nodeMap.object
childPropertiesAvailable: ->
(key for key in _.keys(codeLanguages) when not @data[key]?)
(key for key in _.keys(codeLanguages) when not @data[key]? and not (key is 'javascript' and @schema.skipJavaScript))
class CodeLanguageTreema extends TreemaNode.nodeMap.string
buildValueForEditing: (valEl) ->
@ -316,7 +316,7 @@ class LatestVersionReferenceNode extends TreemaNode
input = valEl.find('input')
input.focus().keyup @search
input.attr('placeholder', @formatDocument(@data)) if @data
buildSearchURL: (term) -> "#{@url}?term=#{term}&project=true"
search: =>
@ -351,7 +351,7 @@ class LatestVersionReferenceNode extends TreemaNode
getSearchResultsEl: -> @getValEl().find('.treema-search-results')
getSelectedResultEl: -> @getValEl().find('.treema-search-selected')
modelToString: (model) -> model.get('name')
formatDocument: (docOrModel) ->
@ -411,7 +411,7 @@ class LatestVersionReferenceNode extends TreemaNode
return if @data?
selected = @getSelectedResultEl()
return not selected.length
class LevelComponentReferenceNode extends LatestVersionReferenceNode
# HACK: this list of properties is needed by the thang components edit view and config views.
# need a better way to specify this, or keep the search models from bleeding into those

View file

@ -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')

View file

@ -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}