Fixed #941. Actually it was no longer crashing probably because of the fix for #934, but there were still other bugs. Fixed it, and other bugs like it, particularly in the spectate view. Cleaned up a bit, too.

This commit is contained in:
Scott Erickson 2014-05-01 16:38:27 -07:00
parent 3bc0c1710e
commit 26cafd2f19
5 changed files with 17 additions and 127 deletions

View file

@ -1,104 +0,0 @@
CocoClass = require 'lib/CocoClass'
module.exports = class LoadingScreen extends CocoClass
progress: 0
constructor: (canvas) ->
super()
@width = canvas.width
@height = canvas.height
@stage = new createjs.Stage(canvas)
subscriptions:
'level-loader:progress-changed': 'onLevelLoaderProgressChanged'
show: ->
@stage.removeChild(@screen) if @screen
@screen = @makeScreen()
@stage.addChild(@screen)
@updateProgressBar()
hide: ->
@stage.removeChild(@screen) if @screen
@screen = null
makeScreen: ->
c = new createjs.Container()
c.addChild(@makeLoadBackground())
c.addChild(@makeLoadText())
c.addChild(@makeProgressBar())
@makeLoadLogo(c)
c
makeLoadBackground: ->
g = new createjs.Graphics()
g.beginFill(createjs.Graphics.getRGB(30,30,60))
g.drawRoundRect(0, 0, @width, @height, 0.0)
s = new createjs.Shape(g)
s.y = 0
s.x = 0
s
makeLoadLogo: (container) ->
logoImage = new Image()
$(logoImage).load =>
@logo = new createjs.Bitmap logoImage
@logo.x = @width / 2 - logoImage.width / 2
@logo.y = 40
container.addChild @logo
logoImage.src = "/images/loading_image.png"
makeLoadText: ->
size = @height / 10
text = new createjs.Text("LOADING", "#{size}px Monospace", "#ff7700")
text.regX = text.getMeasuredWidth() / 2
text.regY = text.getMeasuredHeight() / 2
text.x = @width / 2
text.y = @height / 2
@text = text
return text
makeProgressBar: ->
BAR_PIXEL_HEIGHT = 20
BAR_PCT_WIDTH = .75
pixelWidth = parseInt(@width * BAR_PCT_WIDTH)
pixelMargin = (@width - (@width * BAR_PCT_WIDTH)) / 2
barY = 2 * (@height / 3)
c = new createjs.Container()
c.x = pixelMargin
c.y = barY
g = new createjs.Graphics()
g.beginFill(createjs.Graphics.getRGB(255,0,0))
g.drawRoundRect(0,0,pixelWidth, BAR_PIXEL_HEIGHT, 5)
@progressBar = new createjs.Shape(g)
c.addChild(@progressBar)
g = new createjs.Graphics()
g.setStrokeStyle(2)
g.beginStroke(createjs.Graphics.getRGB(230,230,230))
g.drawRoundRect(0,0,pixelWidth, BAR_PIXEL_HEIGHT, 5)
c.addChild(new createjs.Shape(g))
c
onLevelLoaderProgressChanged: (e) ->
@progress = e.progress
@updateProgressBar()
updateProgressBar: ->
newProg = parseInt((@progress or 0) * 100)
newProg = ' '+newProg while newProg.length < 4
@lastProg = newProg
@text.text = "BUILDING" if @progress is 1
@progressBar.scaleX = @progress
@stage.update()
showReady: ->
@text.text = 'READY'
@text.regX = @text.getMeasuredWidth() / 2
@stage.update()
destroy: ->
@stage.canvas = null
super()

View file

@ -115,7 +115,7 @@ module.exports = class CocoView extends Backbone.View
afterRender: -> afterRender: ->
updateProgress: (progress)=> updateProgress: (progress) ->
@loadProgress.progress = progress if progress > @loadProgress.progress @loadProgress.progress = progress if progress > @loadProgress.progress
@updateProgressBar(progress) @updateProgressBar(progress)

View file

