From eeee4a8398a487c0d2f51b14c36ddb7b0cbbe4ac Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 4 Apr 2018 17:23:46 +0100 Subject: Clean up player data validation --- api_helpers.lua | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) (limited to 'api_helpers.lua') 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 -- cgit v1.2.3