Add improvements by taikedz and EdwardThorsten

* add protector blocks to hud
* change from unknown source
* add mod explicit name
* Add handler for other mods to advise protection
  * Allow other mods to register a handler to display protected areas in the hud
  * remove the protector mod specific code from this areas code
* support non-numeric IDs
* adjusted handler registration name
* add API documentation for modding extension
* rename to explicit variables
* 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
* fixed typo in documentation
* ignore vim cache files
* adjust handler registration function name
* reinstate the format string unsigned int]
* reverting auth change
* restore code style, adjust further style
* added space for stylistic imrpovement
* stylistic fixes etc
* Merge branch 'master' of https://github.com/ShadowNinja/areas
  *Merge ShadowNinja's version
* Cleaning up deprecated calls.
* Merge pull request #1 from EdwardThorsten/master
  *Cleaning up deprecated calls.
This commit is contained in:
Muhammad Nur Hidayat Yasuyoshi (MNH48.com) 2018-02-17 00:19:58 +08:00 committed by GitHub
commit 41bba581a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*~
*.swp

View File

@ -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

47
api.md
View File

@ -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
===