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