-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evan Wallace
committed
Mar 5, 2011
1 parent
e554daf
commit 6b3c41c
Showing
10 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function loadStats(username, callback) { | ||
$.ajax({ | ||
'url': '/stats/' + username, | ||
'type': 'GET', | ||
'cache': false, | ||
'dataType': 'json', | ||
'success': callback | ||
}); | ||
} | ||
|
||
function saveStats(username, levelname, stats) { | ||
$.ajax({ | ||
'url': '/stats/' + username + '/' + levelname, | ||
'type': 'PUT', | ||
'dataType': 'json', | ||
'data': JSON.stringify({ | ||
'statistic': { | ||
'complete': stats.complete, | ||
'got_all_cogs': stats.gotAllCogs | ||
} | ||
}), | ||
'contentType': 'application/json; charset=utf-8' | ||
}); | ||
} | ||
|
||
function PlayerStats(username, callback) { | ||
this.username = username; | ||
this.stats = {}; | ||
|
||
if (this.username != null) { | ||
var this_ = this; | ||
loadStats(username, function(stats) { | ||
for (var i = 0; i < stats.length; i++) { | ||
var s = stats[i]['statistic']; | ||
this_.stats[s.levelname] = { | ||
complete: s['complete'], | ||
gotAllCogs: s['got_all_cogs'] | ||
}; | ||
} | ||
callback(); | ||
}); | ||
} | ||
} | ||
|
||
PlayerStats.prototype.getStatsForLevel = function(levelname) { | ||
if (this.username != null) { | ||
if (levelname in this.stats) { | ||
return this.stats[levelname]; | ||
} | ||
} else { | ||
// TODO: cookies | ||
} | ||
return { | ||
complete: false, | ||
gotAllCogs: false | ||
}; | ||
}; | ||
|
||
PlayerStats.prototype.setStatsForLevel = function(levelname, complete, gotAllCogs) { | ||
if (this.username != null) { | ||
var stats = { | ||
complete: complete, | ||
gotAllCogs: gotAllCogs | ||
}; | ||
this.stats[levelname] = stats; | ||
saveStats(this.username, levelname, stats); | ||
} else { | ||
// TODO: cookies | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
class Statistic < ActiveRecord::Base | ||
belongs_to :level | ||
belongs_to :user | ||
|
||
attr_accessible :complete, :got_all_cogs | ||
|
||
def levelname | ||
self.level.html_title | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Statistics < ActiveRecord::Migration | ||
def self.up | ||
add_column :statistics, :complete, :boolean, :default => false | ||
add_column :statistics, :got_all_cogs, :boolean, :default => false | ||
end | ||
|
||
def self.down | ||
remove_column :statistics, :complete | ||
remove_column :statistics, :got_all_cogs | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters