Optimized Communicator.lua

torsten.philipp [03-28-18 - 19:40]
Optimized Communicator.lua
Filename
TaosGroupTools/communication/Communicator.lua
diff --git a/TaosGroupTools/communication/Communicator.lua b/TaosGroupTools/communication/Communicator.lua
index cbc1d58..f583ed1 100644
--- a/TaosGroupTools/communication/Communicator.lua
+++ b/TaosGroupTools/communication/Communicator.lua
@@ -9,6 +9,11 @@
 ]]--
 local LOG_ACTIVE = false

+local LGPS = LibStub("LibGPS2", true)
+if(not LGPS) then
+	error("Cannot load without LibGPS2")
+end
+
 local LMP = LibStub("LibMapPing")
 if(not LMP) then
 	error("Cannot load without LibMapPing")
@@ -37,30 +42,37 @@ TGU_Communicator.IsMocked = false
 function TGU_Communicator.OnMapPing(pingType, pingTag, offsetX, offsetY, isLocalPlayerOwner)
     if (LOG_ACTIVE) then
         _logger:logTrace("TGU_Communicator.OnMapPing")
-        --_logger:logDebug("pingTag; offsetX; offsetY", pingTag, offsetX, offsetY)
+        _logger:logDebug("pingTag; offsetX; offsetY", pingTag, offsetX, offsetY)
     end

-	if (pingType == MAP_PIN_TYPE_PING and
-        LMP:IsPositionOnMap(offsetX, offsetY) and
-		TGU_Communicator.IsPossiblePing(offsetX, offsetY)) then
-
-        if (LOG_ACTIVE) then
-            _logger:logDebug("SuppressPing ->", pingType, pingTag)
-        end
+	if (pingType == MAP_PIN_TYPE_PING) then
+        LGPS:PushCurrentMap()
+	    SetMapToMapListIndex(lib:GetMapIndexForUnit(pingTag))
+
+	    offsetX, offsetY = LMP:GetMapPing(pingType, pingTag)
+        if (LOG_ACTIVE) then _logger:logDebug("MapPing coords; offsetX; offsetY", offsetX, offsetY) end
+
+	    LGPS:PopCurrentMap()
+
+        if (LOG_ACTIVE) then _logger:logDebug("SuppressPing ->", pingType, pingTag) end

         LMP:SuppressPing(pingType, pingTag)

-        local abilityPing = TGU_Communicator.GetAbilityPing(offsetX)
-		local relativeUltimate = TGU_Communicator.GetRelativeUltimate(offsetY)
+        if (LMP:IsPositionOnMap(offsetX, offsetY) and
+		    TGU_Communicator.IsPossiblePing(offsetX, offsetY)) then
+
+            local abilityPing = TGU_Communicator.GetAbilityPing(offsetX)
+		    local relativeUltimate = TGU_Communicator.GetRelativeUltimate(offsetY)

-        if (LOG_ACTIVE) then
-            _logger:logDebug("pingTag; abilityPing; relativeUltimate", pingTag, abilityPing, relativeUltimate)
-        end
+            if (LOG_ACTIVE) then
+                _logger:logDebug("pingTag; abilityPing; relativeUltimate", pingTag, abilityPing, relativeUltimate)
+            end

-        if (abilityPing ~= -1 and relativeUltimate ~= -1) then
-            CALLBACK_MANAGER:FireCallbacks(TGU_MAP_PING_CHANGED, pingTag, abilityPing, relativeUltimate)
-        else
-            _logger:logError("TGU_Communicator.OnMapPing, Ping invalid abilityPing: " .. tostring(abilityPing) .. "; relativeUltimate: " .. tostring(relativeUltimate))
+            if (abilityPing ~= -1 and relativeUltimate ~= -1) then
+                CALLBACK_MANAGER:FireCallbacks(TGU_MAP_PING_CHANGED, pingTag, abilityPing, relativeUltimate)
+            else
+                _logger:logError("TGU_Communicator.OnMapPing, Ping invalid abilityPing: " .. tostring(abilityPing) .. "; relativeUltimate: " .. tostring(relativeUltimate))
+            end
         end
     end
 end
@@ -126,7 +138,12 @@ function TGU_Communicator.SendData(abilityGroup)
                 --_logger:logDebug("ultimatePing", ultimatePing)
             end

+            LGPS:PushCurrentMap()
+            SetMapToMapListIndex(GetUnitZoneIndex("player"))
+
             LMP:SetMapPing(MAP_PIN_TYPE_PING, MAP_TYPE_LOCATION_CENTERED, abilityPing, ultimatePing)
+
+            LGPS:PopCurrentMap()
         end
     else
         _logger:logError("TGU_Communicator.SendData, abilityGroup is nil.")