Quantcast

Update HereBeDragons to version 1.08-release

Jim Whitehead [10-18-15 - 17:45]
Update HereBeDragons to version 1.08-release
Filename
libs/HereBeDragons-1.0/HereBeDragons-1.0.lua
libs/HereBeDragons-1.0/HereBeDragons-Pins-1.0.lua
diff --git a/libs/HereBeDragons-1.0/HereBeDragons-1.0.lua b/libs/HereBeDragons-1.0/HereBeDragons-1.0.lua
old mode 100644
new mode 100755
index b082756..caf5bff
--- a/libs/HereBeDragons-1.0/HereBeDragons-1.0.lua
+++ b/libs/HereBeDragons-1.0/HereBeDragons-1.0.lua
@@ -18,6 +18,9 @@ HereBeDragons.transforms       = HereBeDragons.transforms or {}

 HereBeDragons.callbacks        = CBH:New(HereBeDragons, nil, nil, false)

+-- constants
+local TERRAIN_MATCH = "_terrain%d+$"
+
 -- Lua upvalues
 local PI2 = math.pi * 2
 local atan2 = math.atan2
@@ -163,7 +166,7 @@ if not oldversion or oldversion < 10 then
         local mapFile = GetMapInfo()
         if mapFile then
             -- remove phased terrain from the map names
-            mapFile = mapFile:gsub("_terrain%d+$", "")
+            mapFile = mapFile:gsub(TERRAIN_MATCH, "")

             if not mapToID[mapFile] then mapToID[mapFile] = id end
             mapData[id].mapFile = mapFile
@@ -329,7 +332,7 @@ end
 local function getMapDataTable(mapID, level)
     if not mapID then return nil end
     if type(mapID) == "string" then
-        mapID = mapID:gsub("_terrain%d+$", "")
+        mapID = mapID:gsub(TERRAIN_MATCH, "")
         mapID = mapToID[mapID]
     end
     local data = mapData[mapID]
@@ -371,7 +374,7 @@ local function UpdateCurrentPosition()

     -- we want to ignore any terrain phasings
     if mapFile then
-        mapFile = mapFile:gsub("_terrain%d+$", "")
+        mapFile = mapFile:gsub(TERRAIN_MATCH, "")
     end

     -- hack to update the mapfile for the garrison map (as it changes when the player updates his garrison)
@@ -426,7 +429,7 @@ end
 -- @param mapID numeric mapID or mapFile
 function HereBeDragons:GetLocalizedMap(mapID)
     if type(mapID) == "string" then
-        mapID = mapID:gsub("_terrain%d+$", "")
+        mapID = mapID:gsub(TERRAIN_MATCH, "")
         mapID = mapToID[mapID]
     end
     return mapData[mapID] and mapData[mapID].name or nil
@@ -436,7 +439,7 @@ end
 -- @param mapFile Map File
 function HereBeDragons:GetMapIDFromFile(mapFile)
     if mapFile then
-        mapFile = mapFile:gsub("_terrain%d+$", "")
+        mapFile = mapFile:gsub(TERRAIN_MATCH, "")
         return mapToID[mapFile]
     end
     return nil
@@ -483,7 +486,7 @@ end
 function HereBeDragons:GetNumFloors(mapID)
     if not mapID then return 0 end
     if type(mapID) == "string" then
-        mapID = mapID:gsub("_terrain%d+$", "")
+        mapID = mapID:gsub(TERRAIN_MATCH, "")
         mapID = mapToID[mapID]
     end

diff --git a/libs/HereBeDragons-1.0/HereBeDragons-Pins-1.0.lua b/libs/HereBeDragons-1.0/HereBeDragons-Pins-1.0.lua
old mode 100644
new mode 100755
index 355a786..53f2216
--- a/libs/HereBeDragons-1.0/HereBeDragons-Pins-1.0.lua
+++ b/libs/HereBeDragons-1.0/HereBeDragons-Pins-1.0.lua
@@ -1,6 +1,6 @@
 -- HereBeDragons-Pins is a library to show pins/icons on the world map and minimap

-local MAJOR, MINOR = "HereBeDragons-Pins-1.0", 7
+local MAJOR, MINOR = "HereBeDragons-Pins-1.0", 11
 assert(LibStub, MAJOR .. " requires LibStub")

 local pins, oldversion = LibStub:NewLibrary(MAJOR, MINOR)
@@ -19,6 +19,9 @@ pins.minimapPinRegistry   = pins.minimapPinRegistry or {}
 pins.worldmapPins         = pins.worldmapPins or {}
 pins.worldmapPinRegistry  = pins.worldmapPinRegistry or {}

+-- store a reference to the active minimap object
+pins.Minimap = pins.Minimap or Minimap
+
 -- upvalue lua api
 local cos, sin, max = math.cos, math.sin, math.max
 local type, pairs = type, pairs
@@ -90,7 +93,7 @@ end
 local rotateMinimap = GetCVar("rotateMinimap") == "1"

 -- is the minimap indoors or outdoors
-local indoors = GetCVar("minimapZoom")+0 == Minimap:GetZoom() and "outdoor" or "indoor"
+local indoors = GetCVar("minimapZoom")+0 == pins.Minimap:GetZoom() and "outdoor" or "indoor"

 local minimapPinCount, queueFullUpdate = 0, false
 local minimapScale, minimapShape, mapRadius, minimapWidth, minimapHeight, mapSin, mapCos
