2014-11-28 20:49:41 -05:00
RootView = require ' views/core/RootView '
2014-05-19 14:58:45 -04:00
template = require ' templates/play/ladder_home '
LevelSession = require ' models/LevelSession '
CocoCollection = require ' collections/CocoCollection '
class LevelSessionsCollection extends CocoCollection
url: ' '
model: LevelSession
constructor: (model) ->
super ( )
@url = " /db/user/ #{ me . id } /level.sessions?project=state.complete,levelID "
2016-01-16 07:07:15 -05:00
module.exports = class MainLadderView extends RootView
id: ' main-ladder-view '
2014-05-19 14:58:45 -04:00
template: template
2016-06-02 03:54:00 -04:00
initialize: ->
@levelStatusMap = [ ]
@levelPlayCountMap = [ ]
@campaigns = campaigns
2015-02-11 16:12:42 -05:00
@sessions = @ supermodel . loadCollection ( new LevelSessionsCollection ( ) , ' your_sessions ' , { cache: false } , 0 ) . model
2016-07-14 13:26:09 -04:00
@ listenToOnce @ sessions , ' sync ' , @ onSessionsLoaded
2016-06-02 03:54:00 -04:00
2014-08-28 01:23:24 -04:00
@ getLevelPlayCounts ( )
2014-05-19 14:58:45 -04:00
onSessionsLoaded: (e) ->
for session in @ sessions . models
@ levelStatusMap [ session . get ( ' levelID ' ) ] = if session . get ( ' state ' ) ? . complete then ' complete ' else ' started '
@ render ( )
2014-08-28 01:23:24 -04:00
getLevelPlayCounts: ->
success = (levelPlayCounts) =>
return if @ destroyed
for level in levelPlayCounts
@ levelPlayCountMap [ level . _id ] = playtime: level . playtime , sessions: level . sessions
@ render ( ) if @ supermodel . finished ( )
levelIDs = [ ]
for campaign in campaigns
for level in campaign . levels
levelIDs . push level . id
levelPlayCountsRequest = @ supermodel . addRequestResource ' play_counts ' , {
url: ' /db/level/-/play_counts '
data: { ids: levelIDs }
method: ' POST '
success: success
} , 0
levelPlayCountsRequest . load ( )
2015-07-07 14:43:24 -04:00
heroArenas = [
{
2015-09-12 09:54:14 -04:00
name: ' Ace of Coders '
2015-07-07 14:43:24 -04:00
difficulty: 3
2015-09-12 09:54:14 -04:00
id: ' ace-of-coders '
image: ' /file/db/level/55de80407a57948705777e89/Ace-of-Coders-banner.png '
description: ' Battle for control over the icy treasure chests as your gigantic warrior marshals his armies against his mirror-match nemesis. '
2015-07-07 14:43:24 -04:00
}
2015-09-03 11:33:48 -04:00
{
2015-09-12 09:54:14 -04:00
name: ' Zero Sum '
2015-09-03 11:33:48 -04:00
difficulty: 3
2015-09-12 09:54:14 -04:00
id: ' zero-sum '
2015-09-03 11:33:48 -04:00
image: ' /file/db/level/550363b4ec31df9c691ab629/MAR26-Banner_Zero%20Sum.png '
2015-09-12 09:54:14 -04:00
description: ' Unleash your coding creativity in both gold gathering and battle tactics in this alpine mirror match between red sorcerer and blue sorcerer. '
2015-09-03 11:33:48 -04:00
}
2015-07-07 14:43:24 -04:00
{
name: ' Cavern Survival '
difficulty: 1
id: ' cavern-survival '
2015-11-12 19:30:56 -05:00
image: ' /file/db/level/544437e0645c0c0000c3291d/OCT30-Cavern%20Survival.png '
2015-07-07 14:43:24 -04:00
description: ' Stay alive longer than your multiplayer opponent amidst hordes of ogres! '
}
{
name: ' Dueling Grounds '
difficulty: 1
id: ' dueling-grounds '
2015-11-12 19:30:56 -05:00
image: ' /file/db/level/5442ba0e1e835500007eb1c7/OCT27-Dueling%20Grounds.png '
2015-07-07 14:43:24 -04:00
description: ' Battle head-to-head against another hero in this basic beginner combat arena. '
}
{
name: ' Multiplayer Treasure Grove '
difficulty: 2
id: ' multiplayer-treasure-grove '
2015-11-12 19:30:56 -05:00
image: ' /file/db/level/5469643c37600b40e0e09c5b/OCT27-Multiplayer%20Treasure%20Grove.png '
2015-07-07 14:43:24 -04:00
description: ' Mix collection, flags, and combat in this multiplayer coin-gathering arena. '
}
{
name: ' Harrowland '
difficulty: 2
id: ' harrowland '
2015-11-12 19:30:56 -05:00
image: ' /file/db/level/54b83c2629843994803c838e/OCT27-Harrowland.png '
2015-07-07 14:43:24 -04:00
description: ' Go head-to-head against another player in this dueling arena--but watch out for their friends! '
}
]
2014-08-28 01:23:24 -04:00
campaigns = [
2015-07-07 14:43:24 -04:00
{ id: ' multiplayer ' , name: ' Multiplayer Arenas ' , description: ' ... in which you code head-to-head against other players. ' , levels: heroArenas }
2014-08-28 01:23:24 -04:00
]