From a35d0cb651f8bed7a563760a1831e3adde951b88 Mon Sep 17 00:00:00 2001 From: dpen2000 Date: Fri, 21 Mar 2014 23:49:30 +0000 Subject: [PATCH 1/9] Implement saving lastLevel in database re #627 --- app/views/home_view.coffee | 19 ++++++++----------- app/views/play/level_view.coffee | 4 +++- server/users/user_handler.coffee | 2 +- server/users/user_schema.coffee | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/home_view.coffee b/app/views/home_view.coffee index 5b3086127..7c063d6cf 100644 --- a/app/views/home_view.coffee +++ b/app/views/home_view.coffee @@ -31,14 +31,11 @@ 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 "" - 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.") \ No newline at end of file + lastLevel = me.get("lastLevel") + if lastLevel? and lastLevel isnt "" + 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) \ No newline at end of file diff --git a/app/views/play/level_view.coffee b/app/views/play/level_view.coffee index aaa718703..98b1d3cd8 100644 --- a/app/views/play/level_view.coffee +++ b/app/views/play/level_view.coffee @@ -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) diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 397e44e8a..7bdc7f1dc 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -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', 'simulatedBy', 'simulatedFor', 'autocastDelay', 'lastLevel' ] jsonSchema: schema diff --git a/server/users/user_schema.coffee b/server/users/user_schema.coffee index 1c8807c44..c6399576f 100644 --- a/server/users/user_schema.coffee +++ b/server/users/user_schema.coffee @@ -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} From 860c3a34d37e6b5d66e46c5b9027c54445e7f95a Mon Sep 17 00:00:00 2001 From: Jayant Jain Date: Sat, 22 Mar 2014 05:51:44 +0530 Subject: [PATCH 2/9] Fixes #641, the list of levels in editor reloads properly upon changing language --- app/views/kinds/SearchView.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/kinds/SearchView.coffee b/app/views/kinds/SearchView.coffee index 1198f74a1..6fae0228d 100644 --- a/app/views/kinds/SearchView.coffee +++ b/app/views/kinds/SearchView.coffee @@ -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() From e101fb04eb069b321adfe39c86eaf173d722033c Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Fri, 21 Mar 2014 17:42:13 -0700 Subject: [PATCH 3/9] For #648: Keeping localStorage fallback for played levels temporarily until most have migrated to user property. Fixed #627. --- app/views/home_view.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/home_view.coffee b/app/views/home_view.coffee index 7c063d6cf..7c0eea234 100644 --- a/app/views/home_view.coffee +++ b/app/views/home_view.coffee @@ -8,7 +8,7 @@ Simulator = require 'lib/simulator/Simulator' module.exports = class HomeView extends View id: 'home-view' template: template - + constructor: -> super(arguments...) ThangType.loadUniversalWizard() @@ -32,10 +32,11 @@ module.exports = class HomeView extends View # Try to find latest level and set "Play" link to go to that level lastLevel = me.get("lastLevel") - if lastLevel? and lastLevel isnt "" + 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) \ No newline at end of file + playLink.attr("href", href) From 14ee9c30cef907be4604ca49cca474086996c36c Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 21 Mar 2014 19:50:54 -0700 Subject: [PATCH 4/9] Added facebook friends to the ladder page. --- app/styles/play/ladder.sass | 28 +++++++++++ app/templates/play/ladder/ladder_tab.jade | 46 +++++++++++++++-- app/views/play/ladder/ladder_tab.coffee | 61 ++++++++++++++++++++--- 3 files changed, 123 insertions(+), 12 deletions(-) diff --git a/app/styles/play/ladder.sass b/app/styles/play/ladder.sass index ba99c6948..c1c2fd374 100644 --- a/app/styles/play/ladder.sass +++ b/app/styles/play/ladder.sass @@ -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 diff --git a/app/templates/play/ladder/ladder_tab.jade b/app/templates/play/ladder/ladder_tab.jade index 092e60372..81bf058c4 100644 --- a/app/templates/play/ladder/ladder_tab.jade +++ b/app/templates/play/ladder/ladder_tab.jade @@ -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 + if !showJustTop tr(class="active") td(colspan=4).ellipsis-row ... for session in team.leaderboard.nearbySessions() @@ -38,4 +38,40 @@ div#columns.row td.name-col-cell= session.get('creatorName') || "Anonymous" td.fight-cell a(href="/play/level/#{level.get('slug') || level.id}/?team=#{team.otherTeam}&opponent=#{session.id}") - span(data-i18n="ladder.fight") Fight! \ No newline at end of file + 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! \ No newline at end of file diff --git a/app/views/play/ladder/ladder_tab.coffee b/app/views/play/ladder/ladder_tab.coffee index 226ab5f54..9cce33a14 100644 --- a/app/views/play/ladder/ladder_tab.coffee +++ b/app/views/play/ladder/ladder_tab.coffee @@ -19,25 +19,68 @@ module.exports = class LadderTabView extends CocoView id: 'ladder-tab-view' template: require 'templates/play/ladder/ladder_tab' startsLoading: true + + events: + 'click .connect-facebook': -> FB.login() + + subscriptions: + 'facebook-logged-in': -> location.reload() constructor: (options, @level, @sessions) -> super(options) @teams = teamDataFromLevel @level @leaderboards = {} @refreshLadder() + @checkFriends() + + 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, @ - - onLeaderboardLoaded: -> @renderMaybe() + promises.push @leaderboards[team.id].promise + @loadingLeaderboards = true + $.when(promises...).then(@leaderboardsLoaded) + 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 +91,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 @@ -70,7 +115,9 @@ class LeaderboardData 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 @@ -82,7 +129,7 @@ class LeaderboardData return me.id in (session.attributes.creator for session in @topPlayers.models) nearbySessions: -> - return unless @session + return [] unless @session l = [] above = @playersAbove.models above.reverse() From 2cdfbf1c48438e0bac1173fd6bcdd9df26d5de80 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 21 Mar 2014 19:56:25 -0700 Subject: [PATCH 5/9] Merged conflicts. --- app/templates/play/ladder/ladder_tab.jade | 6 +----- app/views/play/ladder/ladder_tab.coffee | 6 ------ 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/app/templates/play/ladder/ladder_tab.jade b/app/templates/play/ladder/ladder_tab.jade index c78c0af08..4c5bf58e3 100644 --- a/app/templates/play/ladder/ladder_tab.jade +++ b/app/templates/play/ladder/ladder_tab.jade @@ -27,11 +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! -<<<<<<< HEAD - if !showJustTop -======= - if !inTheTop && team.leaderboard.nearbySessions().length ->>>>>>> b91f3200c216482908a3b5762f91134c6c602a8f + if !showJustTop && team.leaderboard.nearbySessions().length tr(class="active") td(colspan=4).ellipsis-row ... for session in team.leaderboard.nearbySessions() diff --git a/app/views/play/ladder/ladder_tab.coffee b/app/views/play/ladder/ladder_tab.coffee index 79d75e55d..2abd0cabf 100644 --- a/app/views/play/ladder/ladder_tab.coffee +++ b/app/views/play/ladder/ladder_tab.coffee @@ -114,15 +114,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} -<<<<<<< HEAD - @promise = $.when(promises...) @promise.then @onLoad @promise -======= - - $.when(promises...).then @onLoad ->>>>>>> b91f3200c216482908a3b5762f91134c6c602a8f onLoad: => @loaded = true From 0df09f7f356811a4d2375bf9c963b6bed2ef9c94 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 21 Mar 2014 21:11:51 -0700 Subject: [PATCH 6/9] Fixed an ever-reloading bug. --- app/views/play/ladder/ladder_tab.coffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/views/play/ladder/ladder_tab.coffee b/app/views/play/ladder/ladder_tab.coffee index 2abd0cabf..7b15e4c94 100644 --- a/app/views/play/ladder/ladder_tab.coffee +++ b/app/views/play/ladder/ladder_tab.coffee @@ -21,10 +21,10 @@ module.exports = class LadderTabView extends CocoView startsLoading: true events: - 'click .connect-facebook': -> FB.login() + 'click .connect-facebook': 'onConnectFacebook' subscriptions: - 'facebook-logged-in': -> location.reload() + 'facebook-logged-in': 'onConnectedWithFacebook' constructor: (options, @level, @sessions) -> super(options) @@ -32,6 +32,13 @@ module.exports = class LadderTabView extends CocoView @leaderboards = {} @refreshLadder() @checkFriends() + + onConnectFacebook: -> + @connecting = true + FB.login() + + onConnectedWithFacebook: -> + location.reload() if @connecting checkFriends: -> @loadingFriends = true From 3e87d54663dc33a50031d15c50729842b2545b84 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Fri, 21 Mar 2014 21:14:48 -0700 Subject: [PATCH 7/9] I guess we don't edit simulate counts on the client. --- server/users/user_handler.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/users/user_handler.coffee b/server/users/user_handler.coffee index 7bdc7f1dc..c822f9139 100644 --- a/server/users/user_handler.coffee +++ b/server/users/user_handler.coffee @@ -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', 'lastLevel' + 'wizard', 'aceConfig', 'autocastDelay', 'lastLevel' ] jsonSchema: schema From b2c500369b6159bf8ae02b84e352e0a4866af65b Mon Sep 17 00:00:00 2001 From: therealbond Date: Sat, 22 Mar 2014 01:56:32 -0400 Subject: [PATCH 8/9] Added more names for #53 --- app/lib/world/names.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/lib/world/names.coffee b/app/lib/world/names.coffee index 385d2f630..04d8e1fc6 100644 --- a/app/lib/world/names.coffee +++ b/app/lib/world/names.coffee @@ -286,10 +286,19 @@ module.exports.thangNames = thangNames = ] "Potion Master": [ "Snake" + "Amaranth" + "Zander" + "Arora" ] "Librarian": [ "Hushbaum" + "Matilda" + "Agnes" + "Agathe" ] "Equestrian": [ "Reynaldo" + "Ryder" + "Thoron" + "Mirial" ] From d289ca825e04921c00449cd1b592c5e4811971be Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Sat, 22 Mar 2014 08:52:47 -0700 Subject: [PATCH 9/9] Fixed Simulator to actually use protectAPI. --- app/lib/simulator/Simulator.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/lib/simulator/Simulator.coffee b/app/lib/simulator/Simulator.coffee index a91ec2306..888ba3f52 100644 --- a/app/lib/simulator/Simulator.coffee +++ b/app/lib/simulator/Simulator.coffee @@ -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: