Added getThangByID method to Thang. Handled a few error corner cases with the time popup.

This commit is contained in:
Nick Winter 2014-04-11 14:03:13 -07:00
parent cc0c588eb9
commit 10bb17c38a
2 changed files with 13 additions and 10 deletions
app
lib/world
views/play/level

View file

@ -42,6 +42,9 @@ module.exports = class Thang
setGoalState: (goalID, status) ->
@world.setGoalState goalID, status
getThangByID: (id) ->
@world.getThangByID id
addComponents: (components...) ->
# We don't need to keep the components around after attaching them, but we will keep their initial config for recreating Thangs
@components ?= []

View file

@ -151,7 +151,7 @@ module.exports = class PlaybackView extends View
@newTime = 0
@currentTime = 0
@timePopup = new HoverPopup unless @timePopup?
@timePopup ?= new HoverPopup
#TODO: Why do we need defaultValues here at all? Fallback language has been set to 'en'... oO
@ -192,7 +192,7 @@ module.exports = class PlaybackView extends View
@$progressScrubber.slider('disable', true)
catch e
#console.warn('error disabling scrubber')
@timePopup.disable()
@timePopup?.disable()
$('#volume-button', @$el).removeClass('disabled')
onEnableControls: (e) ->
@ -203,7 +203,7 @@ module.exports = class PlaybackView extends View
@$progressScrubber.slider('enable', true)
catch e
#console.warn('error enabling scrubber')
@timePopup.enable()
@timePopup?.enable()
onSetPlaying: (e) ->
@playing = (e ? {}).playing ? true
@ -242,21 +242,21 @@ module.exports = class PlaybackView extends View
@lastProgress = e.progress
onProgressEnter: (e) ->
#Why it needs itself as parameter you ask? Ask Twitter instead..
@timePopup.enter @timePopup
# Why it needs itself as parameter you ask? Ask Twitter instead.
@timePopup?.enter @timePopup
onProgressLeave: (e) ->
@timePopup.leave @timePopup
@timePopup?.leave @timePopup
onProgressHover: (e) ->
timeRatio = @$progressScrubber.width() / @totalTime
@newTime = e.offsetX / timeRatio
@updatePopupContent()
@timePopup.onHover e
@timePopup?.onHover e
#Show it instantaniously if close enough to current time.
if Math.abs(@currentTime - @newTime) < 1 and not @timePopup.shown
@timePopup.show() unless @timePopup.shown
# Show it instantaneously if close enough to current time.
if @timePopup and Math.abs(@currentTime - @newTime) < 1 and not @timePopup.shown
@timePopup.show()
updateProgress: (progress) ->
$('.scrubber .progress-bar', @$el).css('width', "#{progress*100}%")