From 9e8ea201cad5d7cf8f8dc4389df0508edb6ae7ff Mon Sep 17 00:00:00 2001 From: Zughy <4279489-marco_a@users.noreply.gitlab.com> Date: Tue, 28 Jul 2020 02:20:50 +0200 Subject: [PATCH] More panels per player --- DOCS.md | 7 ++++--- api.lua | 14 ++++++++++---- init.lua | 3 +++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/DOCS.md b/DOCS.md index 5f35a31..dbdc4ac 100644 --- a/DOCS.md +++ b/DOCS.md @@ -9,7 +9,8 @@ To declare a new panel, simply do `local panel = Panel:new({parameters})` The parameters it takes are the following: -* `player`: the player to assign the panel to +* `name`: required. The panel name. Used to retrieve it via `panel_lib.get_panel(player_name, panel_name)`. +* `player`: required. The player to assign the panel to * `position`: the panel position (as in any other HUD) * `alignment`: same * `bg`: the picture to put in the background @@ -47,8 +48,8 @@ panel:update(nil, nil, {my_custom_img = { ``` updates just the text of the sub-element `my_custom_img`. -There is also a getter, to obtain the panel associated with a player -* `panel_lib.get_panel(player_name)` +## 2.2 Getters +* `panel_lib.get_panel(player_name, panel_name)`: obtains the panel associated with a player ## 3. Collaborating Something's wrong? Feel free to: diff --git a/api.lua b/api.lua index 789c31e..89b600c 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,4 @@ -panel_lib.panels = {} +panel_lib.panels = {} -- KEY: p_name; VALUE: {{"panel name" = panel}, {"panel name 2" = panel2}, ...} local function clone_table() end @@ -111,7 +111,11 @@ function Panel:new(def) end -- salvo in memoria - panel_lib.panels[def.player] = panel + if not panel_lib.panels[def.player] then + panel_lib.panels[def.player] = {} + end + + panel_lib.panels[def.player][def.name] = panel return panel end @@ -130,6 +134,7 @@ function Panel:show() for _, name in pairs(self.sub_txt_elems) do self.hud_id[name] = player:hud_add(self[name]) end + end @@ -143,6 +148,7 @@ function Panel:hide() player:hud_remove(self.hud_id[k]) end end + end @@ -190,8 +196,8 @@ end -----------------GETTERS---------------------- ---------------------------------------------- -function panel_lib.get_panel(p_name) - return panel_lib.panels[p_name] +function panel_lib.get_panel(p_name, panel_name) + return panel_lib.panels[p_name][panel_name] end diff --git a/init.lua b/init.lua index 0681251..68570ee 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,6 @@ panel_lib = {} +local version = "2.0.0-dev" dofile(minetest.get_modpath("panel_lib") .. "/api.lua") + +minetest.log("action", "[PANEL_LIB] Mod initialised, running version " .. version)