Fixed grouped and mocking

torsten.philipp [03-30-18 - 22:59]
Fixed grouped and mocking
Filename
TaosGroupTools/util/GroupHelper.lua
TaosGroupTools/util/ZOSMockingHelper.lua
diff --git a/TaosGroupTools/util/GroupHelper.lua b/TaosGroupTools/util/GroupHelper.lua
index 370541c..9397ce0 100644
--- a/TaosGroupTools/util/GroupHelper.lua
+++ b/TaosGroupTools/util/GroupHelper.lua
@@ -24,7 +24,7 @@ if (TaosGroupHelper == nil or TaosGroupHelper.Version == nil or TaosGroupHelper.

 	-- local members
     local name = "TaosGroupHelper"
-    local isUnitGrouped = IsUnitGrouped("player") -- Initial state
+    local isUnitGrouped = false

     --[[
         GetIsUnitGrouped Gets the current UnitGrouped state
@@ -65,6 +65,9 @@ if (TaosGroupHelper == nil or TaosGroupHelper.Version == nil or TaosGroupHelper.
 	    Called when loading UI finished
     ]]--
     local function OnPlayerActivated(eventCode)
+        -- Initial state
+        isUnitGrouped = IsUnitGrouped("player")
+
         CALLBACK_MANAGER:FireCallbacks(TAO_UNIT_GROUPED_CHANGED, isUnitGrouped)
         CALLBACK_MANAGER:FireCallbacks(TAO_GROUP_CHANGED)
     end
diff --git a/TaosGroupTools/util/ZOSMockingHelper.lua b/TaosGroupTools/util/ZOSMockingHelper.lua
index 5c49b80..dfc5195 100644
--- a/TaosGroupTools/util/ZOSMockingHelper.lua
+++ b/TaosGroupTools/util/ZOSMockingHelper.lua
@@ -18,11 +18,19 @@ if (TaosZOSMockingHelper == nil or TaosZOSMockingHelper.Version == nil or TaosZO
 	TaosZOSMockingHelper.__index = TaosZOSMockingHelper
     TaosZOSMockingHelper.Version = VERSION

+    local oldGetUnitName = nil
+    local oldIsUnitDead = nil
+    local oldIsUnitGrouped = nil
+
     --[[
-	    Mocks GetUnitName, returns always playerTag
+	    Mocks GetUnitName, returns always playerTag if not "player"
     ]]--
     local function GetUnitNameMock(playerTag)
-        return playerTag
+        if (playerTag == "player" and oldGetUnitName ~= nil) then
+            return oldGetUnitName(playerTag)
+        else
+            return playerTag
+        end
     end

     --[[
@@ -43,8 +51,16 @@ if (TaosZOSMockingHelper == nil or TaosZOSMockingHelper.Version == nil or TaosZO
 	    Mocks needed ZOS methods with mock methods
     ]]--
     function MockZOSMethods()
+        -- Mock GetUnitName
+        oldGetUnitName = GetUnitName
         GetUnitName = GetUnitNameMock
+
+        -- Mock IsUnitDead
+        oldIsUnitDead = IsUnitDead
         IsUnitDead = IsUnitDeadMock
+
+        -- Mock IsUnitGrouped
+        oldIsUnitGrouped = IsUnitGrouped
         IsUnitGrouped = IsUnitGroupedMock
     end
 end
\ No newline at end of file