diff --git a/schema/game.json b/schema/game.json index ba0d137..f35c907 100644 --- a/schema/game.json +++ b/schema/game.json @@ -74,6 +74,28 @@ }, "required": ["name"] }, + "scoreComponentMap": { + "type": "object", + "description": "A map of score components used in a game, including grades, lamps, EX score, and whatever other constructs are used.", + "properties": { + "$keyFormat": { + "type": "string", + "format": "record-key", + "minLength": 1, + "maxLength": 32 + }, + "$valueType": { + "type": "union", + "description": "If you need a component type that doesn't exist yet, contact @lemmaeof.gay", + "refs": [ + "#enum", + "#points", + "#percentage", + "#text" + ] + } + } + }, "main": { "type": "record", "description":"A record describing a game hosting leaderboards via Tsunagite.", @@ -136,26 +158,9 @@ } }, "scoreComponents": { - "type": "object", - "description": "All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used.", - "properties": { - "$keyFormat": { - "type": "string", - "format": "record-key", - "minLength": 1, - "maxLength": 32 - }, - "$valueType": { - "type": "union", - "description": "If you need a component type that doesn't exist yet, contact @lemmaeof.gay", - "refs": [ - "#enum", - "#points", - "#percentage", - "#text" - ] - } - } + "type": "ref", + "description": "All the components of a score in the game.", + "ref": "#scoreComponentMap" }, "defaultComponent": { "type": "string", diff --git a/schema/getLeaderboard.json b/schema/getLeaderboard.json index f207675..2bc3443 100644 --- a/schema/getLeaderboard.json +++ b/schema/getLeaderboard.json @@ -7,6 +7,10 @@ "type": "object", "description": "A sorted leaderboard of associated scores, with an index for assembling longer leaderboards.", "properties": { + "components": { + "type": "ref", + "ref": "dev.tsunagite.game#scoreComponentMap" + }, "scores": { "type": "array", "description": "The scores in this slice of leaderboard, sorted in descending order by the specified property.", diff --git a/scripts/getLeaderboard.lua b/scripts/getLeaderboard.lua index 3357dfc..87a0a81 100644 --- a/scripts/getLeaderboard.lua +++ b/scripts/getLeaderboard.lua @@ -1,4 +1,5 @@ --TODO: ascending sort as well? +--TODO: limit and cursor fields function handle() if not params.chart then error("chartNotFound") @@ -56,7 +57,7 @@ function handle() local rows = db.raw(query) - local result = toarray({}) + local leaderboard = toarray({}) for _, row in ipairs(rows) do local entry = {} @@ -68,8 +69,9 @@ function handle() entry["profile"] = profile end entry["score"] = db.get(row.uri) - table.insert(result, entry) + table.insert(leaderboard, entry) end + local result = {["scores"] = leaderboard, ["components"] = game.scoreComponents} return result end