diff --git a/app/lib/LevelLoader.coffee b/app/lib/LevelLoader.coffee index cc9a6dd12..4298460c0 100644 --- a/app/lib/LevelLoader.coffee +++ b/app/lib/LevelLoader.coffee @@ -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 diff --git a/app/lib/surface/CocoSprite.coffee b/app/lib/surface/CocoSprite.coffee index a3dbc4130..d1066a37d 100644 --- a/app/lib/surface/CocoSprite.coffee +++ b/app/lib/surface/CocoSprite.coffee @@ -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) diff --git a/app/lib/surface/WizardSprite.coffee b/app/lib/surface/WizardSprite.coffee index fc59f010d..e0cb356f1 100644 --- a/app/lib/surface/WizardSprite.coffee +++ b/app/lib/surface/WizardSprite.coffee @@ -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 diff --git a/app/models/CocoModel.coffee b/app/models/CocoModel.coffee index de02d9f1d..759505283 100644 --- a/app/models/CocoModel.coffee +++ b/app/models/CocoModel.coffee @@ -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 diff --git a/app/models/Level.coffee b/app/models/Level.coffee index ad3458692..8dca3da50 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -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 = {} diff --git a/app/treema-ext.coffee b/app/treema-ext.coffee index d1f76b9a9..56e91a303 100644 --- a/app/treema-ext.coffee +++ b/app/treema-ext.coffee @@ -37,7 +37,7 @@ class LiveEditingMarkup extends TreemaNode.nodeMap.ace .click(=> filepicker.pick @onFileChosen) ) ) - + addPreviewToggle: (valEl) -> valEl.append($('
').append( $('') @@ -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 diff --git a/app/views/editor/level/LevelEditView.coffee b/app/views/editor/level/LevelEditView.coffee index 8461437e7..7dd827254 100644 --- a/app/views/editor/level/LevelEditView.coffee +++ b/app/views/editor/level/LevelEditView.coffee @@ -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') diff --git a/test/app/models/CocoModel.spec.coffee b/test/app/models/CocoModel.spec.coffee index 059eeb2cf..9456707b3 100644 --- a/test/app/models/CocoModel.spec.coffee +++ b/test/app/models/CocoModel.spec.coffee @@ -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/