Permalink
Browse files

add support for clearing scores and move examples to readme

  • Loading branch information...
Abica committed May 3, 2010
1 parent 00cc0ef commit 3c2042b294a9fac1e04c35bc9a709c2d808bdb52
Showing with 62 additions and 6 deletions.
  1. +0 −5 README
  2. +50 −0 README.rdoc
  3. +1 −1 TODO
  4. +11 −0 lime.lua
View
5 README
@@ -1,5 +0,0 @@
-lime is a basic high score framework for saving and reloading global and local scores
-using the corona sdk (anscamobile.com)
-
-Right now it's fairly rough around the edges and only supports some basic abilities for
-local scores. Local scores are persisted as json files.
View
@@ -0,0 +1,50 @@
+lime is a basic high score framework for saving and reloading global and local scores
+using the corona sdk (anscamobile.com)
+
+Right now it's fairly rough around the edges and only supports some basic abilities for
+local scores. Local scores are persisted as json files.
+
+= Usage
+ json = require("json")
+ lime = require("lime")
+
+ -- setup
+ --
+ -- the levelKeyFrom option takes a table of property names
+ -- that are used to generate and group scores, based off of
+ -- the optios table that you pass in at score creation
+ --
+ -- think of them as a method of creating dymanic lobbies
+ --
+ -- if levelKeyFrom is empty then scores are added into lime as an array,
+ -- treating it as a single scoreboard
+ lime.setup({
+ maxPerLevel = 10,
+ levelKeyFrom = {"difficulty", "level"}
+ })
+
+ -- add a score
+ lime.add({
+ score = player.score,
+ level = 50,
+ difficulty = "hard"
+ })
+
+ -- load all local scores for a level
+ local scores = lime.localScores({
+ level = 50,
+ difficulty = "hard"
+ })
+
+ -- get amount of scores in this level
+ print(#scores)
+
+ -- clear all scores for a level,
+ lime.clear({
+ level = 50,
+ difficulty = "hard"
+ })
+
+ -- write scores to a file
+ lime.save()
+
View
2 TODO
@@ -8,7 +8,7 @@
[x] set per board limit on scores
[x] save scores
[x] load scores
- [ ] clear scores
+ [x] clear scores
[ ] global scores
[ ] save scores on server
[ ] load scores
View
@@ -106,6 +106,16 @@ function ScoresFile:scoresFor(o)
end
end
+function ScoresFile:clearScoresFor(o)
+ local o = o or {}
+ local key = generateLevelKey(self.levelKeyFrom, o)
+ if key == '' then
+ self.scores = {}
+ else
+ self.scores[key] = {}
+ end
+end
+
function ScoresFile:add(score, o)
local key = generateLevelKey(self.levelKeyFrom, o)
local score = Score:new(score, o)
@@ -152,6 +162,7 @@ function save()
end
function clear(o)
+ return scoresFile:clearScoresFor(o)
end
function formatTimestamp(t)

0 comments on commit 3c2042b

Please sign in to comment.