Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-03-22 08:56:49 -07:00
commit 27c70d0a98
10 changed files with 155 additions and 28 deletions

View file

@ -231,9 +231,8 @@ module.exports = class Simulator extends CocoClass
createAether: (methodName, method) ->
aetherOptions =
functionName: methodName
protectAPI: false
protectAPI: true
includeFlow: false
#includeFlow: true
requiresThis: true
yieldConditionally: false
problems:

View file

@ -286,10 +286,19 @@ module.exports.thangNames = thangNames =
]
"Potion Master": [
"Snake"
"Amaranth"
"Zander"
"Arora"
]
"Librarian": [
"Hushbaum"
"Matilda"
"Agnes"
"Agathe"
]
"Equestrian": [
"Reynaldo"
"Ryder"
"Thoron"
"Mirial"
]

View file

@ -29,6 +29,34 @@
.ellipsis-row
text-align: center
// friend column
.friends-header
margin-top: 0
margin-bottom: 5px
.connect-buttons
margin-bottom: 10px
.btn
margin-left: 5px
.friend-entry img
float: left
margin-right: 10px
.friend-entry
margin-bottom: 15px
.connect-facebook
background-color: #4c66a4 !important
background-image: none
color: white
.connect-google-plus
background-color: #CC3234 !important
background-image: none
color: white
td
padding: 1px 2px

View file

@ -1,6 +1,6 @@
div#columns.row
for team in teams
div.column.col-md-6
div.column.col-md-4
table.table.table-bordered.table-condensed.table-hover
tr
th
@ -15,8 +15,8 @@ div#columns.row
th
- var topSessions = team.leaderboard.topPlayers.models;
- var inTheTop = team.leaderboard.inTopSessions();
- if(!inTheTop) topSessions = topSessions.slice(0, 10);
- var showJustTop = team.leaderboard.inTopSessions() || me.get('anonymous');
- if(!showJustTop) topSessions = topSessions.slice(0, 10);
for session, rank in topSessions
- var myRow = session.get('creator') == me.id
tr(class=myRow ? "success" : "")
@ -27,7 +27,7 @@ div#columns.row
a(href="/play/level/#{level.get('slug') || level.id}/?team=#{team.otherTeam}&opponent=#{session.id}")
span(data-i18n="ladder.fight") Fight!
if !inTheTop && team.leaderboard.nearbySessions().length
if !showJustTop && team.leaderboard.nearbySessions().length
tr(class="active")
td(colspan=4).ellipsis-row ...
for session in team.leaderboard.nearbySessions()
@ -39,3 +39,39 @@ div#columns.row
td.fight-cell
a(href="/play/level/#{level.get('slug') || level.id}/?team=#{team.otherTeam}&opponent=#{session.id}")
span(data-i18n="ladder.fight") Fight!
div.column.col-md-4
h4.friends-header Friends Playing
if me.get('anonymous')
div.alert.alert-info
a(data-toggle="coco-modal", data-target="modal/signup") Sign up to play with your friends!
else
if !onFacebook
div.connect-buttons
| Connect:
if !onFacebook
button.btn.btn-sm.connect-facebook Facebook
//button.btn.btn-sm.connect-google-plus Google+
if !!friends
if friends.length
for friend in friends
p.friend-entry
img(src="http://graph.facebook.com/#{friend.facebookID}/picture").img-thumbnail
span= friend.creatorName + ' (' + friend.facebookName + ')'
br
span= Math.round(friend.totalScore * 100)
span :
span= friend.team
br
a(href="/play/level/#{level.get('slug') || level.id}/?team=#{friend.otherTeam}&opponent=#{friend._id}")
span(data-i18n="ladder.fight") Fight!
else
p Invite your friends to join you in battle!
else
p Connect to social networks to play with your friends!

View file

@ -31,14 +31,12 @@ module.exports = class HomeView extends View
$('input:visible:first', @).focus()
# Try to find latest level and set "Play" link to go to that level
if localStorage?
lastLevel = localStorage["lastLevel"]
if lastLevel? and lastLevel isnt ""
lastLevel = me.get("lastLevel")
lastLevel ?= localStorage?["lastLevel"] # Temp, until it's migrated to user property
if lastLevel
playLink = @$el.find("#beginner-campaign")
if playLink[0]?
href = playLink.attr("href").split("/")
href[href.length-1] = lastLevel if href.length isnt 0
href = href.join("/")
playLink.attr("href", href)
else
console.log("TODO: Insert here code to get latest level played from the database. If this can't be found, we just let the user play the first level.")

View file

@ -53,6 +53,7 @@ module.exports = class ThangTypeHomeView extends View
hash = document.location.hash[1..]
searchInput = @$el.find('#search')
searchInput.val(hash) if hash?
delete @collection?.term
searchInput.trigger('change')
searchInput.focus()

