2014-12-19 13:04:04 -05:00
|
|
|
RootView = require 'views/core/RootView'
|
2014-12-19 13:06:20 -05:00
|
|
|
template = require 'templates/play/campaign-view'
|
2014-12-19 13:04:04 -05:00
|
|
|
LevelSession = require 'models/LevelSession'
|
|
|
|
EarnedAchievement = require 'models/EarnedAchievement'
|
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
2014-12-19 16:46:01 -05:00
|
|
|
Campaign = require 'models/Campaign'
|
2014-12-19 13:04:04 -05:00
|
|
|
AudioPlayer = require 'lib/AudioPlayer'
|
|
|
|
LevelSetupManager = require 'lib/LevelSetupManager'
|
|
|
|
ThangType = require 'models/ThangType'
|
|
|
|
MusicPlayer = require 'lib/surface/MusicPlayer'
|
|
|
|
storage = require 'core/storage'
|
2016-02-25 18:24:16 -05:00
|
|
|
CreateAccountModal = require 'views/core/CreateAccountModal'
|
2014-12-19 13:04:04 -05:00
|
|
|
SubscribeModal = require 'views/core/SubscribeModal'
|
2015-01-30 15:27:19 -05:00
|
|
|
LeaderboardModal = require 'views/play/modal/LeaderboardModal'
|
2014-12-19 13:04:04 -05:00
|
|
|
Level = require 'models/Level'
|
2014-12-22 10:29:29 -05:00
|
|
|
utils = require 'core/utils'
|
2015-01-29 19:11:13 -05:00
|
|
|
require 'vendor/three'
|
|
|
|
ParticleMan = require 'core/ParticleMan'
|
2015-02-06 17:49:47 -05:00
|
|
|
ShareProgressModal = require 'views/play/modal/ShareProgressModal'
|
2015-03-07 19:30:25 -05:00
|
|
|
UserPollsRecord = require 'models/UserPollsRecord'
|
|
|
|
Poll = require 'models/Poll'
|
|
|
|
PollModal = require 'views/play/modal/PollModal'
|
2015-12-01 14:24:16 -05:00
|
|
|
CourseInstance = require 'models/CourseInstance'
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
trackedHourOfCode = false
|
|
|
|
|
|
|
|
class LevelSessionsCollection extends CocoCollection
|
|
|
|
url: ''
|
|
|
|
model: LevelSession
|
|
|
|
|
|
|
|
constructor: (model) ->
|
|
|
|
super()
|
2015-08-07 10:33:30 -04:00
|
|
|
@url = "/db/user/#{me.id}/level.sessions?project=state.complete,levelID,state.difficulty,playtime"
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
class CampaignsCollection extends CocoCollection
|
2015-11-19 16:20:42 -05:00
|
|
|
# We don't send all of levels, just the parts needed in countLevels
|
|
|
|
url: '/db/campaign/-/overworld?project=slug,adjacentCampaigns,name,fullName,description,i18n,color,levels'
|
2015-02-05 18:05:22 -05:00
|
|
|
model: Campaign
|
|
|
|
|
2014-12-28 16:25:20 -05:00
|
|
|
module.exports = class CampaignView extends RootView
|
2014-12-19 13:06:20 -05:00
|
|
|
id: 'campaign-view'
|
2014-12-19 13:04:04 -05:00
|
|
|
template: template
|
|
|
|
|
|
|
|
subscriptions:
|
|
|
|
'subscribe-modal:subscribed': 'onSubscribed'
|
|
|
|
|
|
|
|
events:
|
|
|
|
'click .map-background': 'onClickMap'
|
|
|
|
'click .level a': 'onClickLevel'
|
2014-12-29 15:46:14 -05:00
|
|
|
'dblclick .level a': 'onDoubleClickLevel'
|
2014-12-19 13:04:04 -05:00
|
|
|
'click .level-info-container .start-level': 'onClickStartLevel'
|
2015-02-03 21:25:38 -05:00
|
|
|
'click .level-info-container .view-solutions': 'onClickViewSolutions'
|
2015-12-01 14:24:16 -05:00
|
|
|
'click .level-info-container .course-version button': 'onClickCourseVersion'
|
2014-12-19 13:04:04 -05:00
|
|
|
'click #volume-button': 'onToggleVolume'
|
2015-02-05 18:40:33 -05:00
|
|
|
'click #back-button': 'onClickBack'
|
2015-02-25 14:09:11 -05:00
|
|
|
'click #clear-storage-button': 'onClickClearStorage'
|
2015-02-05 18:05:22 -05:00
|
|
|
'click .portal .campaign': 'onClickPortalCampaign'
|
|
|
|
'mouseenter .portals': 'onMouseEnterPortals'
|
|
|
|
'mouseleave .portals': 'onMouseLeavePortals'
|
|
|
|
'mousemove .portals': 'onMouseMovePortals'
|
2015-03-07 19:30:25 -05:00
|
|
|
'click .poll': 'showPoll'
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
constructor: (options, @terrain) ->
|
2014-12-19 13:04:04 -05:00
|
|
|
super options
|
2016-02-16 23:39:59 -05:00
|
|
|
@terrain = 'picoctf' if window.serverConfig.picoCTF
|
2015-02-05 18:05:22 -05:00
|
|
|
@editorMode = options?.editorMode
|
|
|
|
if @editorMode
|
|
|
|
@terrain ?= 'dungeon'
|
2014-12-19 13:04:04 -05:00
|
|
|
@levelStatusMap = {}
|
|
|
|
@levelPlayCountMap = {}
|
2015-04-13 20:07:13 -04:00
|
|
|
@levelDifficultyMap = {}
|
2016-02-16 23:39:59 -05:00
|
|
|
if window.serverConfig.picoCTF
|
2016-02-17 14:33:50 -05:00
|
|
|
@supermodel.addRequestResource(url: '/picoctf/problems', success: (@picoCTFProblems) =>).load()
|
2016-02-16 23:39:59 -05:00
|
|
|
else
|
|
|
|
@sessions = @supermodel.loadCollection(new LevelSessionsCollection(), 'your_sessions', {cache: false}, 0).model
|
|
|
|
@listenToOnce @sessions, 'sync', @onSessionsLoaded
|
|
|
|
unless @terrain
|
|
|
|
@campaigns = @supermodel.loadCollection(new CampaignsCollection(), 'campaigns', null, 1).model
|
|
|
|
@listenToOnce @campaigns, 'sync', @onCampaignsLoaded
|
|
|
|
return
|
2015-02-05 18:05:22 -05:00
|
|
|
|
|
|
|
@campaign = new Campaign({_id:@terrain})
|
2016-02-18 11:44:40 -05:00
|
|
|
@campaign = @supermodel.loadModel(@campaign).model
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
# Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution...
|
|
|
|
@earnedAchievements = new CocoCollection([], {url: '/db/earned_achievement', model:EarnedAchievement, project: ['earnedRewards']})
|
|
|
|
@listenToOnce @earnedAchievements, 'sync', ->
|
|
|
|
earned = me.get('earned')
|
|
|
|
for m in @earnedAchievements.models
|
|
|
|
continue unless loadedEarned = m.get('earnedRewards')
|
|
|
|
for group in ['heroes', 'levels', 'items']
|
|
|
|
continue unless loadedEarned[group]
|
|
|
|
for reward in loadedEarned[group]
|
|
|
|
if reward not in earned[group]
|
|
|
|
console.warn 'Filling in a gap for reward', group, reward
|
|
|
|
earned[group].push(reward)
|
2014-12-19 16:46:01 -05:00
|
|
|
|
2015-02-11 16:12:42 -05:00
|
|
|
@supermodel.loadCollection(@earnedAchievements, 'achievements', {cache: false})
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2014-12-28 16:25:20 -05:00
|
|
|
@listenToOnce @campaign, 'sync', @getLevelPlayCounts
|
2014-12-19 13:04:04 -05:00
|
|
|
$(window).on 'resize', @onWindowResize
|
|
|
|
@probablyCachedMusic = storage.load("loaded-menu-music")
|
|
|
|
musicDelay = if @probablyCachedMusic then 1000 else 10000
|
|
|
|
@playMusicTimeout = _.delay (=> @playMusic() unless @destroyed), musicDelay
|
|
|
|
@hadEverChosenHero = me.get('heroConfig')?.thangType
|
|
|
|
@listenTo me, 'change:purchased', -> @renderSelectors('#gems-count')
|
|
|
|
@listenTo me, 'change:spent', -> @renderSelectors('#gems-count')
|
2015-03-07 19:30:25 -05:00
|
|
|
@listenTo me, 'change:earned', -> @renderSelectors('#gems-count')
|
2014-12-19 13:04:04 -05:00
|
|
|
@listenTo me, 'change:heroConfig', -> @updateHero()
|
2015-02-27 19:07:41 -05:00
|
|
|
window.tracker?.trackEvent 'Loaded World Map', category: 'World Map', label: @terrain
|
2014-12-19 13:04:04 -05:00
|
|
|
@requiresSubscription = not me.isPremium()
|
|
|
|
|
|
|
|
destroy: ->
|
|
|
|
@setupManager?.destroy()
|
2015-02-04 16:24:15 -05:00
|
|
|
@$el.find('.ui-draggable').off().draggable 'destroy'
|
2014-12-19 13:04:04 -05:00
|
|
|
$(window).off 'resize', @onWindowResize
|
|
|
|
if ambientSound = @ambientSound
|
|
|
|
# Doesn't seem to work; stops immediately.
|
|
|
|
createjs.Tween.get(ambientSound).to({volume: 0.0}, 1500).call -> ambientSound.stop()
|
|
|
|
@musicPlayer?.destroy()
|
|
|
|
clearTimeout @playMusicTimeout
|
2015-02-02 21:02:57 -05:00
|
|
|
@particleMan?.destroy()
|
2015-02-05 18:05:22 -05:00
|
|
|
clearInterval @portalScrollInterval
|
2014-12-19 13:04:04 -05:00
|
|
|
super()
|
|
|
|
|
2015-11-14 20:30:37 -05:00
|
|
|
showLoading: ($el) ->
|
|
|
|
unless @campaign
|
|
|
|
@$el.find('.game-controls, .user-status').addClass 'hidden'
|
|
|
|
@$el.find('.portal .campaign-name span').text $.i18n.t 'common.loading'
|
|
|
|
|
|
|
|
hideLoading: ->
|
|
|
|
unless @campaign
|
|
|
|
@$el.find('.game-controls, .user-status').removeClass 'hidden'
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
getLevelPlayCounts: ->
|
|
|
|
return unless me.isAdmin()
|
2015-02-03 21:25:38 -05:00
|
|
|
return # TODO: get rid of all this? It's redundant with new campaign editor analytics, unless we want to show player counts on leaderboards buttons.
|
2014-12-19 13:04:04 -05:00
|
|
|
success = (levelPlayCounts) =>
|
|
|
|
return if @destroyed
|
|
|
|
for level in levelPlayCounts
|
|
|
|
@levelPlayCountMap[level._id] = playtime: level.playtime, sessions: level.sessions
|
|
|
|
@render() if @fullyRendered
|
|
|
|
|
2014-12-28 16:25:20 -05:00
|
|
|
levelSlugs = (level.slug for levelID, level of @campaign.get 'levels')
|
2014-12-19 13:04:04 -05:00
|
|
|
levelPlayCountsRequest = @supermodel.addRequestResource 'play_counts', {
|
|
|
|
url: '/db/level/-/play_counts'
|
2014-12-28 16:25:20 -05:00
|
|
|
data: {ids: levelSlugs}
|
2014-12-19 13:04:04 -05:00
|
|
|
method: 'POST'
|
|
|
|
success: success
|
|
|
|
}, 0
|
|
|
|
levelPlayCountsRequest.load()
|
|
|
|
|
|
|
|
onLoaded: ->
|
|
|
|
return if @fullyRendered
|
|
|
|
@fullyRendered = true
|
|
|
|
@render()
|
|
|
|
@preloadTopHeroes() unless me.get('heroConfig')?.thangType
|
2015-02-04 16:00:07 -05:00
|
|
|
@$el.find('#campaign-status').delay(4000).animate({top: "-=58"}, 1000) unless @terrain is 'dungeon'
|
2015-04-08 21:31:13 -04:00
|
|
|
if @terrain and me.get('anonymous') and me.get('lastLevel') is 'shadow-guard' and me.level() < 4
|
2016-02-25 18:24:16 -05:00
|
|
|
@openModalView new CreateAccountModal supermodel: @supermodel, showSignupRationale: true
|
2015-04-09 00:48:21 -04:00
|
|
|
else if @terrain and me.get('name') and me.get('lastLevel') in ['forgetful-gemsmith', 'signs-and-portents'] and me.level() < 5 and not (me.get('ageRange') in ['18-24', '25-34', '35-44', '45-100']) and not storage.load('sent-parent-email') and not me.isPremium()
|
2015-02-06 22:49:13 -05:00
|
|
|
@openModalView new ShareProgressModal()
|
2015-02-06 17:49:47 -05:00
|
|
|
|
2014-12-22 12:06:17 -05:00
|
|
|
setCampaign: (@campaign) ->
|
|
|
|
@render()
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
onSubscribed: ->
|
|
|
|
@requiresSubscription = false
|
|
|
|
@render()
|
|
|
|
|
|
|
|
getRenderData: (context={}) ->
|
|
|
|
context = super(context)
|
2014-12-19 16:46:01 -05:00
|
|
|
context.campaign = @campaign
|
2015-02-05 18:05:22 -05:00
|
|
|
context.levels = _.values($.extend true, {}, @campaign?.get('levels') ? {})
|
2015-02-26 17:24:00 -05:00
|
|
|
if me.level() < 12 and @terrain is 'dungeon' and not @editorMode
|
|
|
|
reject = if me.getFourthLevelGroup() is 'signs-and-portents' then 'forgetful-gemsmith' else 'signs-and-portents'
|
|
|
|
context.levels = _.reject context.levels, slug: reject
|
2015-02-05 18:05:22 -05:00
|
|
|
@annotateLevel level for level in context.levels
|
|
|
|
count = @countLevels context.levels
|
|
|
|
context.levelsCompleted = count.completed
|
|
|
|
context.levelsTotal = count.total
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
@determineNextLevel context.levels if @sessions?.loaded
|
2014-12-19 16:46:01 -05:00
|
|
|
# put lower levels in last, so in the world map they layer over one another properly.
|
2015-01-13 12:04:09 -05:00
|
|
|
context.levels = (_.sortBy context.levels, (l) -> l.position.y).reverse()
|
2015-02-05 18:05:22 -05:00
|
|
|
@campaign.renderedLevels = context.levels if @campaign
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
context.levelStatusMap = @levelStatusMap
|
2015-04-13 20:07:13 -04:00
|
|
|
context.levelDifficultyMap = @levelDifficultyMap
|
2014-12-19 13:04:04 -05:00
|
|
|
context.levelPlayCountMap = @levelPlayCountMap
|
|
|
|
context.isIPadApp = application.isIPadApp
|
2016-02-16 23:39:59 -05:00
|
|
|
context.picoCTF = window.serverConfig.picoCTF
|
2014-12-19 13:04:04 -05:00
|
|
|
context.requiresSubscription = @requiresSubscription
|
|
|
|
context.editorMode = @editorMode
|
2015-02-05 18:05:22 -05:00
|
|
|
context.adjacentCampaigns = _.filter _.values(_.cloneDeep(@campaign?.get('adjacentCampaigns') or {})), (ac) =>
|
2015-01-13 12:04:09 -05:00
|
|
|
return false if ac.showIfUnlocked and (ac.showIfUnlocked not in me.levels()) and not @editorMode
|
2014-12-22 10:29:29 -05:00
|
|
|
ac.name = utils.i18n ac, 'name'
|
|
|
|
styles = []
|
|
|
|
styles.push "color: #{ac.color}" if ac.color
|
|
|
|
styles.push "transform: rotate(#{ac.rotation}deg)" if ac.rotation
|
|
|
|
ac.position ?= { x: 10, y: 10 }
|
|
|
|
styles.push "left: #{ac.position.x}%"
|
|
|
|
styles.push "top: #{ac.position.y}%"
|
|
|
|
ac.style = styles.join('; ')
|
|
|
|
return true
|
2015-01-22 14:22:35 -05:00
|
|
|
context.marked = marked
|
|
|
|
context.i18n = utils.i18n
|
2015-02-05 18:05:22 -05:00
|
|
|
|
|
|
|
if @campaigns
|
|
|
|
context.campaigns = {}
|
2015-04-07 17:32:51 -04:00
|
|
|
for campaign in @campaigns.models when campaign.get('slug') isnt 'auditions'
|
2015-02-05 18:05:22 -05:00
|
|
|
context.campaigns[campaign.get('slug')] = campaign
|
|
|
|
if @sessions.loaded
|
|
|
|
levels = _.values($.extend true, {}, campaign.get('levels') ? {})
|
|
|
|
count = @countLevels levels
|
|
|
|
campaign.levelsTotal = count.total
|
|
|
|
campaign.levelsCompleted = count.completed
|
|
|
|
if campaign.get('slug') is 'dungeon'
|
|
|
|
campaign.locked = false
|
|
|
|
else unless campaign.levelsTotal
|
|
|
|
campaign.locked = true
|
|
|
|
else
|
|
|
|
campaign.locked = true
|
|
|
|
for campaign in @campaigns.models
|
|
|
|
for acID, ac of campaign.get('adjacentCampaigns') ? {}
|
|
|
|
_.find(@campaigns.models, id: acID)?.locked = false if ac.showIfUnlocked in me.levels()
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
context
|
|
|
|
|
|
|
|
afterRender: ->
|
|
|
|
super()
|
|
|
|
@onWindowResize()
|
|
|
|
unless application.isIPadApp
|
2015-03-07 19:30:25 -05:00
|
|
|
_.defer => @$el?.find('.game-controls .btn:not(.poll)').addClass('has-tooltip').tooltip() # Have to defer or i18n doesn't take effect.
|
2014-12-22 10:54:07 -05:00
|
|
|
view = @
|
2015-02-02 21:02:57 -05:00
|
|
|
@$el.find('.level, .campaign-switch').addClass('has-tooltip').tooltip().each ->
|
2015-02-04 16:24:15 -05:00
|
|
|
return unless me.isAdmin() and view.editorMode
|
2014-12-19 13:04:04 -05:00
|
|
|
$(@).draggable().on 'dragstop', ->
|
|
|
|
bg = $('.map-background')
|
|
|
|
x = ($(@).offset().left - bg.offset().left + $(@).outerWidth() / 2) / bg.width()
|
|
|
|
y = 1 - ($(@).offset().top - bg.offset().top + $(@).outerHeight() / 2) / bg.height()
|
2014-12-29 11:45:55 -05:00
|
|
|
e = { position: { x: (100 * x), y: (100 * y) }, levelOriginal: $(@).data('level-original'), campaignID: $(@).data('campaign-id') }
|
2014-12-22 10:54:07 -05:00
|
|
|
view.trigger 'level-moved', e if e.levelOriginal
|
|
|
|
view.trigger 'adjacent-campaign-moved', e if e.campaignID
|
2014-12-19 13:04:04 -05:00
|
|
|
@updateVolume()
|
|
|
|
@updateHero()
|
|
|
|
unless window.currentModal or not @fullyRendered
|
|
|
|
@highlightElement '.level.next', delay: 500, duration: 60000, rotation: 0, sides: ['top']
|
2015-01-13 12:04:09 -05:00
|
|
|
if @editorMode
|
2015-02-05 18:05:22 -05:00
|
|
|
for level in @campaign?.renderedLevels ? []
|
2015-01-15 12:07:47 -05:00
|
|
|
for nextLevelOriginal in level.nextLevels ? []
|
2015-01-13 12:04:09 -05:00
|
|
|
if nextLevel = _.find(@campaign.renderedLevels, original: nextLevelOriginal)
|
|
|
|
@createLine level.position, nextLevel.position
|
2015-02-03 20:07:15 -05:00
|
|
|
@showLeaderboard @options.justBeatLevel?.get('slug') if @options.showLeaderboard# or true # Testing
|
2014-12-28 16:25:20 -05:00
|
|
|
@applyCampaignStyles()
|
2015-01-29 19:11:13 -05:00
|
|
|
@testParticles()
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
afterInsert: ->
|
|
|
|
super()
|
|
|
|
return unless @getQueryVariable 'signup'
|
|
|
|
return if me.get('email')
|
|
|
|
@endHighlight()
|
2016-02-25 18:24:16 -05:00
|
|
|
authModal = new CreateAccountModal supermodel: @supermodel
|
2014-12-19 13:04:04 -05:00
|
|
|
authModal.mode = 'signup'
|
|
|
|
@openModalView authModal
|
|
|
|
|
2016-03-15 18:51:59 -04:00
|
|
|
showAds: ->
|
2016-06-09 15:13:17 -04:00
|
|
|
return false # No ads for now.
|
2016-03-15 18:51:59 -04:00
|
|
|
if application.isProduction() && !me.isPremium() && !me.isTeacher() && !window.serverConfig.picoCTF
|
|
|
|
return me.getCampaignAdsGroup() is 'leaderboard-ads'
|
|
|
|
false
|
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
annotateLevel: (level) ->
|
|
|
|
level.position ?= { x: 10, y: 10 }
|
|
|
|
level.locked = not me.ownsLevel level.original
|
2015-08-07 10:33:30 -04:00
|
|
|
level.locked = true if level.slug is 'kithgard-mastery' and @calculateExperienceScore() is 0
|
2015-02-05 18:05:22 -05:00
|
|
|
level.locked = false if @levelStatusMap[level.slug] in ['started', 'complete']
|
|
|
|
level.locked = false if @editorMode
|
2016-02-16 23:39:59 -05:00
|
|
|
level.locked = false if @campaign?.get('name') in ['Auditions', 'Intro']
|
2015-02-12 14:42:05 -05:00
|
|
|
level.locked = false if me.isInGodMode()
|
2015-09-12 09:54:14 -04:00
|
|
|
#level.locked = false if level.slug is 'robot-ragnarok'
|
2016-03-04 14:44:36 -05:00
|
|
|
level.disabled = true if level.adminOnly and @levelStatusMap[level.slug] not in ['started', 'complete']
|
|
|
|
level.disabled = false if me.isInGodMode()
|
|
|
|
level.color = 'rgb(255, 80, 60)'
|
|
|
|
if level.requiresSubscription
|
|
|
|
level.color = 'rgb(80, 130, 200)'
|
|
|
|
if unlocksHero = _.find(level.rewards, 'hero')?.hero
|
|
|
|
level.unlocksHero = unlocksHero
|
|
|
|
if level.unlocksHero
|
|
|
|
level.purchasedHero = level.unlocksHero in (me.get('purchased')?.heroes or [])
|
|
|
|
|
2016-02-16 23:39:59 -05:00
|
|
|
if window.serverConfig.picoCTF
|
|
|
|
if problem = _.find(@picoCTFProblems or [], pid: level.picoCTFProblem)
|
2016-03-03 20:18:17 -05:00
|
|
|
level.locked = false if problem.unlocked or level.slug is 'digital-graffiti'
|
|
|
|
#level.locked = false # Testing to see all levels
|
2016-02-16 23:39:59 -05:00
|
|
|
level.description = """
|
|
|
|
### #{problem.name}
|
2016-02-17 14:33:50 -05:00
|
|
|
#{level.description or problem.description}
|
2016-02-16 23:39:59 -05:00
|
|
|
|
|
|
|
#{problem.category} - #{problem.score} points
|
2016-03-03 20:18:17 -05:00
|
|
|
"""
|
2016-03-04 14:44:36 -05:00
|
|
|
level.color = 'rgb(80, 130, 200)' if problem.solved
|
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
level.hidden = level.locked
|
2015-07-21 13:28:13 -04:00
|
|
|
if level.concepts?.length
|
|
|
|
level.displayConcepts = level.concepts
|
|
|
|
maxConcepts = 6
|
|
|
|
if level.displayConcepts.length > maxConcepts
|
|
|
|
level.displayConcepts = level.displayConcepts.slice -maxConcepts
|
2015-02-05 18:05:22 -05:00
|
|
|
level
|
|
|
|
|
|
|
|
countLevels: (levels) ->
|
|
|
|
count = total: 0, completed: 0
|
2015-04-07 17:32:51 -04:00
|
|
|
for level, levelIndex in levels
|
2015-02-05 18:05:22 -05:00
|
|
|
@annotateLevel level unless level.locked? # Annotate if we haven't already.
|
|
|
|
unless level.disabled
|
2015-04-07 17:32:51 -04:00
|
|
|
unlockedInSameCampaign = levelIndex < 5 # First few are always counted (probably unlocked in previous campaign)
|
|
|
|
for otherLevel in levels when not unlockedInSameCampaign and otherLevel isnt level
|
|
|
|
for reward in (otherLevel.rewards ? []) when reward.level
|
|
|
|
unlockedInSameCampaign ||= reward.level is level.original
|
|
|
|
++count.total if unlockedInSameCampaign or not level.locked
|
2015-02-05 18:05:22 -05:00
|
|
|
++count.completed if @levelStatusMap[level.slug] is 'complete'
|
|
|
|
count
|
|
|
|
|
2015-01-31 00:36:36 -05:00
|
|
|
showLeaderboard: (levelSlug) ->
|
|
|
|
leaderboardModal = new LeaderboardModal supermodel: @supermodel, levelSlug: levelSlug
|
2015-01-30 15:27:19 -05:00
|
|
|
@openModalView leaderboardModal
|
|
|
|
|
2015-01-13 12:04:09 -05:00
|
|
|
determineNextLevel: (levels) ->
|
|
|
|
foundNext = false
|
2015-08-07 10:33:30 -04:00
|
|
|
dontPointTo = ['lost-viking', 'kithgard-mastery'] # Challenge levels we don't want most players bashing heads against
|
2015-09-18 11:28:04 -04:00
|
|
|
subscriptionPrompts = [{slug: 'boom-and-bust', unless: 'defense-of-plainswood'}]
|
2015-01-13 12:04:09 -05:00
|
|
|
for level in levels
|
2015-08-07 10:33:30 -04:00
|
|
|
# Iterate through all levels in order and look to find the first unlocked one that meets all our criteria for being pointed out as the next level.
|
2015-02-09 11:19:59 -05:00
|
|
|
level.nextLevels = (reward.level for reward in level.rewards ? [] when reward.level)
|
2015-01-13 12:04:09 -05:00
|
|
|
unless foundNext
|
|
|
|
for nextLevelOriginal in level.nextLevels
|
|
|
|
nextLevel = _.find levels, original: nextLevelOriginal
|
2015-08-07 10:33:30 -04:00
|
|
|
|
|
|
|
# If it's a challenge level, we efficiently determine whether we actually do want to point it out.
|
|
|
|
if nextLevel and nextLevel.slug is 'kithgard-mastery' and not nextLevel.locked and not @levelStatusMap[nextLevel.slug] and @calculateExperienceScore() >= 3
|
|
|
|
unless (timesPointedOut = storage.load("pointed-out-#{nextLevel.slug}") or 0) > 3
|
|
|
|
# We may determineNextLevel more than once per render, so we can't just do this once. But we do give up after a couple highlights.
|
|
|
|
dontPointTo = _.without dontPointTo, nextLevel.slug
|
|
|
|
storage.save "pointed-out-#{nextLevel.slug}", timesPointedOut + 1
|
|
|
|
|
|
|
|
# Should we point this level out?
|
2015-06-01 17:39:55 -04:00
|
|
|
if nextLevel and not nextLevel.locked and not nextLevel.disabled and @levelStatusMap[nextLevel.slug] isnt 'complete' and nextLevel.slug not in dontPointTo and not nextLevel.replayable and (
|
2015-09-18 11:28:04 -04:00
|
|
|
me.isPremium() or not nextLevel.requiresSubscription or
|
|
|
|
_.any(subscriptionPrompts, (prompt) => nextLevel.slug is prompt.slug and not @levelStatusMap[prompt.unless])
|
2015-04-08 19:23:51 -04:00
|
|
|
)
|
2015-01-13 12:04:09 -05:00
|
|
|
nextLevel.next = true
|
|
|
|
foundNext = true
|
|
|
|
break
|
|
|
|
if not foundNext and levels[0] and not levels[0].locked and @levelStatusMap[levels[0].slug] isnt 'complete'
|
|
|
|
levels[0].next = true
|
|
|
|
|
2015-08-07 10:33:30 -04:00
|
|
|
calculateExperienceScore: ->
|
|
|
|
adultPoint = me.get('ageRange') in ['18-24', '25-34', '35-44', '45-100'] # They have to have answered the poll for this, likely after Shadow Guard.
|
|
|
|
speedPoints = 0
|
|
|
|
for [levelSlug, speedThreshold] in [['dungeons-of-kithgard', 50], ['gems-in-the-deep', 55], ['shadow-guard', 55], ['forgetful-gemsmith', 40], ['true-names', 40]]
|
2016-02-16 23:39:59 -05:00
|
|
|
if _.find(@sessions?.models, (session) -> session.get('levelID') is levelSlug)?.attributes.playtime <= speedThreshold
|
2015-08-07 10:33:30 -04:00
|
|
|
++speedPoints
|
|
|
|
experienceScore = adultPoint + speedPoints # 0-6 score of how likely we think they are to be experienced and ready for Kithgard Mastery
|
|
|
|
return experienceScore
|
|
|
|
|
2015-01-13 12:04:09 -05:00
|
|
|
createLine: (o1, o2) ->
|
|
|
|
p1 = x: o1.x, y: 0.66 * o1.y + 0.5
|
|
|
|
p2 = x: o2.x, y: 0.66 * o2.y + 0.5
|
|
|
|
length = Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))
|
|
|
|
angle = Math.atan2(p1.y - p2.y, p2.x - p1.x) * 180 / Math.PI
|
|
|
|
transform = "rotate(#{angle}deg)"
|
|
|
|
line = $('<div>').appendTo('.map').addClass('next-level-line').css(transform: transform, width: length + '%', left: o1.x + '%', bottom: (o1.y + 0.5) + '%')
|
|
|
|
line.append($('<div class="line">')).append($('<div class="point">'))
|
|
|
|
|
2014-12-28 16:25:20 -05:00
|
|
|
applyCampaignStyles: ->
|
2015-02-05 18:05:22 -05:00
|
|
|
return unless @campaign?.loaded
|
2014-12-28 16:25:20 -05:00
|
|
|
if (backgrounds = @campaign.get 'backgroundImage') and backgrounds.length
|
|
|
|
backgrounds = _.sortBy backgrounds, 'width'
|
|
|
|
backgrounds.reverse()
|
|
|
|
rules = []
|
|
|
|
for background, i in backgrounds
|
|
|
|
rule = "#campaign-view .map-background { background-image: url(/file/#{background.image}); }"
|
|
|
|
rule = "@media screen and (max-width: #{background.width}px) { #{rule} }" if i
|
|
|
|
rules.push rule
|
|
|
|
utils.injectCSS rules.join('\n')
|
|
|
|
if backgroundColor = @campaign.get 'backgroundColor'
|
|
|
|
backgroundColorTransparent = @campaign.get 'backgroundColorTransparent'
|
|
|
|
@$el.css 'background-color', backgroundColor
|
|
|
|
for pos in ['top', 'right', 'bottom', 'left']
|
|
|
|
@$el.find(".#{pos}-gradient").css 'background-image', "linear-gradient(to #{pos}, #{backgroundColorTransparent} 0%, #{backgroundColor} 100%)"
|
|
|
|
@playAmbientSound()
|
|
|
|
|
2015-01-29 19:11:13 -05:00
|
|
|
testParticles: ->
|
2015-02-26 17:24:00 -05:00
|
|
|
return unless @campaign?.loaded and $.browser.chrome # Sometimes this breaks in non-Chrome browsers, according to A/B tests.
|
2015-01-29 19:11:13 -05:00
|
|
|
@particleMan ?= new ParticleMan()
|
|
|
|
@particleMan.removeEmitters()
|
|
|
|
@particleMan.attach @$el.find('.map')
|
2015-04-13 20:07:13 -04:00
|
|
|
for level in @campaign.renderedLevels ? {}
|
2015-10-16 19:06:53 -04:00
|
|
|
particleKey = ['level', @terrain.replace('-branching-test', '')]
|
2015-07-24 20:37:42 -04:00
|
|
|
particleKey.push level.type if level.type and not (level.type in ['hero', 'course'])
|
2015-04-13 20:07:13 -04:00
|
|
|
particleKey.push 'replayable' if level.replayable
|
2015-01-29 21:18:55 -05:00
|
|
|
particleKey.push 'premium' if level.requiresSubscription
|
2015-06-14 14:07:21 -04:00
|
|
|
particleKey.push 'gate' if level.slug in ['kithgard-gates', 'siege-of-stonehold', 'clash-of-clones', 'summits-gate']
|
2015-02-02 21:02:57 -05:00
|
|
|
particleKey.push 'hero' if level.unlocksHero and not level.unlockedHero
|
2015-09-12 09:54:14 -04:00
|
|
|
#particleKey.push 'item' if level.slug is 'robot-ragnarok' # TODO: generalize
|
2015-01-29 21:18:55 -05:00
|
|
|
continue if particleKey.length is 2 # Don't show basic levels
|
2016-06-08 19:57:00 -04:00
|
|
|
continue unless level.hidden or _.intersection(particleKey, ['item', 'hero-ladder', 'replayable', 'game-dev']).length
|
2015-01-29 21:18:55 -05:00
|
|
|
@particleMan.addEmitter level.position.x / 100, level.position.y / 100, particleKey.join('-')
|
2015-01-29 19:11:13 -05:00
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
onMouseEnterPortals: (e) ->
|
|
|
|
return unless @campaigns?.loaded and @sessions?.loaded
|
|
|
|
@portalScrollInterval = setInterval @onMouseMovePortals, 100
|
|
|
|
@onMouseMovePortals e
|
|
|
|
|
|
|
|
onMouseLeavePortals: (e) ->
|
|
|
|
return unless @portalScrollInterval
|
|
|
|
clearInterval @portalScrollInterval
|
|
|
|
@portalScrollInterval = null
|
|
|
|
|
|
|
|
onMouseMovePortals: (e) =>
|
|
|
|
return unless @portalScrollInterval
|
|
|
|
$portal = @$el.find('.portal')
|
|
|
|
$portals = @$el.find('.portals')
|
|
|
|
if e
|
|
|
|
@portalOffsetX = Math.round Math.max 0, e.clientX - $portal.offset().left
|
|
|
|
bodyWidth = $('body').innerWidth()
|
|
|
|
fraction = @portalOffsetX / bodyWidth
|
|
|
|
return if 0.2 < fraction < 0.8
|
|
|
|
direction = if fraction < 0.5 then 1 else -1
|
|
|
|
magnitude = 0.2 * bodyWidth * (if direction is -1 then fraction - 0.8 else 0.2 - fraction) / 0.2
|
|
|
|
portalsWidth = 1902 # TODO: if we add campaigns or change margins, this will get out of date...
|
|
|
|
scrollTo = $portals.offset().left + direction * magnitude
|
|
|
|
scrollTo = Math.max bodyWidth - portalsWidth, scrollTo
|
|
|
|
scrollTo = Math.min 0, scrollTo
|
|
|
|
$portals.stop().animate {marginLeft: scrollTo}, 100, 'linear'
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
onSessionsLoaded: (e) ->
|
2014-12-19 16:46:01 -05:00
|
|
|
return if @editorMode
|
2014-12-19 13:04:04 -05:00
|
|
|
for session in @sessions.models
|
2015-11-17 18:23:34 -05:00
|
|
|
unless @levelStatusMap[session.get('levelID')] is 'complete' # Don't overwrite a complete session with an incomplete one
|
|
|
|
@levelStatusMap[session.get('levelID')] = if session.get('state')?.complete then 'complete' else 'started'
|
2015-04-13 20:07:13 -04:00
|
|
|
@levelDifficultyMap[session.get('levelID')] = session.get('state').difficulty if session.get('state')?.difficulty
|
2014-12-19 13:04:04 -05:00
|
|
|
@render()
|
2016-02-16 23:39:59 -05:00
|
|
|
@loadUserPollsRecord() unless me.get('anonymous') or window.serverConfig.picoCTF
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-02-05 18:05:22 -05:00
|
|
|
onCampaignsLoaded: (e) ->
|
|
|
|
@render()
|
|
|
|
|
2015-02-04 16:24:15 -05:00
|
|
|
preloadLevel: (levelSlug) ->
|
|
|
|
levelURL = "/db/level/#{levelSlug}"
|
|
|
|
level = new Level().setURL levelURL
|
2016-02-18 11:44:40 -05:00
|
|
|
level = @supermodel.loadModel(level, null, 0).model
|
2015-02-04 16:24:15 -05:00
|
|
|
sessionURL = "/db/level/#{levelSlug}/session"
|
2015-02-06 16:04:06 -05:00
|
|
|
@preloadedSession = new LevelSession().setURL sessionURL
|
|
|
|
@listenToOnce @preloadedSession, 'sync', @onSessionPreloaded
|
2016-02-18 11:44:40 -05:00
|
|
|
@preloadedSession = @supermodel.loadModel(@preloadedSession, {cache: false}).model
|
2015-02-06 16:04:06 -05:00
|
|
|
@preloadedSession.levelSlug = levelSlug
|
2015-02-04 16:42:49 -05:00
|
|
|
|
|
|
|
onSessionPreloaded: (session) ->
|
2015-02-06 16:04:06 -05:00
|
|
|
session.url = -> '/db/level.session/' + @id
|
2015-02-04 16:42:49 -05:00
|
|
|
levelElement = @$el.find('.level-info-container:visible')
|
|
|
|
return unless session.levelSlug is levelElement.data 'level-slug'
|
|
|
|
return unless difficulty = session.get('state')?.difficulty
|
|
|
|
badge = $("<span class='badge'>#{difficulty}</span>")
|
|
|
|
levelElement.find('.start-level .badge').remove()
|
|
|
|
levelElement.find('.start-level').append badge
|
|
|
|
|
|
|
|
onClickMap: (e) ->
|
|
|
|
@$levelInfo?.hide()
|
2016-02-16 23:39:59 -05:00
|
|
|
if @sessions?.models.length < 3
|
2015-02-25 14:58:03 -05:00
|
|
|
# Restore the next level higlight for very new players who might otherwise get lost.
|
|
|
|
@highlightElement '.level.next', delay: 500, duration: 60000, rotation: 0, sides: ['top']
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
onClickLevel: (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
@$levelInfo?.hide()
|
|
|
|
levelElement = $(e.target).parents('.level')
|
2014-12-28 16:25:20 -05:00
|
|
|
levelSlug = levelElement.data('level-slug')
|
2014-12-29 15:46:14 -05:00
|
|
|
levelOriginal = levelElement.data('level-original')
|
2014-12-22 11:09:58 -05:00
|
|
|
if @editorMode
|
2014-12-29 15:46:14 -05:00
|
|
|
return @trigger 'level-clicked', levelOriginal
|
2015-02-03 21:25:38 -05:00
|
|
|
@$levelInfo = @$el.find(".level-info-container[data-level-slug=#{levelSlug}]").show()
|
2015-12-01 14:24:16 -05:00
|
|
|
@checkForCourseOption levelOriginal
|
2015-02-03 21:25:38 -05:00
|
|
|
@adjustLevelInfoPosition e
|
|
|
|
@endHighlight()
|
2015-02-04 16:24:15 -05:00
|
|
|
@preloadLevel levelSlug
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2014-12-29 15:46:14 -05:00
|
|
|
onDoubleClickLevel: (e) ->
|
|
|
|
return unless @editorMode
|
|
|
|
levelElement = $(e.target).parents('.level')
|
|
|
|
levelOriginal = levelElement.data('level-original')
|
|
|
|
@trigger 'level-double-clicked', levelOriginal
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
onClickStartLevel: (e) ->
|
|
|
|
levelElement = $(e.target).parents('.level-info-container')
|
2015-02-03 21:25:38 -05:00
|
|
|
levelSlug = levelElement.data('level-slug')
|
|
|
|
levelOriginal = levelElement.data('level-original')
|
|
|
|
level = _.find _.values(@campaign.get('levels')), slug: levelSlug
|
|
|
|
|
2015-10-09 11:05:34 -04:00
|
|
|
requiresSubscription = level.requiresSubscription or (me.isOnPremiumServer() and not (level.slug in ['dungeons-of-kithgard', 'gems-in-the-deep', 'shadow-guard', 'forgetful-gemsmith', 'signs-and-portents', 'true-names']))
|
2015-04-07 13:18:04 -04:00
|
|
|
canPlayAnyway = not @requiresSubscription or level.adventurer or @levelStatusMap[level.slug]
|
2015-03-23 18:26:44 -04:00
|
|
|
if requiresSubscription and not canPlayAnyway
|
2015-02-03 21:25:38 -05:00
|
|
|
@openModalView new SubscribeModal()
|
2016-02-16 23:39:59 -05:00
|
|
|
# TODO: Added levelID on 2/9/16. Remove level property and associated AnalyticsLogEvent 'properties.level' index later.
|
2016-02-09 18:12:01 -05:00
|
|
|
window.tracker?.trackEvent 'Show subscription modal', category: 'Subscription', label: 'map level clicked', level: levelSlug, levelID: levelSlug
|
2015-02-03 21:25:38 -05:00
|
|
|
else
|
|
|
|
@startLevel levelElement
|
2015-02-27 19:07:41 -05:00
|
|
|
window.tracker?.trackEvent 'Clicked Start Level', category: 'World Map', levelID: levelSlug
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-12-01 14:24:16 -05:00
|
|
|
onClickCourseVersion: (e) ->
|
|
|
|
levelSlug = $(e.target).parents('.level-info-container').data 'level-slug'
|
|
|
|
courseID = $(e.target).parents('.course-version').data 'course-id'
|
|
|
|
courseInstanceID = $(e.target).parents('.course-version').data 'course-instance-id'
|
|
|
|
url = "/play/level/#{levelSlug}?course=#{courseID}&course-instance=#{courseInstanceID}"
|
|
|
|
Backbone.Mediator.publish 'router:navigate', route: url
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
startLevel: (levelElement) ->
|
|
|
|
@setupManager?.destroy()
|
2015-02-04 16:24:15 -05:00
|
|
|
levelSlug = levelElement.data 'level-slug'
|
|
|
|
session = @preloadedSession if @preloadedSession?.loaded and @preloadedSession.levelSlug is levelSlug
|
|
|
|
@setupManager = new LevelSetupManager supermodel: @supermodel, levelID: levelSlug, levelPath: levelElement.data('level-path'), levelName: levelElement.data('level-name'), hadEverChosenHero: @hadEverChosenHero, parent: @, session: session
|
2016-02-17 12:53:45 -05:00
|
|
|
unless @setupManager?.navigatingToPlay
|
2015-12-04 13:26:09 -05:00
|
|
|
@$levelInfo.find('.level-info, .progress').toggleClass('hide')
|
2016-02-17 12:53:45 -05:00
|
|
|
@listenToOnce @setupManager, 'open', ->
|
|
|
|
@$levelInfo?.find('.level-info, .progress').toggleClass('hide')
|
|
|
|
@$levelInfo?.hide()
|
|
|
|
@setupManager.open()
|
2014-12-19 13:04:04 -05:00
|
|
|
|
2015-02-03 21:25:38 -05:00
|
|
|
onClickViewSolutions: (e) ->
|
|
|
|
levelElement = $(e.target).parents('.level-info-container')
|
|
|
|
levelSlug = levelElement.data('level-slug')
|
2015-04-10 12:23:00 -04:00
|
|
|
level = _.find _.values(@campaign.get('levels')), slug: levelSlug
|
2015-07-24 20:37:42 -04:00
|
|
|
if level.type in ['hero-ladder', 'course-ladder']
|
2015-04-10 12:23:00 -04:00
|
|
|
Backbone.Mediator.publish 'router:navigate', route: "/play/ladder/#{levelSlug}", viewClass: 'views/ladder/LadderView', viewArgs: [{supermodel: @supermodel}, levelSlug]
|
|
|
|
else
|
|
|
|
@showLeaderboard levelSlug
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
adjustLevelInfoPosition: (e) ->
|
|
|
|
return unless @$levelInfo
|
|
|
|
@$map ?= @$el.find('.map')
|
|
|
|
mapOffset = @$map.offset()
|
|
|
|
mapX = e.pageX - mapOffset.left
|
|
|
|
mapY = e.pageY - mapOffset.top
|
|
|
|
margin = 20
|
|
|
|
width = @$levelInfo.outerWidth()
|
|
|
|
@$levelInfo.css('left', Math.min(Math.max(margin, mapX - width / 2), @$map.width() - width - margin))
|
|
|
|
height = @$levelInfo.outerHeight()
|
|
|
|
top = mapY - @$levelInfo.outerHeight() - 60
|
2015-02-03 21:25:38 -05:00
|
|
|
if top < 100
|
2014-12-19 13:04:04 -05:00
|
|
|
top = mapY + 60
|
|
|
|
@$levelInfo.css('top', top)
|
|
|
|
|
|
|
|
onWindowResize: (e) =>
|
|
|
|
mapHeight = iPadHeight = 1536
|
2015-06-08 16:20:54 -04:00
|
|
|
mapWidth = {dungeon: 2350, forest: 2500, auditions: 2500, desert: 2350, mountain: 2422, glacier: 2421}[@terrain] or 2350
|
2014-12-19 13:04:04 -05:00
|
|
|
aspectRatio = mapWidth / mapHeight
|
|
|
|
pageWidth = @$el.width()
|
|
|
|
pageHeight = @$el.height()
|
2016-03-15 18:51:59 -04:00
|
|
|
pageHeight -= adContainerHeight if adContainerHeight = $('.ad-container').outerHeight()
|
2014-12-19 13:04:04 -05:00
|
|
|
widthRatio = pageWidth / mapWidth
|
|
|
|
heightRatio = pageHeight / mapHeight
|
|
|
|
# Make sure we can see the whole map, fading to background in one dimension.
|
|
|
|
if heightRatio <= widthRatio
|
|
|
|
# Left and right margin
|
|
|
|
resultingHeight = pageHeight
|
|
|
|
resultingWidth = resultingHeight * aspectRatio
|
|
|
|
else
|
|
|
|
# Top and bottom margin
|
|
|
|
resultingWidth = pageWidth
|
|
|
|
resultingHeight = resultingWidth / aspectRatio
|
|
|
|
resultingMarginX = (pageWidth - resultingWidth) / 2
|
|
|
|
resultingMarginY = (pageHeight - resultingHeight) / 2
|
|
|
|
@$el.find('.map').css(width: resultingWidth, height: resultingHeight, 'margin-left': resultingMarginX, 'margin-top': resultingMarginY)
|
2015-01-29 19:11:13 -05:00
|
|
|
@testParticles() if @particleMan
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
playAmbientSound: ->
|
2015-12-06 15:33:28 -05:00
|
|
|
return unless me.get 'volume'
|
2014-12-19 13:04:04 -05:00
|
|
|
return if @ambientSound
|
2015-01-02 15:36:47 -05:00
|
|
|
return unless file = @campaign?.get('ambientSound')?[AudioPlayer.ext.substr 1]
|
2014-12-28 16:25:20 -05:00
|
|
|
src = "/file/#{file}"
|
2014-12-19 13:04:04 -05:00
|
|
|
unless AudioPlayer.getStatus(src)?.loaded
|
|
|
|
AudioPlayer.preloadSound src
|
|
|
|
Backbone.Mediator.subscribeOnce 'audio-player:loaded', @playAmbientSound, @
|
|
|
|
return
|
|
|
|
@ambientSound = createjs.Sound.play src, loop: -1, volume: 0.1
|
|
|
|
createjs.Tween.get(@ambientSound).to({volume: 0.5}, 1000)
|
|
|
|
|
|
|
|
playMusic: ->
|
|
|
|
@musicPlayer = new MusicPlayer()
|
|
|
|
musicFile = '/music/music-menu'
|
|
|
|
Backbone.Mediator.publish 'music-player:play-music', play: true, file: musicFile
|
|
|
|
storage.save("loaded-menu-music", true) unless @probablyCachedMusic
|
|
|
|
|
2015-12-01 14:24:16 -05:00
|
|
|
checkForCourseOption: (levelOriginal) ->
|
|
|
|
return unless me.get('courseInstances')?.length
|
|
|
|
@courseOptionsChecked ?= {}
|
|
|
|
return if @courseOptionsChecked[levelOriginal]
|
|
|
|
@courseOptionsChecked[levelOriginal] = true
|
|
|
|
courseInstances = new CocoCollection [], url: "/db/course_instance/-/find_by_level/#{levelOriginal}", model: CourseInstance
|
|
|
|
courseInstances.comparator = (ci) -> return -(ci.get('members') ? []).length
|
|
|
|
@supermodel.loadCollection courseInstances, 'course_instances'
|
|
|
|
@listenToOnce courseInstances, 'sync', =>
|
|
|
|
return if @destroyed
|
|
|
|
return unless courseInstance = courseInstances.models[0]
|
|
|
|
@$el.find(".course-version[data-level-original='#{levelOriginal}']").removeClass('hidden').data('course-id': courseInstance.get('courseID'), 'course-instance-id': courseInstance.id)
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
preloadTopHeroes: ->
|
2016-02-17 12:53:45 -05:00
|
|
|
return if window.serverConfig.picoCTF
|
2014-12-19 13:04:04 -05:00
|
|
|
for heroID in ['captain', 'knight']
|
|
|
|
url = "/db/thang.type/#{ThangType.heroes[heroID]}/version"
|
|
|
|
continue if @supermodel.getModel url
|
|
|
|
fullHero = new ThangType()
|
|
|
|
fullHero.setURL url
|
2016-02-18 11:44:40 -05:00
|
|
|
@supermodel.loadModel fullHero
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
updateVolume: (volume) ->
|
|
|
|
volume ?= me.get('volume') ? 1.0
|
|
|
|
classes = ['vol-off', 'vol-down', 'vol-up']
|
|
|
|
button = $('#volume-button', @$el)
|
|
|
|
button.toggleClass 'vol-off', volume <= 0.0
|
|
|
|
button.toggleClass 'vol-down', 0.0 < volume < 1.0
|
|
|
|
button.toggleClass 'vol-up', volume >= 1.0
|
|
|
|
createjs.Sound.setVolume(if volume is 1 then 0.6 else volume) # Quieter for now until individual sound FX controls work again.
|
|
|
|
if volume isnt me.get 'volume'
|
|
|
|
me.set 'volume', volume
|
|
|
|
me.patch()
|
2015-12-06 15:33:28 -05:00
|
|
|
@playAmbientSound() if volume
|
2014-12-19 13:04:04 -05:00
|
|
|
|
|
|
|
onToggleVolume: (e) ->
|
|
|
|
button = $(e.target).closest('#volume-button')
|
|
|
|
classes = ['vol-off', 'vol-down', 'vol-up']
|
|
|
|
volumes = [0, 0.4, 1.0]
|
|
|
|
for oldClass, i in classes
|
|
|
|
if button.hasClass oldClass
|
|
|
|
newI = (i + 1) % classes.length
|
|
|
|
break
|
|
|
|
else if i is classes.length - 1 # no oldClass
|
|
|
|
newI = 2
|
|
|
|
@updateVolume volumes[newI]
|
|
|
|
|
2015-02-05 18:40:33 -05:00
|
|
|
onClickBack: (e) ->
|
|
|
|
Backbone.Mediator.publish 'router:navigate',
|
|
|
|
route: "/play"
|
|
|
|
viewClass: CampaignView
|
|
|
|
viewArgs: [{supermodel: @supermodel}]
|
|
|
|
|
2015-02-25 14:09:11 -05:00
|
|
|
onClickClearStorage: (e) ->
|
|
|
|
localStorage.clear()
|
|
|
|
noty {
|
|
|
|
text: 'Local storage cleared. Reload to view the original campaign.'
|
|
|
|
layout: 'topCenter'
|
|
|
|
timeout: 5000
|
|
|
|
type: 'information'
|
|
|
|
}
|
|
|
|
|
2014-12-19 13:04:04 -05:00
|
|
|
updateHero: ->
|
|
|
|
return unless hero = me.get('heroConfig')?.thangType
|
|
|
|
for slug, original of ThangType.heroes when original is hero
|
|
|
|
@$el.find('.player-hero-icon').removeClass().addClass('player-hero-icon ' + slug)
|
|
|
|
return
|
2014-12-28 16:25:20 -05:00
|
|
|
console.error "CampaignView hero update couldn't find hero slug for original:", hero
|
2015-02-05 18:05:22 -05:00
|
|
|
|
|
|
|
onClickPortalCampaign: (e) ->
|
|
|
|
campaign = $(e.target).closest('.campaign')
|
|
|
|
return if campaign.is('.locked') or campaign.is('.silhouette')
|
|
|
|
campaignSlug = campaign.data('campaign-slug')
|
|
|
|
Backbone.Mediator.publish 'router:navigate',
|
|
|
|
route: "/play/#{campaignSlug}"
|
|
|
|
viewClass: CampaignView
|
|
|
|
viewArgs: [{supermodel: @supermodel}, campaignSlug]
|
2015-03-07 19:30:25 -05:00
|
|
|
|
|
|
|
loadUserPollsRecord: ->
|
|
|
|
url = "/db/user.polls.record/-/user/#{me.id}"
|
|
|
|
@userPollsRecord = new UserPollsRecord().setURL url
|
|
|
|
onRecordSync = ->
|
|
|
|
return if @destroyed
|
|
|
|
@userPollsRecord.url = -> '/db/user.polls.record/' + @id
|
2015-03-09 12:51:15 -04:00
|
|
|
lastVoted = new Date(@userPollsRecord.get('changed') or 0)
|
2015-03-09 12:30:51 -04:00
|
|
|
interval = new Date() - lastVoted
|
|
|
|
if interval > 22 * 60 * 60 * 1000 # Wait almost a day before showing the next poll
|
|
|
|
@loadPoll()
|
|
|
|
else
|
|
|
|
console.log 'Poll will be ready in', (22 * 60 * 60 * 1000 - interval) / (60 * 60 * 1000), 'hours.'
|
2015-03-07 19:30:25 -05:00
|
|
|
@listenToOnce @userPollsRecord, 'sync', onRecordSync
|
2016-02-18 11:44:40 -05:00
|
|
|
@userPollsRecord = @supermodel.loadModel(@userPollsRecord, null, 0).model
|
2015-03-07 19:30:25 -05:00
|
|
|
onRecordSync.call @ if @userPollsRecord.loaded
|
|
|
|
|
|
|
|
loadPoll: ->
|
2015-03-14 12:57:31 -04:00
|
|
|
url = "/db/poll/#{@userPollsRecord.id}/next"
|
2015-03-07 19:30:25 -05:00
|
|
|
@poll = new Poll().setURL url
|
|
|
|
onPollSync = ->
|
|
|
|
return if @destroyed
|
|
|
|
@poll.url = -> '/db/poll/' + @id
|
|
|
|
_.delay (=> @activatePoll?()), 1000
|
|
|
|
onPollError = (poll, response, request) ->
|
|
|
|
if response.status is 404
|
|
|
|
console.log 'There are no more polls left.'
|
|
|
|
else
|
|
|
|
console.error "Couldn't load poll:", response.status, response.statusText
|
|
|
|
delete @poll
|
|
|
|
@listenToOnce @poll, 'sync', onPollSync
|
|
|
|
@listenToOnce @poll, 'error', onPollError
|
2016-02-18 11:44:40 -05:00
|
|
|
@poll = @supermodel.loadModel(@poll, null, 0).model
|
2015-03-07 19:30:25 -05:00
|
|
|
onPollSync.call @ if @poll.loaded
|
|
|
|
|
|
|
|
activatePoll: ->
|
2015-03-18 20:17:30 -04:00
|
|
|
pollTitle = utils.i18n @poll.attributes, 'name'
|
2015-03-07 19:30:25 -05:00
|
|
|
$pollButton = @$el.find('button.poll').removeClass('hidden').addClass('highlighted').attr(title: pollTitle).addClass('has-tooltip').tooltip title: pollTitle
|
|
|
|
if me.get('lastLevel') is 'shadow-guard'
|
|
|
|
@showPoll()
|
|
|
|
else
|
|
|
|
$pollButton.tooltip 'show'
|
|
|
|
|
|
|
|
showPoll: ->
|
|
|
|
pollModal = new PollModal supermodel: @supermodel, poll: @poll, userPollsRecord: @userPollsRecord
|
|
|
|
@openModalView pollModal
|
|
|
|
$pollButton = @$el.find 'button.poll'
|
|
|
|
pollModal.on 'vote-updated', ->
|
|
|
|
$pollButton.removeClass('highlighted').tooltip 'hide'
|