From ff9ebe33c81ddd13eabe056e58544b271daf877c Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Sun, 11 Dec 2022 23:57:09 +0100 Subject: [PATCH] Make panels table local --- api.lua | 41 ++++++++++++++++++++++++----------------- player_manager.lua | 4 +++- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/api.lua b/api.lua index b986fb2..520584d 100644 --- a/api.lua +++ b/api.lua @@ -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 + + + ---------------------------------------------- diff --git a/player_manager.lua b/player_manager.lua index 043b098..fe302df 100644 --- a/player_manager.lua +++ b/player_manager.lua @@ -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)