2014-11-28 20:49:41 -05:00
|
|
|
CocoView = require 'views/core/CocoView'
|
2014-12-15 18:11:27 -05:00
|
|
|
GameMenuModal = require 'views/play/menu/GameMenuModal'
|
2014-01-03 13:32:13 -05:00
|
|
|
template = require 'templates/play/level/tome/problem_alert'
|
2014-11-28 20:49:41 -05:00
|
|
|
{me} = require 'core/auth'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2014-07-17 20:20:11 -04:00
|
|
|
module.exports = class ProblemAlertView extends CocoView
|
2014-11-07 00:43:39 -05:00
|
|
|
id: 'problem-alert-view'
|
2014-01-03 13:32:13 -05:00
|
|
|
className: 'problem-alert'
|
|
|
|
template: template
|
|
|
|
|
2014-11-07 00:43:39 -05:00
|
|
|
subscriptions:
|
|
|
|
'tome:show-problem-alert': 'onShowProblemAlert'
|
2014-11-09 14:36:17 -05:00
|
|
|
'tome:hide-problem-alert': 'onHideProblemAlert'
|
2014-11-18 12:36:01 -05:00
|
|
|
'level:restart': 'onHideProblemAlert'
|
2014-11-08 01:46:12 -05:00
|
|
|
'tome:jiggle-problem-alert': 'onJiggleProblemAlert'
|
2014-11-07 00:43:39 -05:00
|
|
|
'tome:manual-cast': 'onHideProblemAlert'
|
|
|
|
'real-time-multiplayer:manual-cast': 'onHideProblemAlert'
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
events:
|
2014-06-30 22:16:26 -04:00
|
|
|
'click .close': 'onRemoveClicked'
|
2015-11-30 17:18:42 -05:00
|
|
|
'click': -> Backbone.Mediator.publish 'tome:focus-editor', {}
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2014-12-15 18:11:27 -05:00
|
|
|
@level = options.level
|
|
|
|
@session = options.session
|
|
|
|
@supermodel = options.supermodel
|
2014-11-07 00:43:39 -05:00
|
|
|
if options.problem?
|
2014-11-08 14:59:39 -05:00
|
|
|
@problem = options.problem
|
2014-11-07 00:43:39 -05:00
|
|
|
@onWindowResize()
|
|
|
|
else
|
|
|
|
@$el.hide()
|
|
|
|
$(window).on 'resize', @onWindowResize
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
$(window).off 'resize', @onWindowResize
|
|
|
|
super()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
2016-02-02 23:17:52 -05:00
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
if @problem?
|
|
|
|
@$el.addClass('alert').addClass("alert-#{@problem.aetherProblem.level}").hide().fadeIn('slow')
|
|
|
|
@$el.addClass('no-hint') unless @problem.aetherProblem.hint
|
|
|
|
@playSound 'error_appear'
|
|
|
|
|
|
|
|
setProblemMessage: ->
|
2014-11-07 00:43:39 -05:00
|
|
|
if @problem?
|
2014-11-19 18:27:06 -05:00
|
|
|
format = (s) -> marked(s.replace(/</g, '<').replace(/>/g, '>')) if s?
|
2014-11-19 20:12:57 -05:00
|
|
|
message = @problem.aetherProblem.message
|
|
|
|
# Add time to problem message if hint is for a missing null check
|
|
|
|
# NOTE: This may need to be updated with Aether error hint changes
|
|
|
|
if @problem.aetherProblem.hint? and /(?:null|undefined)/.test @problem.aetherProblem.hint
|
|
|
|
age = @problem.aetherProblem.userInfo?.age
|
|
|
|
if age?
|
|
|
|
if /^Line \d+:/.test message
|
|
|
|
message = message.replace /^(Line \d+)/, "$1, time #{age.toFixed(1)}"
|
|
|
|
else
|
|
|
|
message = "Time #{age.toFixed(1)}: #{message}"
|
2016-02-02 23:17:52 -05:00
|
|
|
@message = format message
|
|
|
|
@hint = format @problem.aetherProblem.hint
|
2014-11-07 00:43:39 -05:00
|
|
|
|
|
|
|
onShowProblemAlert: (data) ->
|
|
|
|
return unless $('#code-area').is(":visible")
|
2014-11-09 00:51:54 -05:00
|
|
|
if @problem?
|
|
|
|
if @$el.hasClass "alert-#{@problem.aetherProblem.level}"
|
|
|
|
@$el.removeClass "alert-#{@problem.aetherProblem.level}"
|
|
|
|
if @$el.hasClass "no-hint"
|
|
|
|
@$el.removeClass "no-hint"
|
2014-11-07 00:43:39 -05:00
|
|
|
@problem = data.problem
|
|
|
|
@lineOffsetPx = data.lineOffsetPx or 0
|
|
|
|
@$el.show()
|
|
|
|
@onWindowResize()
|
2016-02-02 23:17:52 -05:00
|
|
|
@setProblemMessage()
|
2014-11-07 00:43:39 -05:00
|
|
|
@render()
|
2014-11-08 01:46:12 -05:00
|
|
|
@onJiggleProblemAlert()
|
2015-01-15 14:04:48 -05:00
|
|
|
application.tracker?.trackEvent 'Show problem alert', {levelID: @level.get('slug'), ls: @session?.get('_id')}
|
2014-11-08 01:46:12 -05:00
|
|
|
|
|
|
|
onJiggleProblemAlert: ->
|
2014-11-09 00:51:54 -05:00
|
|
|
return unless @problem?
|
|
|
|
@$el.show() unless @$el.is(":visible")
|
|
|
|
@$el.addClass 'jiggling'
|
2015-09-09 17:36:05 -04:00
|
|
|
@playSound 'error_appear'
|
2014-11-09 00:51:54 -05:00
|
|
|
pauseJiggle = =>
|
|
|
|
@$el?.removeClass 'jiggling'
|
2014-11-24 00:58:27 -05:00
|
|
|
_.delay pauseJiggle, 1000
|
2014-11-07 00:43:39 -05:00
|
|
|
|
|
|
|
onHideProblemAlert: ->
|
2014-12-09 17:00:48 -05:00
|
|
|
return unless @$el.is(':visible')
|
2014-11-07 00:43:39 -05:00
|
|
|
@onRemoveClicked()
|
2014-01-03 13:32:13 -05:00
|
|
|
|
|
|
|
onRemoveClicked: ->
|
2014-11-26 09:58:23 -05:00
|
|
|
@playSound 'menu-button-click'
|
2014-11-07 00:43:39 -05:00
|
|
|
@$el.hide()
|
2015-11-30 17:18:42 -05:00
|
|
|
Backbone.Mediator.publish 'tome:focus-editor', {}
|
2014-11-07 00:43:39 -05:00
|
|
|
|
2014-11-08 14:59:39 -05:00
|
|
|
onWindowResize: (e) =>
|
2014-11-07 00:43:39 -05:00
|
|
|
# TODO: This all seems a little hacky
|
|
|
|
if @problem?
|
2014-11-23 01:48:00 -05:00
|
|
|
levelContentWidth = $('.level-content').outerWidth(true)
|
|
|
|
goalsViewWidth = $('#goals-view').outerWidth(true)
|
|
|
|
codeAreaWidth = $('#code-area').outerWidth(true)
|
|
|
|
# problem alert view has 20px padding
|
|
|
|
@$el.css('max-width', levelContentWidth - codeAreaWidth - goalsViewWidth + 40 + 'px')
|
|
|
|
@$el.css('right', codeAreaWidth + 'px')
|
2014-11-07 00:43:39 -05:00
|
|
|
|
2014-11-08 14:59:39 -05:00
|
|
|
# 110px from top roughly aligns top of alert with top of first code line
|
2014-11-07 00:43:39 -05:00
|
|
|
# TODO: calculate this in a more dynamic, less sketchy way
|
2014-11-08 14:59:39 -05:00
|
|
|
@$el.css('top', (110 + @lineOffsetPx) + 'px')
|