From 23f81f6278af2269bb11f41ec424936b05c2655f Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sun, 4 Dec 2016 04:12:14 +0000 Subject: [PATCH 1/4] Add mod.conf --- mod.conf | 1 + 1 file changed, 1 insertion(+) create mode 100644 mod.conf diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..0ca8ec1 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = areas From 6080ff065ea89e899f356ba723ea2467b6d32ccb Mon Sep 17 00:00:00 2001 From: "Tai @ Flex" Date: Sat, 26 Nov 2016 07:20:23 +0000 Subject: [PATCH 2/4] Add API for adding areas to HUD --- api.lua | 16 ++++++++++++++++ api.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ hud.lua | 10 ++++++++++ 3 files changed, 71 insertions(+) create mode 100644 api.md diff --git a/api.lua b/api.lua index e8b9c7a..730e96d 100644 --- a/api.lua +++ b/api.lua @@ -1,7 +1,23 @@ +local hudHandlers = {} + +--- Adds a function as a HUD handler, it will be able to add items to the Areas HUD element. +function areas:registerHudHandler(handler) + table.insert(hudHandlers, handler) +end + + +function areas:getExternalHudEntries(pos) + local areas = {} + for _, func in pairs(hudHandlers) do + func(pos, areas) + end + return areas +end --- Returns a list of areas that include the provided position. function areas:getAreasAtPos(pos) local res = {} + if self.store then local a = self.store:get_areas_for_pos(pos, false, true) for store_id, store_area in pairs(a) do diff --git a/api.md b/api.md new file mode 100644 index 0000000..c74b4c7 --- /dev/null +++ b/api.md @@ -0,0 +1,45 @@ +Areas mod API +=== + +API list +--- + + * `areas.registerHudHandler(handler)` - Registers a handler to add items to the Areas HUD. See [HUD](#hud). + + +HUD +--- + +If you are making a protection mod or a similar mod that adds invisible regions +to the world, and you would like then to show up in the areas HUD element, you +can register a callback to show your areas. + +HUD handler specification: + + * `handler(pos, list)` + * `pos` - The position to check. + * `list` - The list of area HUD elements, this should be modified in-place. + +The area list item is a table containing a list of tables with the following fields: + + * `id` - An identifier for the area. This should be a unique string in the format `mod:id`. + * `name` - The name of the area. + * `owner` - The player name of the region owner, if any. + +All of the fields are optional but at least one of them must be set. + +### Example + + local function areas_hud_handler(pos, areas) + local val = find_my_protection(pos) + + if val then + table.insert(areas, { + id = "mod:"..val.id, + name = val.name, + owner = val.owner, + }) + end + end + + areas:registerHudHandler(areas_hud_handler) diff --git a/hud.lua b/hud.lua index 4908b92..0b7931f 100644 --- a/hud.lua +++ b/hud.lua @@ -7,11 +7,21 @@ minetest.register_globalstep(function(dtime) local name = player:get_player_name() local pos = vector.round(player:getpos()) local areaStrings = {} + for id, area in pairs(areas:getAreasAtPos(pos)) do table.insert(areaStrings, ("%s [%u] (%s%s)") :format(area.name, id, area.owner, area.open and ":open" or "")) end + + for i, area in pairs(areas:getExternalHudEntries(pos)) do + local str = "" + if area.name then str = area.name .. " " end + if area.id then str = str.."["..area.id.."] " end + if area.owner then str = str.."("..area.owner..")" end + table.insert(areaStrings, str) + end + local areaString = "Areas:" if #areaStrings > 0 then areaString = areaString.."\n".. From d3d43d951154fb2b9e30186f7a1e52bd05ae6d80 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sat, 6 May 2017 10:41:45 -0700 Subject: [PATCH 3/4] Reference 'settings.lua' instead of 'config.lua' (#21) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd6a54d..f7c07c6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Configuration If you wish to specify configuration options, such as whether players are allowed to protect their own areas with the `protect` command (disabled by -default), you should check config.lua and set the appropriate settings in your +default), you should check settings.lua and set the appropriate settings in your server's configuration file (probably `minetest.conf`). From 289d0e623c1d383f26cbc57c94ce9a8a184bf525 Mon Sep 17 00:00:00 2001 From: AntumDeluge Date: Sat, 13 May 2017 01:59:30 -0700 Subject: [PATCH 4/4] Update usage of settings API --- init.lua | 2 +- settings.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 2c10cdd..d1b7ebe 100644 --- a/init.lua +++ b/init.lua @@ -32,7 +32,7 @@ if not minetest.registered_privileges[areas.config.self_protection_privilege] th }) end -if minetest.setting_getbool("log_mod") then +if minetest.settings:get_bool("log_mod") then local diffTime = os.clock() - areas.startTime minetest.log("action", "areas loaded in "..diffTime.."s.") end diff --git a/settings.lua b/settings.lua index 140a655..ffb5355 100644 --- a/settings.lua +++ b/settings.lua @@ -6,13 +6,13 @@ local function setting(tp, name, default) local full_name = "areas."..name local value if tp == "boolean" then - value = minetest.setting_getbool(full_name) + value = minetest.settings:get_bool(full_name) elseif tp == "string" then - value = minetest.setting_get(full_name) + value = minetest.settings:get(full_name) elseif tp == "position" then value = minetest.setting_get_pos(full_name) elseif tp == "number" then - value = tonumber(minetest.setting_get(full_name)) + value = tonumber(minetest.settings:get(full_name)) else error("Invalid setting type!") end