mirror of
https://github.com/minetest-mods/areas.git
synced 2025-01-30 19:50:26 +01:00
De-couple from original code
* `api.lua` create separate handler for listing registered nodes, leave the areas list clean * `hud.lua` call second handler separately * `api.md` extended and clarified documentaion
This commit is contained in:
parent
4eda120fc1
commit
60d7a41c8c
7
api.lua
7
api.lua
@ -18,10 +18,15 @@ local detect_extra_protection = function(pos,area_list)
|
|||||||
return area_list
|
return area_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function areas:getRegisteredProtections(pos)
|
||||||
|
local res = {}
|
||||||
|
res = detect_extra_protection(pos,res)
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
--- Returns a list of areas that include the provided position.
|
--- Returns a list of areas that include the provided position.
|
||||||
function areas:getAreasAtPos(pos)
|
function areas:getAreasAtPos(pos)
|
||||||
local res = {}
|
local res = {}
|
||||||
res = detect_extra_protection(pos,res)
|
|
||||||
|
|
||||||
if self.store then
|
if self.store then
|
||||||
local a = self.store:get_areas_for_pos(pos, false, true)
|
local a = self.store:get_areas_for_pos(pos, false, true)
|
||||||
|
31
api.md
31
api.md
@ -5,13 +5,38 @@ Adding your protections to the HUD
|
|||||||
|
|
||||||
If you are providing an extra protection mod to work in cunjunction with the
|
If you are providing an extra protection mod to work in cunjunction with the
|
||||||
HUD feature of `areas`, you can register a callback to add your mod's code to
|
HUD feature of `areas`, you can register a callback to add your mod's code to
|
||||||
display your protection's existence. For example
|
display your protection's existence.
|
||||||
|
|
||||||
local myhandler = function(pos,arealist)
|
Registering a handler:
|
||||||
|
|
||||||
|
* `areas.register_hud_handler(handler_name) --> nil`
|
||||||
|
|
||||||
|
Handler specification:
|
||||||
|
|
||||||
|
* `handler_name(pos,area_list) --> new_area_list`
|
||||||
|
* `pos` - the position at which to check for protection coverage by your mod
|
||||||
|
* `area_list` - the current list of protected areas
|
||||||
|
* `new_area_list` - the list of protected areas, updated with your entries
|
||||||
|
|
||||||
|
Area list items:
|
||||||
|
|
||||||
|
The area list item is a map table identified with an ID, and properties
|
||||||
|
|
||||||
|
The ID should be in the format `modname:` and appended with an identifier for the protection.
|
||||||
|
|
||||||
|
Each area list item should be a table with the following properties
|
||||||
|
|
||||||
|
* `owner` - (required) the name of the protection owner
|
||||||
|
* `name` - (optional) the name of the area
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
local myhandler = function(pos,area_list)
|
||||||
local areaowner = find_my_protections(pos)
|
local areaowner = find_my_protections(pos)
|
||||||
|
|
||||||
if areaowner then
|
if areaowner then
|
||||||
arealist["mymodname"] = {
|
arealist["mymodname:first"] = {
|
||||||
name = "Protection name",
|
name = "Protection name",
|
||||||
owner = areaowner,
|
owner = areaowner,
|
||||||
}
|
}
|
||||||
|
15
hud.lua
15
hud.lua
@ -7,11 +7,24 @@ minetest.register_globalstep(function(dtime)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos = vector.round(player:getpos())
|
local pos = vector.round(player:getpos())
|
||||||
local areaStrings = {}
|
local areaStrings = {}
|
||||||
|
|
||||||
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||||
table.insert(areaStrings, ("%s [%s] (%s%s)")
|
table.insert(areaStrings, ("%s [%i] (%s%s)")
|
||||||
:format(area.name, id, area.owner,
|
:format(area.name, id, area.owner,
|
||||||
area.open and ":open" or ""))
|
area.open and ":open" or ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for id, area in pairs(areas:getRegisteredProtections(pos)) do
|
||||||
|
table.insert(
|
||||||
|
areaStrings, ("%s [%s] (%s)")
|
||||||
|
:format(
|
||||||
|
area.name or "",
|
||||||
|
id ,
|
||||||
|
area.owner
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
local areaString = "Areas:"
|
local areaString = "Areas:"
|
||||||
if #areaStrings > 0 then
|
if #areaStrings > 0 then
|
||||||
areaString = areaString.."\n"..
|
areaString = areaString.."\n"..
|
||||||
|
Loading…
Reference in New Issue
Block a user