Did what I needed to do to get d3 to not be loaded during play: refactored the ladder views out of the play wad, and got the Router to handle viewClass being a string rather than a fully loaded module.

This commit is contained in:
Scott Erickson 2014-11-29 16:46:36 -08:00
parent ad913024c0
commit 3a4eaa718f
19 changed files with 48 additions and 21 deletions

View file

@ -59,15 +59,25 @@ module.exports = ModuleLoader = class ModuleLoader extends CocoClass
onFileLoad: (e) =>
$("#module-loading-list li[data-path='#{e.item.id}']").removeClass('loading').addClass('success')
have = window.require.list()
console.group('Dependencies', e.item.id) if LOG
@recentLoadedBytes += e.rawResult.length
dependencies = @parseDependencies(e.rawResult)
console.groupEnd() if LOG
missing = _.difference dependencies, have
@load(module, false) for module in missing
locale.update() if _.string.startsWith(e.item.id, 'locale')
# load dependencies if it's not a vendor library
if not _.string.startsWith(e.item.id, 'vendor')
have = window.require.list()
console.group('Dependencies', e.item.id) if LOG
@recentLoadedBytes += e.rawResult.length
dependencies = @parseDependencies(e.rawResult)
console.groupEnd() if LOG
missing = _.difference dependencies, have
@load(module, false) for module in missing
# update locale data
if _.string.startsWith(e.item.id, 'locale')
locale.update()
# just a bit of cleanup to get the script objects out of the body element
$(e.result).remove()
# a module and its dependencies have loaded!
if @queue.progress is 1
$('#module-loading-list').modal('hide')
@recentPaths.sort()
@ -96,6 +106,7 @@ module.exports = ModuleLoader = class ModuleLoader extends CocoClass
console.groupEnd() if LOG
return dependencies
# basically ripped out of commonjs definition
expand: (root, name) ->
results = []
if /^\.\.?(\/|$)/.test(name)

View file

@ -84,8 +84,8 @@ module.exports = class CocoRouter extends Backbone.Router
'play-old': go('play/MainPlayView') # This used to be 'play'.
'play': go('play/WorldMapView')
'play/ladder/:levelID': go('play/ladder/LadderView')
'play/ladder': go('play/ladder/MainLadderView')
'play/ladder/:levelID': go('ladder/LadderView')
'play/ladder': go('ladder/MainLadderView')
'play/level/:levelID': go('play/level/PlayLevelView')
'play/spectate/:levelID': go('play/SpectateView')
'play/:map': go('play/WorldMapView')
@ -185,6 +185,14 @@ module.exports = class CocoRouter extends Backbone.Router
window.tracker?.trackPageView()
onNavigate: (e) ->
if _.isString e.viewClass
ViewClass = @tryToLoadModule e.viewClass
if not ViewClass and application.moduleLoader.load(e.viewClass)
@listenToOnce application.moduleLoader, 'load-complete', ->
@onNavigate(e)
return
e.viewClass = ViewClass
manualView = e.view or e.viewClass
if (e.route is document.location.pathname) and not manualView
return document.location.reload()

View file

