forked from nalc/awards
Move api_helpers.lua in api.lua
This commit is contained in:
parent
7c5fd79b57
commit
5de9dcb797
13
api.lua
13
api.lua
@ -39,6 +39,19 @@ function awards.load()
|
||||
end
|
||||
awards.players = {}
|
||||
end
|
||||
|
||||
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_or_nil(name)
|
||||
return awards.players[name]
|
||||
end
|
||||
|
||||
--
|
||||
-- local function make_on_reg_wrapper()
|
||||
-- return function(def)
|
||||
|
@ -1,31 +0,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_or_nil(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
|
24
gui.lua
24
gui.lua
@ -1,8 +1,28 @@
|
||||
local S = awards.gettext
|
||||
|
||||
local function 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
|
||||
|
||||
function awards.get_formspec(name, to, sid)
|
||||
local formspec = ""
|
||||
local listofawards = awards._order_awards(name)
|
||||
local listofawards = order_awards(name)
|
||||
local playerdata = awards.player(name)
|
||||
|
||||
if #listofawards == 0 then
|
||||
@ -103,7 +123,7 @@ function awards.show_to(name, to, sid, text)
|
||||
return
|
||||
end
|
||||
if text then
|
||||
local listofawards = awards._order_awards(name)
|
||||
local listofawards = order_awards(name)
|
||||
if #listofawards == 0 then
|
||||
minetest.chat_send_player(to, S("Error: No awards available."))
|
||||
return
|
||||
|
3
init.lua
3
init.lua
@ -22,7 +22,8 @@ awards = {
|
||||
|
||||
-- Internationalization support.
|
||||
awards.gettext, awards.ngettext = dofile(minetest.get_modpath("awards").."/intllib.lua")
|
||||
dofile(minetest.get_modpath("awards").."/api_helpers.lua")
|
||||
|
||||
-- Load files
|
||||
dofile(minetest.get_modpath("awards").."/api.lua")
|
||||
dofile(minetest.get_modpath("awards").."/chat_commands.lua")
|
||||
dofile(minetest.get_modpath("awards").."/gui.lua")
|
||||
|
Loading…
Reference in New Issue
Block a user