summaryrefslogtreecommitdiff
path: root/api_helpers.lua
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-04 17:23:46 +0100
committerrubenwardy <rw@rubenwardy.com>2018-04-04 17:23:46 +0100
commiteeee4a8398a487c0d2f51b14c36ddb7b0cbbe4ac (patch)
treead0db2abde53e7103351f8d008e3a100cf828b36 /api_helpers.lua
parentef19940edc20791d2342b7b68b7bb098a0abc2db (diff)
Clean up player data validation
Diffstat (limited to 'api_helpers.lua')
-rw-r--r--api_helpers.lua42
1 files changed, 7 insertions, 35 deletions
diff --git a/api_helpers.lua b/api_helpers.lua
index 88aebd4..6e4c514 100644
--- a/api_helpers.lua
+++ b/api_helpers.lua
@@ -1,40 +1,12 @@
-function awards.tbv(tb,value,default)
- if not default then
- default = {}
- end
- if not tb or type(tb) ~= "table" then
- if not value then
- value = "[NULL]"
- end
- minetest.log("error", "awards.tbv - table "..dump(value).." is null, or not a table! Dump: "..dump(tb))
- return
- end
- if not value then
- error("[ERROR] awards.tbv was not used correctly!\n"..
- "Value: '"..dump(value).."'\n"..
- "Dump:"..dump(tb))
- return
- end
- if not tb[value] then
- tb[value] = default
- end
-end
-
-function awards.assertPlayer(playern)
- awards.tbv(awards.players, playern)
- awards.tbv(awards.players[playern], "name", playern)
- awards.tbv(awards.players[playern], "unlocked")
- awards.tbv(awards.players[playern], "place")
- awards.tbv(awards.players[playern], "count")
- awards.tbv(awards.players[playern], "craft")
- awards.tbv(awards.players[playern], "eat")
- awards.tbv(awards.players[playern], "deaths", 0)
- awards.tbv(awards.players[playern], "joins", 0)
- awards.tbv(awards.players[playern], "chats", 0)
+function awards.player(name)
+ local data = awards.players[name] or {}
+ awards.players[name] = data
+ data.name = data.name or name
+ data.unlocked = data.unlocked or {}
+ return data
end
-function awards.player(name)
- awards.assertPlayer(name)
+function awards.player_or_nil(name)
return awards.players[name]
end