codecombat/app/views/play/level/LevelLoadingView.coffee

56 lines
2.1 KiB
CoffeeScript
Raw Normal View History

2014-07-17 20:20:11 -04:00
CocoView = require 'views/kinds/CocoView'
2014-03-14 20:06:08 -04:00
template = require 'templates/play/level/level_loading'
2014-07-17 20:20:11 -04:00
module.exports = class LevelLoadingView extends CocoView
2014-06-30 22:16:26 -04:00
id: 'level-loading-view'
2014-03-14 20:06:08 -04:00
template: template
events:
2014-09-21 18:52:49 -04:00
'mousedown .start-level-button': 'startUnveiling' # split into two for animation smoothness
'click .start-level-button': 'onClickStartLevel'
2014-09-21 18:52:49 -04:00
subscriptions:
'level:loaded': 'onLevelLoaded'
afterRender: ->
2014-03-17 03:12:11 -04:00
@$el.find('.tip.rare').remove() if _.random(1, 10) < 9
tips = @$el.find('.tip').addClass('to-remove')
tip = _.sample(tips)
2014-03-17 03:12:11 -04:00
$(tip).removeClass('to-remove')
@$el.find('.to-remove').remove()
2014-03-14 20:06:08 -04:00
2014-09-21 18:52:49 -04:00
onLevelLoaded: (e) ->
@level = e.level
goalList = @$el.find('.level-loading-goals').removeClass('secret').find('ul')
for goalID, goal of @level.get('goals') when not goal.team or goal.team is e.team
goalList.append $('<li class="list-group-item header-font">' + goal.name + '</li>')
console.log 'got goals', @level.get('goals'), 'team', e.team
2014-03-14 20:06:08 -04:00
showReady: ->
return if @shownReady
@shownReady = true
ready = $.i18n.t('play_level.loading_ready', defaultValue: 'Ready!')
@$el.find('#tip-wrapper .tip').addClass('ready').text ready
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'level_loaded', volume: 0.75 # old: loading_ready
@$el.find('.start-level-button').removeClass 'secret'
2014-03-14 20:06:08 -04:00
2014-09-21 18:52:49 -04:00
startUnveiling: (e) ->
Backbone.Mediator.publish 'level:loading-view-unveiling', {}
onClickStartLevel: (e) ->
@unveil()
2014-03-14 20:06:08 -04:00
unveil: ->
2014-04-09 12:04:59 -04:00
@$el.addClass 'unveiled'
2014-03-14 20:06:08 -04:00
loadingDetails = @$el.find('.loading-details')
duration = parseFloat loadingDetails.css 'transition-duration'
loadingDetails.css 'top', -loadingDetails.outerHeight(true)
2014-03-14 22:44:19 -04:00
@$el.find('.left-wing').css left: '-100%', backgroundPosition: 'right -400px top 0'
@$el.find('.right-wing').css right: '-100%', backgroundPosition: 'left -400px top 0'
2014-09-11 11:38:30 -04:00
Backbone.Mediator.publish 'audio-player:play-sound', trigger: 'loading-view-unveil', volume: 0.5
2014-03-14 20:06:08 -04:00
_.delay @onUnveilEnded, duration * 1000
onUnveilEnded: =>
return if @destroyed
Backbone.Mediator.publish 'level:loading-view-unveiled', view: @