From 791666489ba7a15933ae1cc71ca92aa98f5231d2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 11 Jun 2015 17:11:15 +0100 Subject: helpers.lua -> api_helpers.lua --- api.lua | 2 +- api_helpers.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ helpers.lua | 56 -------------------------------------------------------- 3 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 api_helpers.lua delete mode 100644 helpers.lua diff --git a/api.lua b/api.lua index 6ffef7d..23573eb 100644 --- a/api.lua +++ b/api.lua @@ -18,7 +18,7 @@ awards = { show_mode = "hud" } -dofile(minetest.get_modpath("awards").."/helpers.lua") +dofile(minetest.get_modpath("awards").."/api_helpers.lua") -- Table Save Load Functions function awards.save() diff --git a/api_helpers.lua b/api_helpers.lua new file mode 100644 index 0000000..084f563 --- /dev/null +++ b/api_helpers.lua @@ -0,0 +1,56 @@ +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], "deaths", 0) + awards.tbv(awards.players[playern], "joins", 0) + awards.tbv(awards.players[playern], "chats", 0) +end + +function awards.player(name) + return awards.players[name] +end + +function awards._order_awards(name) + local done = {} + local retval = {} + local player = awards.player(name) + if player and player.unlocked then + for _,got in pairs(player.unlocked) do + if awards.def[got] then + done[got] = true + table.insert(retval,{name=got,got=true}) + end + end + end + for _,def in pairs(awards.def) do + if not done[def.name] then + table.insert(retval,{name=def.name,got=false}) + end + end + return retval +end diff --git a/helpers.lua b/helpers.lua deleted file mode 100644 index 084f563..0000000 --- a/helpers.lua +++ /dev/null @@ -1,56 +0,0 @@ -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], "deaths", 0) - awards.tbv(awards.players[playern], "joins", 0) - awards.tbv(awards.players[playern], "chats", 0) -end - -function awards.player(name) - return awards.players[name] -end - -function awards._order_awards(name) - local done = {} - local retval = {} - local player = awards.player(name) - if player and player.unlocked then - for _,got in pairs(player.unlocked) do - if awards.def[got] then - done[got] = true - table.insert(retval,{name=got,got=true}) - end - end - end - for _,def in pairs(awards.def) do - if not done[def.name] then - table.insert(retval,{name=def.name,got=false}) - end - end - return retval -end -- cgit v1.2.3