Implement saving lastLevel in database re

This commit is contained in:
dpen2000 2014-03-21 23:49:30 +00:00
parent f0640dd2e8
commit a35d0cb651
4 changed files with 13 additions and 13 deletions

View file

@ -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.")
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)

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', 'simulatedBy', 'simulatedFor', '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}