@@ -141,7 +144,7 @@ local function drawMinimapPin(pin, data)
     if dist <= 1 or data.floatOnEdge then
         pin:Show()
         pin:ClearAllPoints()
-        pin:SetPoint("CENTER", Minimap, "CENTER", diffX * minimapWidth, -diffY * minimapHeight)
+        pin:SetPoint("CENTER", pins.Minimap, "CENTER", diffX * minimapWidth, -diffY * minimapHeight)
         data.onEdge = (dist > 1)
     else
         pin:Hide()
@@ -156,7 +159,7 @@ local function UpdateMinimapPins(force)
     local mapID, mapFloor = HBD:GetPlayerZone()

     -- get data from the API for calculations
-    local zoom = Minimap:GetZoom()
+    local zoom = pins.Minimap:GetZoom()
     local diffZoom = zoom ~= lastZoom

     -- for rotating minimap support
@@ -167,7 +170,7 @@ local function UpdateMinimapPins(force)
         facing = lastFacing
     end

-    local newScale = Minimap:GetScale()
+    local newScale = pins.Minimap:GetScale()
     if minimapScale ~= newScale then
         minimapScale = newScale
         force = true
@@ -177,8 +180,8 @@ local function UpdateMinimapPins(force)
         -- minimap information
         minimapShape = GetMinimapShape and minimap_shapes[GetMinimapShape() or "ROUND"]
         mapRadius = minimap_size[indoors][zoom] / 2
-        minimapWidth = Minimap:GetWidth() / 2
-        minimapHeight = Minimap:GetHeight() / 2
+        minimapWidth = pins.Minimap:GetWidth() / 2
+        minimapHeight = pins.Minimap:GetHeight() / 2

         -- update upvalues for icon placement
         lastZoom = zoom
@@ -202,6 +205,7 @@ local function UpdateMinimapPins(force)
         minimapPinCount = 0
         for pin, data in pairs(activeMinimapPins) do
             if not data.keep then
+                pin:Hide()
                 activeMinimapPins[pin] = nil
             else
                 minimapPinCount = minimapPinCount + 1
@@ -214,7 +218,7 @@ end
 local function UpdateMinimapIconPosition()

     -- get the current map  zoom
-    local zoom = Minimap:GetZoom()
+    local zoom = pins.Minimap:GetZoom()
     local diffZoom = zoom ~= lastZoom
     -- if the map zoom changed, run a full update sweep
     if diffZoom then
@@ -236,7 +240,7 @@ local function UpdateMinimapIconPosition()
     end

     local refresh
-    local newScale = Minimap:GetScale()
+    local newScale = pins.Minimap:GetScale()
     if minimapScale ~= newScale then
         minimapScale = newScale
         refresh = true
@@ -263,12 +267,12 @@ local function UpdateMinimapIconPosition()
 end

 local function UpdateMinimapZoom()
-    local zoom = Minimap:GetZoom()
+    local zoom = pins.Minimap:GetZoom()
     if GetCVar("minimapZoom") == GetCVar("minimapInsideZoom") then
-        Minimap:SetZoom(zoom < 2 and zoom + 1 or zoom - 1)
+        pins.Minimap:SetZoom(zoom < 2 and zoom + 1 or zoom - 1)
     end
-    indoors = GetCVar("minimapZoom")+0 == Minimap:GetZoom() and "outdoor" or "indoor"
-    Minimap:SetZoom(zoom)
+    indoors = GetCVar("minimapZoom")+0 == pins.Minimap:GetZoom() and "outdoor" or "indoor"
+    pins.Minimap:SetZoom(zoom)
 end

 local function PositionWorldMapIcon(icon, data, currentMapID, currentMapFloor)
@@ -394,6 +398,8 @@ function pins:AddMinimapIconWorld(ref, icon, instanceID, x, y, floatOnEdge)

     minimapPins[icon] = t
     queueFullUpdate = true
+
+    icon:SetParent(pins.Minimap)
 end

 --- Add a icon to the minimap (mapid/floor coordinate version)
@@ -445,8 +451,9 @@ function pins:RemoveMinimapIcon(ref, icon)
     if minimapPins[icon] then
         recycle(minimapPins[icon])
         minimapPins[icon] = nil
+        activeMinimapPins[icon] = nil
     end
-    queueFullUpdate = true
+    icon:Hide()
 end

 --- Remove all minimap icons belonging to your addon (as tracked by "ref")
@@ -456,9 +463,20 @@ function pins:RemoveAllMinimapIcons(ref)
     for icon in pairs(minimapPinRegistry[ref]) do
         recycle(minimapPins[icon])
         minimapPins[icon] = nil
+        activeMinimapPins[icon] = nil
+        icon:Hide()
     end
     wipe(minimapPinRegistry[ref])
-    queueFullUpdate = true
+end
+
+--- Set the minimap object to position the pins on. Needs to support the usual functions a Minimap-type object exposes.
+-- @param minimapObject The new minimap object, or nil to restore the default
+function pins:SetMinimapObject(minimapObject)
+    pins.Minimap = minimapObject or Minimap
+    for pin in pairs(minimapPins) do
+        pin:SetParent(pins.Minimap)
+    end
+    UpdateMinimapPins(true)
 end

 --- Add a icon to the world map (x/y world coordinate version)