funzione update e 'cose'
parent
3e8ca771f2
commit
4f73fdec29
48
api.lua
48
api.lua
|
@ -5,8 +5,8 @@ local function clone_table() end
|
|||
Scoreboard = {
|
||||
-- player to show the scoreboard to
|
||||
player_name = "",
|
||||
-- id of the hud of the player
|
||||
hud_id = {bg_hud_id = nil, text_hud_id = nil},
|
||||
-- ids of the hud of the player
|
||||
hud_id = {},
|
||||
-- because the scoreboard is composed by a background and a text we need to
|
||||
-- define the two HUD to use later
|
||||
background_def = {
|
||||
|
@ -72,7 +72,6 @@ function Scoreboard:new(def)
|
|||
|
||||
if def.player then
|
||||
scoreboard.player_name = def.player
|
||||
scoreboard.hud_id = {bg_hud_id = nil, text_hud_id = nil}
|
||||
end
|
||||
|
||||
if def.sub_txt_elems ~= nil then
|
||||
|
@ -81,7 +80,6 @@ function Scoreboard:new(def)
|
|||
scoreboard[name] = clone_table(scoreboard.text_def)
|
||||
scoreboard[name].position = elem.position
|
||||
scoreboard[name].text = elem.text
|
||||
scoreboard.hud_id[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -91,7 +89,6 @@ function Scoreboard:new(def)
|
|||
scoreboard[name] = clone_table(scoreboard.background_def)
|
||||
scoreboard[name].position = elem.position
|
||||
scoreboard[name].text = elem.text
|
||||
scoreboard.hud_id[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -110,6 +107,8 @@ function Scoreboard:show()
|
|||
for _, name in pairs(self.sub_txt_elems) do
|
||||
self.hud_id[name] = player:hud_add(self[name])
|
||||
end
|
||||
-- check per testare
|
||||
minetest.chat_send_player(self.player_name, minetest.serialize(self.hud_id))
|
||||
end
|
||||
|
||||
|
||||
|
@ -122,10 +121,49 @@ function Scoreboard:hide()
|
|||
player:hud_remove(self.hud_id[k])
|
||||
end
|
||||
end
|
||||
-- check per testare
|
||||
minetest.chat_send_player(self.player_name, minetest.serialize(self.hud_id))
|
||||
end
|
||||
|
||||
|
||||
|
||||
function Scoreboard:update(def, txt_elems, img_elems)
|
||||
|
||||
if def ~= nil then
|
||||
for k, v in pairs(def) do
|
||||
self[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
if txt_elems ~= nil then
|
||||
|
||||
for elem, _ in pairs(txt_elems) do
|
||||
for k, v in pairs(txt_elems[elem]) do
|
||||
self[elem][k] = v
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
-----------------GETTERS----------------------
|
||||
----------------------------------------------
|
||||
|
||||
function scoreboard_lib.get_scoreboard(p_name)
|
||||
return scoreboard_lib.scoreboards[p_name]
|
||||
end
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
---------------FUNZIONI LOCALI----------------
|
||||
----------------------------------------------
|
||||
|
||||
-- code from => http://lua-users.org/wiki/CopyTable
|
||||
function clone_table(orig)
|
||||
local orig_type = type(orig)
|
||||
|
|
Loading…
Reference in New Issue