@ -6,9 +6,6 @@ module.exports = class LevelLoadingView extends View
id: "level-loading-view" id: "level-loading-view"
template: template template: template
subscriptions:
'level-loader:progress-changed': 'onLevelLoaderProgressChanged'
onLoaded: -> onLoaded: ->
afterRender: -> afterRender: ->
@$el.find('.tip.rare').remove() if _.random(1, 10) < 9 @$el.find('.tip.rare').remove() if _.random(1, 10) < 9
@ -17,15 +14,6 @@ module.exports = class LevelLoadingView extends View
$(tip).removeClass('to-remove') $(tip).removeClass('to-remove')
@$el.find('.to-remove').remove() @$el.find('.to-remove').remove()
onLevelLoaderProgressChanged: (e) ->
return if @destroyed
@progress = e.progress
@progress = 0.01 if @progress < 0.01
@updateProgressBar()
updateProgressBar: ->
@$el.find('.progress-bar').css('width', (100 * @progress) + '%')
showReady: -> showReady: ->
ready = $.i18n.t('play_level.loading_ready', defaultValue: 'Ready!') ready = $.i18n.t('play_level.loading_ready', defaultValue: 'Ready!')
@$el.find('#tip-wrapper .tip').addClass('ready').text ready @$el.find('#tip-wrapper .tip').addClass('ready').text ready
@ -35,7 +23,7 @@ module.exports = class LevelLoadingView extends View
_.delay @reallyUnveil, 1000 _.delay @reallyUnveil, 1000
reallyUnveil: => reallyUnveil: =>
return if @destroyed or @progress < 1 return if @destroyed
@$el.addClass 'unveiled' @$el.addClass 'unveiled'
loadingDetails = @$el.find('.loading-details') loadingDetails = @$el.find('.loading-details')
duration = parseFloat loadingDetails.css 'transition-duration' duration = parseFloat loadingDetails.css 'transition-duration'

View file

@ -87,10 +87,8 @@ module.exports = class PlayLevelView extends View
@saveScreenshot = _.throttle @saveScreenshot, 30000 @saveScreenshot = _.throttle @saveScreenshot, 30000
if @isEditorPreview if @isEditorPreview
f = => # wait to see if it's just given to us through setLevel
@supermodel.shouldSaveBackups = (model) -> f = => @load() unless @levelLoader
model.constructor.className in ['Level', 'LevelComponent', 'LevelSystem']
@load() unless @levelLoader
setTimeout f, 100 setTimeout f, 100
else else
@load() @load()
@ -100,7 +98,11 @@ module.exports = class PlayLevelView extends View
# TODO NOW: remove this in favor of the supermodel handling it # TODO NOW: remove this in favor of the supermodel handling it
application.router.navigate "/play?not_found=#{@levelID}", {trigger: true} application.router.navigate "/play?not_found=#{@levelID}", {trigger: true}
setLevel: (@level, @supermodel) -> setLevel: (@level, givenSupermodel) ->
@supermodel.models = givenSupermodel.models
@supermodel.collections = givenSupermodel.collections
@supermodel.shouldSaveBackups = givenSupermodel.shouldSaveBackups
@god?.level = @level.serialize @supermodel @god?.level = @level.serialize @supermodel
if @world if @world
serializedLevel = @level.serialize(@supermodel) serializedLevel = @level.serialize(@supermodel)
@ -129,7 +131,8 @@ module.exports = class PlayLevelView extends View
@$el.find('#level-done-button').hide() @$el.find('#level-done-button').hide()
$('body').addClass('is-playing') $('body').addClass('is-playing')
onLevelLoaderProgressChanged: -> updateProgress: (progress) ->
super(progress)
return if @seenDocs return if @seenDocs
return unless @levelLoader.session.loaded and @levelLoader.level.loaded return unless @levelLoader.session.loaded and @levelLoader.level.loaded
return unless showFrequency = @levelLoader.level.get('showsGuide') return unless showFrequency = @levelLoader.level.get('showsGuide')

View file

@ -106,7 +106,6 @@ module.exports = class SpectateLevelView extends View
spectateMode: true spectateMode: true
team: @getQueryVariable("team") team: @getQueryVariable("team")
@listenToOnce(@levelLoader, 'loaded-all', @onLevelLoaderLoaded) @listenToOnce(@levelLoader, 'loaded-all', @onLevelLoaderLoaded)
@listenTo(@levelLoader, 'progress', @onLevelLoaderProgressChanged)
@god = new God maxWorkerPoolSize: 1, maxAngels: 1 @god = new God maxWorkerPoolSize: 1, maxAngels: 1
getRenderData: -> getRenderData: ->
@ -121,7 +120,8 @@ module.exports = class SpectateLevelView extends View
super() super()
$('body').addClass('is-playing') $('body').addClass('is-playing')
onLevelLoaderProgressChanged: -> updateProgress: (progress) ->
super(progress)
return if @seenDocs return if @seenDocs
return unless showFrequency = @levelLoader.level.get('showGuide') return unless showFrequency = @levelLoader.level.get('showGuide')
session = @levelLoader.session session = @levelLoader.session
@ -141,7 +141,10 @@ module.exports = class SpectateLevelView extends View
Backbone.Mediator.subscribeOnce 'modal-closed', @onLevelLoaderLoaded, @ Backbone.Mediator.subscribeOnce 'modal-closed', @onLevelLoaderLoaded, @
return true return true
onLevelLoaderLoaded: -> onLoaded: ->
_.defer => @onLevelLoaded()
onLevelLoaded: ->
return unless @levelLoader.progress() is 1 # double check, since closing the guide may trigger this early 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 in local storage
if window.currentModal and not window.currentModal.destroyed if window.currentModal and not window.currentModal.destroyed