Add opening/closing sounds to HintsView

This commit is contained in:
Imperadeiro98 2016-09-07 14:13:29 +01:00
parent d223143557
commit 5922f0947b

View file

@ -24,7 +24,7 @@ module.exports = class HintsView extends CocoView
hintsUsed: {} hintsUsed: {}
}) })
@updateHint() @updateHint()
debouncedRender = _.debounce(@render) debouncedRender = _.debounce(@render)
@listenTo(@state, 'change', debouncedRender) @listenTo(@state, 'change', debouncedRender)
@listenTo(@hintsState, 'change', debouncedRender) @listenTo(@hintsState, 'change', debouncedRender)
@ -38,6 +38,7 @@ module.exports = class HintsView extends CocoView
afterRender: -> afterRender: ->
@$el.toggleClass('hide', @hintsState.get('hidden')) @$el.toggleClass('hide', @hintsState.get('hidden'))
super() super()
@playSound 'game-menu-open'
getProcessedHint: -> getProcessedHint: ->
language = @session.get('codeLanguage') language = @session.get('codeLanguage')
@ -48,9 +49,9 @@ module.exports = class HintsView extends CocoView
translated = utils.i18n(hint, 'body') translated = utils.i18n(hint, 'body')
filtered = utils.filterMarkdownCodeLanguages(translated, language) filtered = utils.filterMarkdownCodeLanguages(translated, language)
markedUp = marked(filtered) markedUp = marked(filtered)
return markedUp return markedUp
updateHint: -> updateHint: ->
index = @state.get('hintIndex') index = @state.get('hintIndex')
hintsTitle = $.i18n.t('play_level.hints_title').replace('{{number}}', index + 1) hintsTitle = $.i18n.t('play_level.hints_title').replace('{{number}}', index + 1)
@ -69,7 +70,9 @@ module.exports = class HintsView extends CocoView
@playSound 'menu-button-click' @playSound 'menu-button-click'
@updateHintTimer() @updateHintTimer()
hideView: -> @hintsState?.set('hidden', true) hideView: ->
@hintsState?.set('hidden', true)
@playSound 'game-menu-close'
visibilityChanged: (e) -> visibilityChanged: (e) ->
@updateHintTimer() @updateHintTimer()
@ -85,10 +88,9 @@ module.exports = class HintsView extends CocoView
hintsViewTime[hintIndex] ?= 0 hintsViewTime[hintIndex] ?= 0
hintsViewTime[hintIndex]++ hintsViewTime[hintIndex]++
hintsUsed = @state.get('hintsUsed') hintsUsed = @state.get('hintsUsed')
if hintsViewTime[hintIndex] > @hintUsedThresholdSeconds and not hintsUsed[hintIndex] if hintsViewTime[hintIndex] > @hintUsedThresholdSeconds and not hintsUsed[hintIndex]
window.tracker?.trackEvent 'Hint Used', category: 'Students', levelSlug: @level.get('slug'), hintCount: @hintsState.get('hints')?.length ? 0, hintCurrent: hintIndex, ['Mixpanel'] window.tracker?.trackEvent 'Hint Used', category: 'Students', levelSlug: @level.get('slug'), hintCount: @hintsState.get('hints')?.length ? 0, hintCurrent: hintIndex, ['Mixpanel']
hintsUsed[hintIndex] = true hintsUsed[hintIndex] = true
@state.set('hintsUsed', hintsUsed) @state.set('hintsUsed', hintsUsed)
clearInterval(@timerIntervalID) clearInterval(@timerIntervalID)
@state.set('hintsViewTime', hintsViewTime) @state.set('hintsViewTime', hintsViewTime)