View file

@ -20,24 +20,74 @@ module.exports = class LadderTabView extends CocoView
template: require 'templates/play/ladder/ladder_tab'
startsLoading: true
events:
'click .connect-facebook': 'onConnectFacebook'
subscriptions:
'facebook-logged-in': 'onConnectedWithFacebook'
constructor: (options, @level, @sessions) ->
super(options)
@teams = teamDataFromLevel @level
@leaderboards = {}
@refreshLadder()
@checkFriends()
onConnectFacebook: ->
@connecting = true
FB.login()
onConnectedWithFacebook: ->
location.reload() if @connecting
checkFriends: ->
@loadingFriends = true
FB.getLoginStatus (response) =>
@facebookStatus = response.status
if @facebookStatus is 'connected'
@loadFriendSessions()
else
@loadingFriends = false
@renderMaybe()
loadFriendSessions: ->
FB.api '/me/friends', (response) =>
@facebookData = response.data
console.log 'got facebookData', @facebookData
levelFrag = "#{@level.get('original')}.#{@level.get('version').major}"
url = "/db/level/#{levelFrag}/leaderboard_friends"
$.ajax url, {
data: { friendIDs: (f.id for f in @facebookData) }
method: 'POST'
success: @facebookFriendsLoaded
}
facebookFriendsLoaded: (result) =>
friendsMap = {}
friendsMap[friend.id] = friend.name for friend in @facebookData
for friend in result
friend.facebookName = friendsMap[friend.facebookID]
friend.otherTeam = if friend.team is 'humans' then 'ogres' else 'humans'
@friends = result
@loadingFriends = false
@renderMaybe()
refreshLadder: ->
promises = []
for team in @teams
@leaderboards[team.id]?.off 'sync'
teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession)
@leaderboards[team.id].once 'sync', @onLeaderboardLoaded, @
promises.push @leaderboards[team.id].promise
@loadingLeaderboards = true
$.when(promises...).then(@leaderboardsLoaded)
onLeaderboardLoaded: -> @renderMaybe()
leaderboardsLoaded: =>
@loadingLeaderboards = false
@renderMaybe()
renderMaybe: ->
leaderboardModels = _.values(@leaderboards)
return unless _.every leaderboardModels, (loader) -> loader.loaded
return if @loadingFriends or @loadingLeaderboards
@startsLoading = false
@render()
@ -48,6 +98,8 @@ module.exports = class LadderTabView extends CocoView
ctx.teams = @teams
team.leaderboard = @leaderboards[team.id] for team in @teams
ctx.levelID = @levelID
ctx.friends = @friends
ctx.onFacebook = @facebookStatus is 'connected'
ctx
class LeaderboardData
@ -69,8 +121,9 @@ class LeaderboardData
level = "#{level.get('original')}.#{level.get('version').major}"
success = (@myRank) =>
promises.push $.ajax "/db/level/#{level}/leaderboard_rank?scoreOffset=#{@session.get('totalScore')}&team=#{@team}", {success}
$.when(promises...).then @onLoad
@promise = $.when(promises...)
@promise.then @onLoad
@promise
onLoad: =>
@loaded = true

View file

@ -154,7 +154,9 @@ module.exports = class PlayLevelView extends View
return Backbone.Mediator.subscribeOnce 'modal-closed', @onLevelLoaderLoaded, @
# Save latest level played in local storage
localStorage["lastLevel"] = @levelID if localStorage? and not (@levelLoader.level.get('type') in ['ladder', 'ladder-tutorial'])
if not (@levelLoader.level.get('type') in ['ladder', 'ladder-tutorial'])
me.set('lastLevel', @levelID)
me.save()
@grabLevelLoaderData()
team = @getQueryVariable("team") ? @world.teamForPlayer(0)
@loadOpponentTeam(team)

View file

@ -18,7 +18,7 @@ UserHandler = class UserHandler extends Handler
'name', 'photoURL', 'password', 'anonymous', 'wizardColor1', 'volume',
'firstName', 'lastName', 'gender', 'facebookID', 'emailSubscriptions',
'testGroupNumber', 'music', 'hourOfCode', 'hourOfCodeComplete', 'preferredLanguage',
'wizard', 'aceConfig', 'simulatedBy', 'simulatedFor', 'autocastDelay'
'wizard', 'aceConfig', 'autocastDelay', 'lastLevel'
]
jsonSchema: schema

View file

@ -18,6 +18,7 @@ UserSchema = c.object {},
volume: c.pct({title: 'Volume'})
music: {type: 'boolean', default: true}
autocastDelay: {type: 'integer', 'default': 5000 }
lastLevel: { type: 'string' }
emailSubscriptions: c.array {uniqueItems: true, 'default': ['announcement', 'notification']}, {'enum': emailSubscriptions}