From a8644d030edc090416d2b64330841f7d353b0afc Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Sat, 30 Aug 2014 14:30:53 -0700 Subject: [PATCH] Fixed #1355. --- app/lib/LevelLoader.coffee | 1 + app/templates/editor/level/edit.jade | 4 +++- app/views/editor/level/LevelEditView.coffee | 4 ++++ app/views/play/level/PlayLevelView.coffee | 15 +++++++++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/lib/LevelLoader.coffee b/app/lib/LevelLoader.coffee index cfdb46ae9..b412abf74 100644 --- a/app/lib/LevelLoader.coffee +++ b/app/lib/LevelLoader.coffee @@ -243,6 +243,7 @@ module.exports = class LevelLoader extends CocoClass resource = null for resource in @spriteSheetsToBuild break if e.thangType is resource.thangType + return console.error 'Did not find spriteSheetToBuildResource for', e unless resource resource.spriteSheetKeys = (k for k in resource.spriteSheetKeys when k isnt e.key) resource.markLoaded() if resource.spriteSheetKeys.length is 0 diff --git a/app/templates/editor/level/edit.jade b/app/templates/editor/level/edit.jade index 5def3a60b..3405164bd 100644 --- a/app/templates/editor/level/edit.jade +++ b/app/templates/editor/level/edit.jade @@ -64,7 +64,9 @@ block header li.dropdown-header Play As Which Team? li for team in ['humans', 'ogres'] - a.play-with-team-button(data-team=team)= team + a.play-with-team-button(data-team=team)= team + ' vs. AI' + for match in recentlyPlayedOpponents + a.play-with-team-button(data-team=match.yourTeam, data-opponent=match.opponentSessionID)= match.yourTeam + ' vs. ' + match.opponentName else li(title="⌃↩ or ⌘↩: Play preview of current level")#play-button diff --git a/app/views/editor/level/LevelEditView.coffee b/app/views/editor/level/LevelEditView.coffee index c0cfaef66..2df56a719 100644 --- a/app/views/editor/level/LevelEditView.coffee +++ b/app/views/editor/level/LevelEditView.coffee @@ -19,6 +19,7 @@ RelatedAchievementsView = require 'views/editor/level/RelatedAchievementsView' VersionHistoryView = require './modals/LevelVersionsModal' ComponentsDocumentationView = require 'views/docs/ComponentsDocumentationView' SystemsDocumentationView = require 'views/docs/SystemsDocumentationView' +storage = require 'lib/storage' module.exports = class LevelEditView extends RootView id: 'editor-level-view' @@ -68,6 +69,7 @@ module.exports = class LevelEditView extends RootView context.level = @level context.authorized = me.isAdmin() or @level.hasWriteAccess(me) context.anonymous = me.get('anonymous') + context.recentlyPlayedOpponents = storage.load('recently-played-matches')?[@levelID] ? [] context afterRender: -> @@ -98,6 +100,7 @@ module.exports = class LevelEditView extends RootView onPlayLevel: (e) -> team = $(e.target).data('team') + opponentSessionID = $(e.target).data('opponent') sendLevel = => @childWindow.Backbone.Mediator.publish 'level:reload-from-data', level: @level, supermodel: @supermodel if @childWindow and not @childWindow.closed @@ -107,6 +110,7 @@ module.exports = class LevelEditView extends RootView # Create a new Window with a blank LevelView scratchLevelID = @level.get('slug') + '?dev=true' scratchLevelID += "&team=#{team}" if team + scratchLevelID += "&opponent=#{opponentSessionID}" if opponentSessionID if me.get('name') is 'Nick' @childWindow = window.open("/play/level/#{scratchLevelID}", 'child_window', 'width=2560,height=1080,left=0,top=-1600,location=1,menubar=1,scrollbars=1,status=0,titlebar=1,toolbar=1', true) else diff --git a/app/views/play/level/PlayLevelView.coffee b/app/views/play/level/PlayLevelView.coffee index acb6aa82f..2cd3e1479 100644 --- a/app/views/play/level/PlayLevelView.coffee +++ b/app/views/play/level/PlayLevelView.coffee @@ -3,9 +3,7 @@ template = require 'templates/play/level' {me} = require 'lib/auth' ThangType = require 'models/ThangType' utils = require 'lib/utils' - -# temp hard coded data -World = require 'lib/world/world' +storage = require 'lib/storage' # tools Surface = require 'lib/surface/Surface' @@ -280,14 +278,23 @@ module.exports = class PlayLevelView extends RootView # Everything is now loaded return unless @levelLoader.progress() is 1 # double check, since closing the guide may trigger this early - # Save latest level played in local storage + # Save latest level played. if not (@levelLoader.level.get('type') in ['ladder', 'ladder-tutorial']) me.set('lastLevel', @levelID) me.save() + @saveRecentMatch() if @otherSession @levelLoader.destroy() @levelLoader = null @initSurface() + saveRecentMatch: -> + allRecentlyPlayedMatches = storage.load('recently-played-matches') ? {} + recentlyPlayedMatches = allRecentlyPlayedMatches[@levelID] ? [] + allRecentlyPlayedMatches[@levelID] = recentlyPlayedMatches + recentlyPlayedMatches.unshift yourTeam: me.team, otherSessionID: @otherSession.id, opponentName: @otherSession.get('creatorName') unless _.find recentlyPlayedMatches, otherSessionID: @otherSession.id + recentlyPlayedMatches.splice(8) + storage.save 'recently-played-matches', allRecentlyPlayedMatches + initSurface: -> surfaceCanvas = $('canvas#surface', @$el) @surface = new Surface(@world, surfaceCanvas, thangTypes: @supermodel.getModels(ThangType), playJingle: not @isEditorPreview)