Skip to content

Commit

Permalink
add support for clearing scores and move examples to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Abica committed May 3, 2010
1 parent 00cc0ef commit 3c2042b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
5 changes: 0 additions & 5 deletions README

This file was deleted.

50 changes: 50 additions & 0 deletions README.rdoc
@@ -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()

2 changes: 1 addition & 1 deletion TODO
Expand Up @@ -8,7 +8,7 @@
[x] set per board limit on scores [x] set per board limit on scores
[x] save scores [x] save scores
[x] load scores [x] load scores
[ ] clear scores [x] clear scores
[ ] global scores [ ] global scores
[ ] save scores on server [ ] save scores on server
[ ] load scores [ ] load scores
11 changes: 11 additions & 0 deletions lime.lua
Expand Up @@ -106,6 +106,16 @@ function ScoresFile:scoresFor(o)
end end
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) function ScoresFile:add(score, o)
local key = generateLevelKey(self.levelKeyFrom, o) local key = generateLevelKey(self.levelKeyFrom, o)
local score = Score:new(score, o) local score = Score:new(score, o)
Expand Down Expand Up @@ -152,6 +162,7 @@ function save()
end end
function clear(o) function clear(o)
return scoresFile:clearScoresFor(o)
end end
function formatTimestamp(t) function formatTimestamp(t)
Expand Down

0 comments on commit 3c2042b

Please sign in to comment.