diff --git a/.gitignore b/.gitignore index 5236e1e..70bb2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ +*.swp diff --git a/api.lua b/api.lua index 730e96d..c379b3d 100644 --- a/api.lua +++ b/api.lua @@ -29,9 +29,9 @@ function areas:getAreasAtPos(pos) for id, area in pairs(self.areas) do local ap1, ap2 = area.pos1, area.pos2 if - (px >= ap1.x and px <= ap2.x) and - (py >= ap1.y and py <= ap2.y) and - (pz >= ap1.z and pz <= ap2.z) then + (px >= ap1.x and px <= ap2.x) and + (py >= ap1.y and py <= ap2.y) and + (pz >= ap1.z and pz <= ap2.z) then res[id] = area end end diff --git a/api.md b/api.md index c74b4c7..d0e08eb 100644 --- a/api.md +++ b/api.md @@ -1,3 +1,50 @@ +# API Extension + +Adding your protections to the HUD +---------------------------------- + +If you are providing an extra protection mod to work in conjunction with the +HUD feature of `areas`, you can register a callback to add your mod's code to +display your protection's existence. + +Registering a handler: + +* `areas.registerHudHandler(handler) --> nil` + +Handler specification: + +* `handler(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) + + if areaowner then + arealist["mymodname:first"] = { + name = "Protection name", + owner = areaowner, + } + end + end + + areas.register_hud_handler(myhandler) +======= Areas mod API ===