From 26cafd2f1981c7c3ba070eb9d322afd4af1854ca Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Thu, 1 May 2014 16:38:27 -0700 Subject: [PATCH] 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. --- app/lib/LoadingScreen.coffee | 104 ------------------ app/views/kinds/CocoView.coffee | 2 +- .../play/level/level_loading_view.coffee | 14 +-- app/views/play/level_view.coffee | 15 ++- app/views/play/spectate_view.coffee | 9 +- 5 files changed, 17 insertions(+), 127 deletions(-) delete mode 100644 app/lib/LoadingScreen.coffee diff --git a/app/lib/LoadingScreen.coffee b/app/lib/LoadingScreen.coffee deleted file mode 100644 index 18889f240..000000000 --- a/app/lib/LoadingScreen.coffee +++ /dev/null @@ -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() diff --git a/app/views/kinds/CocoView.coffee b/app/views/kinds/CocoView.coffee index b78e7b165..aea3dfcf2 100644 --- a/app/views/kinds/CocoView.coffee +++ b/app/views/kinds/CocoView.coffee @@ -115,7 +115,7 @@ module.exports = class CocoView extends Backbone.View afterRender: -> - updateProgress: (progress)=> + updateProgress: (progress) -> @loadProgress.progress = progress if progress > @loadProgress.progress @updateProgressBar(progress) diff --git a/app/views/play/level/level_loading_view.coffee b/app/views/play/level/level_loading_view.coffee index 420128e0a..30bc067aa 100644 --- a/app/views/play/level/level_loading_view.coffee +++ b/app/views/play/level/level_loading_view.coffee @@ -6,9 +6,6 @@ module.exports = class LevelLoadingView extends View id: "level-loading-view" template: template - subscriptions: - 'level-loader:progress-changed': 'onLevelLoaderProgressChanged' - onLoaded: -> afterRender: -> @$el.find('.tip.rare').remove() if _.random(1, 10) < 9 @@ -17,15 +14,6 @@ module.exports = class LevelLoadingView extends View $(tip).removeClass('to-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: -> ready = $.i18n.t('play_level.loading_ready', defaultValue: 'Ready!') @$el.find('#tip-wrapper .tip').addClass('ready').text ready @@ -35,7 +23,7 @@ module.exports = class LevelLoadingView extends View _.delay @reallyUnveil, 1000 reallyUnveil: => - return if @destroyed or @progress < 1 + return if @destroyed @$el.addClass 'unveiled' loadingDetails = @$el.find('.loading-details') duration = parseFloat loadingDetails.css 'transition-duration' diff --git a/app/views/play/level_view.coffee b/app/views/play/level_view.coffee index 4c3b99008..5f087275a 100644 --- a/app/views/play/level_view.coffee +++ b/app/views/play/level_view.coffee @@ -87,10 +87,8 @@ module.exports = class PlayLevelView extends View @saveScreenshot = _.throttle @saveScreenshot, 30000 if @isEditorPreview - f = => - @supermodel.shouldSaveBackups = (model) -> - model.constructor.className in ['Level', 'LevelComponent', 'LevelSystem'] - @load() unless @levelLoader + # wait to see if it's just given to us through setLevel + f = => @load() unless @levelLoader setTimeout f, 100 else @load() @@ -100,7 +98,11 @@ module.exports = class PlayLevelView extends View # TODO NOW: remove this in favor of the supermodel handling it 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 if @world serializedLevel = @level.serialize(@supermodel) @@ -129,7 +131,8 @@ module.exports = class PlayLevelView extends View @$el.find('#level-done-button').hide() $('body').addClass('is-playing') - onLevelLoaderProgressChanged: -> + updateProgress: (progress) -> + super(progress) return if @seenDocs return unless @levelLoader.session.loaded and @levelLoader.level.loaded return unless showFrequency = @levelLoader.level.get('showsGuide') diff --git a/app/views/play/spectate_view.coffee b/app/views/play/spectate_view.coffee index 93db38908..4af55f00b 100644 --- a/app/views/play/spectate_view.coffee +++ b/app/views/play/spectate_view.coffee @@ -106,7 +106,6 @@ module.exports = class SpectateLevelView extends View spectateMode: true team: @getQueryVariable("team") @listenToOnce(@levelLoader, 'loaded-all', @onLevelLoaderLoaded) - @listenTo(@levelLoader, 'progress', @onLevelLoaderProgressChanged) @god = new God maxWorkerPoolSize: 1, maxAngels: 1 getRenderData: -> @@ -121,7 +120,8 @@ module.exports = class SpectateLevelView extends View super() $('body').addClass('is-playing') - onLevelLoaderProgressChanged: -> + updateProgress: (progress) -> + super(progress) return if @seenDocs return unless showFrequency = @levelLoader.level.get('showGuide') session = @levelLoader.session @@ -141,7 +141,10 @@ module.exports = class SpectateLevelView extends View Backbone.Mediator.subscribeOnce 'modal-closed', @onLevelLoaderLoaded, @ return true - onLevelLoaderLoaded: -> + onLoaded: -> + _.defer => @onLevelLoaded() + + onLevelLoaded: -> return unless @levelLoader.progress() is 1 # double check, since closing the guide may trigger this early # Save latest level played in local storage if window.currentModal and not window.currentModal.destroyed