Make panels table local

This commit is contained in:
Zughy 2022-12-11 23:57:09 +01:00
parent e16d78deee
commit ff9ebe33c8
2 changed files with 27 additions and 18 deletions

41
api.lua
View File

@ -1,4 +1,4 @@
panel_lib.panels = {} -- KEY: p_name; VALUE: {{"panel name" = panel}, {"panel name 2" = panel2}, ...}
local panels = {} -- KEY: p_name; VALUE: {{"panel name" = panel}, {"panel name 2" = panel2}, ...}
local function clone_table() end
local function add_sub_elem() end
@ -150,10 +150,10 @@ function Panel:new(name, def)
end
-- salvo in memoria
if not panel_lib.panels[def.player] then
panel_lib.panels[def.player] = {}
if not panels[def.player] then
panels[def.player] = {}
end
panel_lib.panels[def.player][name] = panel
panels[def.player][name] = panel
return panel
end
@ -285,7 +285,7 @@ end
function Panel:remove()
panel_lib.panels[self.player_name][self.name] = nil
panels[self.player_name][self.name] = nil
local player = minetest.get_player_by_name(self.player_name)
@ -327,18 +327,6 @@ end
----------------------------------------------
-----------------GETTERS----------------------
----------------------------------------------
function panel_lib.get_panel(p_name, panel_name)
return panel_lib.panels[p_name][panel_name]
end
-------------------------------------
---------------UTILITÀ---------------
-------------------------------------
@ -349,6 +337,25 @@ end
-- internal use only
function panel_lib.remove_all(p_name)
panels[p_name] = nil
end
----------------------------------------------
-----------------GETTERS----------------------
----------------------------------------------
function panel_lib.get_panel(p_name, panel_name)
return panels[p_name][panel_name]
end
----------------------------------------------

View File

@ -4,7 +4,9 @@ minetest.register_on_leaveplayer(function(player)
-- venga effettuata prima la rimozione e poi il calcolo, causando un crash.
-- Non ho inoltre bisogno di eseguire 'hud_remove', dato che le HUD vengono
-- rimosse in automatico allo sconnettersi
local p_name = player:get_player_name()
minetest.after(0.1, function()
panel_lib.panels[player:get_player_name()] = nil
panel_lib.remove_all(p_name)
end)
end)