@ -89,8 +89,8 @@ module.exports = class LevelSetupManager extends CocoClass
onInventoryModalPlayClicked: ->
@navigatingToPlay = true
PlayLevelView = require 'views/play/level/PlayLevelView'
LadderView = require 'views/play/ladder/LadderView'
PlayLevelView = 'views/play/level/PlayLevelView'
LadderView = 'views/ladder/LadderView'
viewClass = if @options.levelPath is 'ladder' then LadderView else PlayLevelView
Backbone.Mediator.publish 'router:navigate', {
route: "/play/#{@options.levelPath || 'level'}/#{@options.levelID}"

View file

@ -35,7 +35,7 @@ module.exports =
'router:navigate': c.object {required: ['route']},
route: {type: 'string'}
view: {type: 'object'}
viewClass: {type: 'function'}
viewClass: {type: ['function', 'string']}
viewArgs: {type: 'array'}
'router:navigated': c.object {required: ['route']},

View file

@ -1,6 +1,8 @@
CocoView = require 'views/core/CocoView'
template = require 'templates/editor/delta'
deltasLib = require 'core/deltas'
require 'vendor/diffview'
require 'vendor/difflib'
TEXTDIFF_OPTIONS =
baseTextName: "Old"

View file

@ -26,6 +26,8 @@ SystemsDocumentationView = require 'views/editor/docs/SystemsDocumentationView'
LevelFeedbackView = require 'views/editor/level/LevelFeedbackView'
storage = require 'core/storage'
require 'vendor/coffeescript' # this is tenuous, since the LevelSession and LevelComponent models are what compile the code
module.exports = class LevelEditView extends RootView
id: 'editor-level-view'
className: 'editor'

View file

@ -55,7 +55,7 @@ module.exports = class LadderView extends RootView
ctx._ = _
if tournamentDate = {greed: 1402444800000, 'criss-cross': 1410912000000}[@levelID]
ctx.tournamentTimeLeft = moment(new Date(tournamentDate)).fromNow()
ctx.winners = require('views/play/ladder/tournament_results')[@levelID]
ctx.winners = require('./tournament_results')[@levelID]
ctx
afterRender: ->

View file

@ -63,18 +63,18 @@ module.exports = class ControlBarView extends CocoView
if @level.get('type', true) in ['ladder', 'ladder-tutorial', 'hero-ladder']
levelID = @level.get('slug').replace /\-tutorial$/, ''
@homeLink = c.homeLink = '/play/ladder/' + levelID
@homeViewClass = require 'views/play/ladder/LadderView'
@homeViewClass = 'views/ladder/LadderView'
@homeViewArgs.push levelID
else if @level.get('type', true) in ['hero', 'hero-coop']
@homeLink = c.homeLink = '/play'
@homeViewClass = require 'views/play/WorldMapView'
@homeViewClass = 'views/play/WorldMapView'
campaign = CampaignOptions.getCampaignForSlug @level.get 'slug'
if campaign isnt 'dungeon'
@homeLink += '/' + campaign
@homeViewArgs.push campaign
else
@homeLink = c.homeLink = '/'
@homeViewClass = require 'views/HomeView'
@homeViewClass = 'views/HomeView'
c.editorLink = "/editor/level/#{@level.get('slug')}"
c.homeLink = @homeLink
c

View file

@ -340,6 +340,7 @@ module.exports = class PlayLevelView extends RootView
application.tracker?.trackEvent 'Started Level', category:'Play Level', levelID: @levelID
playAmbientSound: ->
return if @destroyed
return if @ambientSound
return unless file = {Dungeon: 'ambient-dungeon', Grass: 'ambient-grass'}[@level.get('terrain')]
src = "/file/interface/#{file}#{AudioPlayer.ext}"

View file

@ -260,7 +260,7 @@ module.exports = class HeroVictoryModal extends ModalView
onGameSubmitted: (e) ->
ladderURL = "/play/ladder/#{@level.get('slug')}#my-matches"
# Preserve the supermodel as we navigate back to the ladder.
Backbone.Mediator.publish 'router:navigate', route: ladderURL, viewClass: require('views/play/ladder/LadderView'), viewArgs: [{supermodel: @supermodel}, @level.get('slug')]
Backbone.Mediator.publish 'router:navigate', route: ladderURL, viewClass: 'views/ladder/LadderView', viewArgs: [{supermodel: @supermodel}, @level.get('slug')]
playSelectionSound: (hero, preload=false) ->
return unless sounds = hero.get('soundTriggers')?.selected
@ -324,4 +324,4 @@ module.exports = class HeroVictoryModal extends ModalView
e.preventDefault()
route = $(e.target).data('href')
# Preserve the supermodel as we navigate back to the ladder.
Backbone.Mediator.publish 'router:navigate', route: route, viewClass: require('views/play/ladder/LadderView'), viewArgs: [{supermodel: if @options.hasReceivedMemoryWarning then null else @supermodel}, @level.get('slug')]
Backbone.Mediator.publish 'router:navigate', route: route, viewClass: 'views/ladder/LadderView', viewArgs: [{supermodel: if @options.hasReceivedMemoryWarning then null else @supermodel}, @level.get('slug')]

View file

@ -63,8 +63,8 @@ exports.config =
#- vendor.js, all the vendor libraries
'javascripts/vendor.js': [
regJoin('^vendor/(?!scripts/Box2d)')
regJoin('^bower_components/(?!(aether|d3))')
regJoin('^vendor/scripts/(?!(Box2d|coffeescript))')
regJoin('^bower_components/(?!(aether|d3|difflib|diffview))')
]
#- Other vendor libraries in separate bunches
@ -78,6 +78,9 @@ exports.config =
# Any vendor libraries we don't want the client to load immediately
'javascripts/app/vendor/d3.js': regJoin('^bower_components/d3')
'javascripts/app/vendor/coffeescript.js': 'vendor/scripts/coffeescript.js'
'javascripts/app/vendor/difflib.js': 'vendor/scripts/difflib.js'
'javascripts/app/vendor/diffview.js': 'vendor/scripts/diffview.js'
#- test, demo libraries
'javascripts/test-app.js': regJoin('^test/app/')