diff --git a/TaosGroupTools/Defaults.lua b/TaosGroupTools/Defaults.lua index b53554c..0af1a47 100644 --- a/TaosGroupTools/Defaults.lua +++ b/TaosGroupTools/Defaults.lua @@ -1,40 +1,40 @@ ---[[ - Addon: Taos Group Tools - Author: TProg Taonnor - Created by @Taonnor -]]-- - ---[[ - Default variables -]]-- - -TGT_DEFAULTS = -{ - -- Global settings - ["Movable"] = true, - ["IsGroupUltimateEnabled"] = true, - - -- Group Ultimate settings - ["OnlyAva"] = false, - ["Style"] = 3, - -- Positioning - ["PosX"] = 0, - ["PosY"] = 0, - ["SelectorPosX"] = 0, - ["SelectorPosY"] = 0, - -- Lane settings - ["IsSortingActive"] = false, - ["StaticUltimateID"] = - { - ["Default"] = 29861, - }, - ["SwimlaneUltimateGroupIds"] = - { - [1] = 29861, - [2] = 27413, - [3] = 86536, - [4] = 86112, - [5] = 46537, - [6] = 46622, - }, +--[[ + Addon: Taos Group Tools + Author: TProg Taonnor + Created by @Taonnor +]]-- + +--[[ + Default variables +]]-- + +TGT_DEFAULTS = +{ + -- Global settings + ["Movable"] = true, + ["IsGroupUltimateEnabled"] = true, + + -- Group Ultimate settings + ["OnlyAva"] = false, + ["Style"] = 3, + -- Positioning + ["PosX"] = 0, + ["PosY"] = 0, + ["SelectorPosX"] = 0, + ["SelectorPosY"] = 0, + -- Lane settings + ["IsSortingActive"] = false, + ["StaticUltimateID"] = + { + ["Default"] = 29861, + }, + ["SwimlaneUltimateGroupIds"] = + { + [1] = 29861, + [2] = 27413, + [3] = 86536, + [4] = 86112, + [5] = 46537, + [6] = 46622, + }, } \ No newline at end of file diff --git a/TaosGroupTools/TaosGroupTools.lua b/TaosGroupTools/TaosGroupTools.lua index a7f6f25..46a1bd2 100644 --- a/TaosGroupTools/TaosGroupTools.lua +++ b/TaosGroupTools/TaosGroupTools.lua @@ -40,6 +40,11 @@ function TaosGroupTools:initialize() local logger = TaosDebugLogger(LOG_NAME, LOG_COMMAND, TRACE_ACTIVE, DEBUG_ACTIVE, ERROR_ACTIVE, DIRECT_PRINT, CATCH_LUA_ERRORS) logger:logTrace("TaosGroupTools:initialize") + -- If mocking active, mock ZOS methods with mock methods + if (ISMOCKED) then + MockZOSMethods() + end + -- Initialize settings TGT_SettingsHandler.Initialize(logger) @@ -47,7 +52,7 @@ function TaosGroupTools:initialize() TGT_Communicator.Initialize(logger, ISMOCKED) -- Initialize logic - TGT_MapPingHandler.Initialize(logger, ISMOCKED) + TGT_MapPingHandler.Initialize(logger) TGT_UltimateGroupHandler.Initialize(logger) TGT_CommandsHandler.Initialize(logger) @@ -57,9 +62,9 @@ function TaosGroupTools:initialize() TGT_UltimateGroupMenu.Initialize(logger) TGT_GroupUltimateSelector.Initialize(logger) - TGT_SimpleList.Initialize(logger, ISMOCKED) - TGT_SwimlaneList.Initialize(logger, ISMOCKED) - TGT_CompactSwimlaneList.Initialize(logger, ISMOCKED) + TGT_SimpleList.Initialize(logger) + TGT_SwimlaneList.Initialize(logger) + TGT_CompactSwimlaneList.Initialize(logger) logger:logTrace("TaosGroupTools:initialized") end diff --git a/TaosGroupTools/TaosGroupTools.txt b/TaosGroupTools/TaosGroupTools.txt index 394c23f..d7a9a08 100644 --- a/TaosGroupTools/TaosGroupTools.txt +++ b/TaosGroupTools/TaosGroupTools.txt @@ -29,6 +29,7 @@ i18n/$(language).lua util/DebugLogger.lua util/UiHelper.lua util/GroupHelper.lua +util/ZOSMockingHelper.lua communication/Communicator.lua communication/UltimateHandler.lua diff --git a/TaosGroupTools/logic/MapPingHandler.lua b/TaosGroupTools/logic/MapPingHandler.lua index 2897d6c..f25202b 100644 --- a/TaosGroupTools/logic/MapPingHandler.lua +++ b/TaosGroupTools/logic/MapPingHandler.lua @@ -27,7 +27,6 @@ TGT_MapPingHandler.__index = TGT_MapPingHandler Table Members ]]-- TGT_MapPingHandler.Name = "TGT-MapPingHandler" -TGT_MapPingHandler.IsMocked = false --[[ Called on new data from Communication @@ -42,13 +41,8 @@ function TGT_MapPingHandler.OnData(pingTag, abilityPing, relativeUltimate) local playerName = "" local isPlayerDead = false - if (TGT_MapPingHandler.IsMocked == false) then - playerName = GetUnitName(pingTag) - isPlayerDead = IsUnitDead(pingTag) - else - playerName = pingTag - isPlayerDead = math.random() > 0.8 - end + playerName = GetUnitName(pingTag) + isPlayerDead = IsUnitDead(pingTag) player.PingTag = pingTag player.PlayerName = playerName @@ -78,30 +72,28 @@ end function TGT_MapPingHandler.OnTimedUpdate(eventCode) if (LOG_ACTIVE) then _logger:logTrace("TGT_MapPingHandler.OnTimedUpdate") end - if (IsUnitGrouped("player") == false and TGT_MapPingHandler.IsMocked == false) then return end -- only if player is in group and system is not mocked + -- only if player is in group + if (IsUnitGrouped("player")) then + local abilityGroup = TGT_UltimateGroupHandler.GetUltimateGroupByAbilityId(TGT_SettingsHandler.GetStaticUltimateIDSettings()) - local abilityGroup = TGT_UltimateGroupHandler.GetUltimateGroupByAbilityId(TGT_SettingsHandler.GetStaticUltimateIDSettings()) - - if (abilityGroup ~= nil) then - TGT_Communicator.SendData(abilityGroup) - else - _logger:logError("TGT_MapPingHandler.OnTimedUpdate, abilityGroup is nil, change ultimate. StaticID: " .. tostring(TGT_SettingsHandler.GetStaticUltimateIDSettings())) + if (abilityGroup ~= nil) then + TGT_Communicator.SendData(abilityGroup) + else + _logger:logError("TGT_MapPingHandler.OnTimedUpdate, abilityGroup is nil, change ultimate. StaticID: " .. tostring(TGT_SettingsHandler.GetStaticUltimateIDSettings())) + end end end --[[ Initialize initializes TGT_MapPingHandler ]]-- -function TGT_MapPingHandler.Initialize(logger, isMocked) +function TGT_MapPingHandler.Initialize(logger) if (LOG_ACTIVE) then logger:logTrace("TGT_MapPingHandler.Initialize") - logger:logDebug("isMocked", isMocked) end _logger = logger - TGT_MapPingHandler.IsMocked = isMocked - -- Register callbacks CALLBACK_MANAGER:RegisterCallback(TGT_MAP_PING_CHANGED, TGT_MapPingHandler.OnData) diff --git a/TaosGroupTools/ui/groupultimate/CompactSwimlaneList.lua b/TaosGroupTools/ui/groupultimate/CompactSwimlaneList.lua index 2e2152f..e493591 100644 --- a/TaosGroupTools/ui/groupultimate/CompactSwimlaneList.lua +++ b/TaosGroupTools/ui/groupultimate/CompactSwimlaneList.lua @@ -27,7 +27,6 @@ TGT_CompactSwimlaneList.__index = TGT_CompactSwimlaneList Table Members ]]-- TGT_CompactSwimlaneList.Name = "TGT-CompactSwimlaneList" -TGT_CompactSwimlaneList.IsMocked = false TGT_CompactSwimlaneList.Swimlanes = {} --[[ @@ -228,11 +227,6 @@ function TGT_CompactSwimlaneList.ClearPlayersFromSwimlane(swimlane) if (swimlanePlayer ~= nil) then local isPlayerNotGrouped = IsUnitGrouped(swimlanePlayer.PingTag) == false - - if (TGT_CompactSwimlaneList.IsMocked) then - isPlayerNotGrouped = false - end - local isPlayerTimedOut = (GetTimeStamp() - swimlanePlayer.LastMapPingTimestamp) > TIMEOUT local isPlayerUltimateNotCorrect = swimlane.UltimateGroupId ~= swimlanePlayer.UltimateGroup.GroupAbilityId @@ -482,7 +476,7 @@ end --[[ Initialize initializes TGT_CompactSwimlaneList ]]-- -function TGT_CompactSwimlaneList.Initialize(logger, isMocked) +function TGT_CompactSwimlaneList.Initialize(logger) if (LOG_ACTIVE) then logger:logTrace("TGT_CompactSwimlaneList.Initialize") end @@ -490,8 +484,6 @@ function TGT_CompactSwimlaneList.Initialize(logger, isMocked) _logger = logger _control = TGT_CompactSwimlaneListControl - TGT_CompactSwimlaneList.IsMocked = isMocked - TGT_CompactSwimlaneList.CreateCompactSwimlaneListHeaders() TGT_CompactSwimlaneList.SetControlActive() diff --git a/TaosGroupTools/ui/groupultimate/SimpleList.lua b/TaosGroupTools/ui/groupultimate/SimpleList.lua index e8d8f81..07be286 100644 --- a/TaosGroupTools/ui/groupultimate/SimpleList.lua +++ b/TaosGroupTools/ui/groupultimate/SimpleList.lua @@ -25,7 +25,6 @@ TGT_SimpleList.__index = TGT_SimpleList --[[ Table Members ]]-- -TGT_SimpleList.IsMocked = false --[[ Sets visibility of labels @@ -39,11 +38,6 @@ function TGT_SimpleList.RefreshList() if (listPlayer ~= nil) then local isPlayerNotGrouped = IsUnitGrouped(listPlayer.PingTag) == false - - if (TGT_SimpleList.IsMocked) then - isPlayerNotGrouped = false - end - local isPlayerTimedOut = (GetTimeStamp() - listPlayer.LastMapPingTimestamp) > TIMEOUT if (isPlayerNotGrouped or isPlayerTimedOut) then @@ -303,7 +297,7 @@ end --[[ Initialize initializes TGT_SimpleList ]]-- -function TGT_SimpleList.Initialize(logger, isMocked) +function TGT_SimpleList.Initialize(logger) if (LOG_ACTIVE) then logger:logTrace("TGT_SimpleList.Initialize") end @@ -311,8 +305,6 @@ function TGT_SimpleList.Initialize(logger, isMocked) _logger = logger _control = TGT_SimpleListControl - TGT_SimpleList.IsMocked = isMocked - TGT_SimpleList.CreateSimpleListRows() TGT_SimpleList.SetControlActive() diff --git a/TaosGroupTools/ui/groupultimate/SwimlaneList.lua b/TaosGroupTools/ui/groupultimate/SwimlaneList.lua index 43d6501..046d6ef 100644 --- a/TaosGroupTools/ui/groupultimate/SwimlaneList.lua +++ b/TaosGroupTools/ui/groupultimate/SwimlaneList.lua @@ -27,7 +27,6 @@ TGT_SwimlaneList.__index = TGT_SwimlaneList Table Members ]]-- TGT_SwimlaneList.Name = "TGT-SwimlaneList" -TGT_SwimlaneList.IsMocked = false TGT_SwimlaneList.Swimlanes = {} --[[ @@ -228,11 +227,6 @@ function TGT_SwimlaneList.ClearPlayersFromSwimlane(swimlane) if (swimlanePlayer ~= nil) then local isPlayerNotGrouped = IsUnitGrouped(swimlanePlayer.PingTag) == false - - if (TGT_SwimlaneList.IsMocked) then - isPlayerNotGrouped = false - end - local isPlayerTimedOut = (GetTimeStamp() - swimlanePlayer.LastMapPingTimestamp) > TIMEOUT local isPlayerUltimateNotCorrect = swimlane.UltimateGroupId ~= swimlanePlayer.UltimateGroup.GroupAbilityId @@ -483,7 +477,7 @@ end --[[ Initialize initializes TGT_SwimlaneList ]]-- -function TGT_SwimlaneList.Initialize(logger, isMocked) +function TGT_SwimlaneList.Initialize(logger) if (LOG_ACTIVE) then logger:logTrace("TGT_SwimlaneList.Initialize") end @@ -491,8 +485,6 @@ function TGT_SwimlaneList.Initialize(logger, isMocked) _logger = logger _control = TGT_SwimlaneListControl - TGT_SwimlaneList.IsMocked = isMocked - TGT_SwimlaneList.CreateSwimLaneListHeaders() TGT_SwimlaneList.SetControlActive() diff --git a/TaosGroupTools/util/ZOSMockingHelper.lua b/TaosGroupTools/util/ZOSMockingHelper.lua new file mode 100644 index 0000000..5c49b80 --- /dev/null +++ b/TaosGroupTools/util/ZOSMockingHelper.lua @@ -0,0 +1,50 @@ +--[[ + Addon: util + Author: TProg Taonnor + Created by @Taonnor +]]-- + +-- Version Control +local VERSION = 1 + +--[[ + Class definition (Static class) +]]-- +-- A table in hole lua workspace must be unique +-- The ui helper is global util table, used in several of my addons +-- The table is created as "static" class without constructor and static helper methods +if (TaosZOSMockingHelper == nil or TaosZOSMockingHelper.Version == nil or TaosZOSMockingHelper.Version < VERSION) then + TaosZOSMockingHelper = {} + TaosZOSMockingHelper.__index = TaosZOSMockingHelper + TaosZOSMockingHelper.Version = VERSION + + --[[ + Mocks GetUnitName, returns always playerTag + ]]-- + local function GetUnitNameMock(playerTag) + return playerTag + end + + --[[ + Mocks IsUnitDead, returns randomly unit death + ]]-- + local function IsUnitDeadMock(playerTag) + return math.random() > 0.8 + end + + --[[ + Mocks IsUnitGrouped, returns always player in group + ]]-- + local function IsUnitGroupedMock(playerTag) + return true + end + + --[[ + Mocks needed ZOS methods with mock methods + ]]-- + function MockZOSMethods() + GetUnitName = GetUnitNameMock + IsUnitDead = IsUnitDeadMock + IsUnitGrouped = IsUnitGroupedMock + end +end \ No newline at end of file