Added item editor level preview window.

This commit is contained in:
Nick Winter 2014-08-12 12:50:41 -07:00
parent 6d04b583f9
commit 2ab83328f3
6 changed files with 64 additions and 4 deletions
app

View file

@ -80,7 +80,7 @@ module.exports = class Level extends CocoModel
visit = (c) ->
return if c in sorted
lc = _.find levelComponents, {original: c.original}
console.error thang.id, 'couldn\'t find lc for', c, 'of', levelComponents unless lc
console.error thang.id or thang.name, 'couldn\'t find lc for', c, 'of', levelComponents unless lc
return unless lc
if lc.name is 'Programmable'
# Programmable always comes last
@ -88,7 +88,7 @@ module.exports = class Level extends CocoModel
else
for d in lc.dependencies or []
c2 = _.find thang.components, {original: d.original}
console.error thang.id, 'couldn\'t find dependent Component', d.original, 'from', lc.name unless c2
console.error thang.id or thang.name, 'couldn\'t find dependent Component', d.original, 'from', lc.name unless c2
visit c2 if c2
if lc.name is 'Collides'
allied = _.find levelComponents, {name: 'Allied'}

View file

@ -6,4 +6,4 @@
width: 30px
td
vertical-align: middle
vertical-align: middle

View file

@ -77,6 +77,8 @@
background-color: white
border-radius: 4px
.play-with-level-input
margin: 5px
#spritesheets

View file

@ -33,6 +33,16 @@ block header
span.navbar-brand #{thangType.attributes.name}
ul.nav.navbar-nav.navbar-right
li.dropdown
a(data-toggle='dropdown').play-with-level-parent
span.glyphicon-play.glyphicon
ul.dropdown-menu
li.dropdown-header Play Which Level?
li
for level in recentlyPlayedLevels
a.play-with-level-button(data-level=level)= level
input.play-with-level-input(placeholder="Type in a level name")
if authorized
li#save-button
a

View file

@ -12,6 +12,7 @@ ThangTypeColorsTabView = require './ThangTypeColorsTabView'
PatchesView = require 'views/editor/PatchesView'
SaveVersionModal = require 'views/modal/SaveVersionModal'
template = require 'templates/editor/thang/thang-type-edit-view'
storage = require 'lib/storage'
CENTER = {x: 200, y: 300}
@ -37,6 +38,9 @@ module.exports = class ThangTypeEditView extends RootView
'click #history-button': 'showVersionHistory'
'click #save-button': 'openSaveModal'
'click #patches-tab': -> @patchesView.load()
'click .play-with-level-button': 'onPlayLevel'
'click .play-with-level-parent': 'onPlayLevelSelect'
'keyup .play-with-level-input': 'onPlayLevelKeyUp'
subscriptions:
'save-new-version': 'saveNewThangType'
@ -58,6 +62,7 @@ module.exports = class ThangTypeEditView extends RootView
context.thangType = @thangType
context.animations = @getAnimationNames()
context.authorized = not me.get('anonymous')
context.recentlyPlayedLevels = storage.load('recently-played-levels') ? ['items']
context
getAnimationNames: ->
@ -408,6 +413,39 @@ module.exports = class ThangTypeEditView extends RootView
openSaveModal: ->
@openModalView(new SaveVersionModal({model: @thangType}))
onPlayLevelSelect: (e) ->
if @childWindow and not @childWindow.closed
# We already have a child window open, so we don't need to ask for a level; we'll use its existing level.
e.stopImmediatePropagation()
@onPlayLevel e
_.defer -> $('.play-with-level-input').focus()
onPlayLevelKeyUp: (e) ->
return unless e.keyCode is 13 # return
input = @$el.find('.play-with-level-input')
input.parents('.dropdown').find('.play-with-level-parent').dropdown('toggle')
level = _.string.slugify input.val()
return unless level
@onPlayLevel null, level
recentlyPlayedLevels = storage.load('recently-played-levels') ? []
recentlyPlayedLevels.push level
storage.save 'recently-played-levels', recentlyPlayedLevels
onPlayLevel: (e, level=null) ->
level ?= $(e.target).data('level')
level = _.string.slugify level
if @childWindow and not @childWindow.closed
# Reset the LevelView's world, but leave the rest of the state alone
@childWindow.Backbone.Mediator.publish 'level-reload-thang-type', thangType: @thangType
else
# Create a new Window with a blank LevelView
scratchLevelID = level + '?dev=true'
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
@childWindow = window.open("/play/level/#{scratchLevelID}", 'child_window', 'width=1024,height=560,left=10,top=10,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0', true)
@childWindow.focus()
destroy: ->
@camera?.destroy()
super()

View file

@ -55,6 +55,7 @@ module.exports = class PlayLevelView extends RootView
'god:new-world-created': 'onNewWorld'
'god:infinite-loop': 'onInfiniteLoop'
'level-reload-from-data': 'onLevelReloadFromData'
'level-reload-thang-type': 'onLevelReloadThangType'
'play-next-level': 'onPlayNextLevel'
'edit-wizard-settings': 'showWizardSettingsModal'
'surface:world-set-up': 'onSurfaceSetUpNewWorld'
@ -321,11 +322,20 @@ module.exports = class PlayLevelView extends RootView
onLevelReloadFromData: (e) ->
isReload = Boolean @world
@setLevel e.level, e.supermodel
@setLevel @level, e.supermodel
if isReload
@scriptManager.setScripts(e.level.get('scripts'))
Backbone.Mediator.publish 'tome:cast-spell' # a bit hacky
onLevelReloadThangType: (e) ->
tt = e.thangType
for url, model of @supermodel.models
if model.id is tt.id
for key, val of tt.attributes
model.attributes[key] = val
break
Backbone.Mediator.publish 'tome:cast-spell'
onWindowResize: (s...) ->
$('#pointer').css('opacity', 0.0)