This commit is contained in:
Nick Winter 2014-08-30 14:30:53 -07:00
parent 85a9a558ef
commit a8644d030e
4 changed files with 19 additions and 5 deletions

View file

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

View file

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

View file

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

View file

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