Enhance version management features and localization for HMGT
This commit is contained in:
@@ -280,6 +280,7 @@ HMGT.pendingSpellPowerCosts = {}
|
||||
HMGT.demoModeData = {}
|
||||
HMGT.peerVersions = {}
|
||||
HMGT.versionWarnings = {}
|
||||
HMGT.versionWhisperWarnings = {}
|
||||
HMGT.debugBuffer = {}
|
||||
HMGT.debugBufferMax = 500
|
||||
HMGT.enabledDebugScopes = {
|
||||
@@ -484,6 +485,79 @@ function HMGT:RememberPeerProtocolVersion(playerName, protocol)
|
||||
self.peerProtocols[normalizedName] = numeric
|
||||
end
|
||||
|
||||
local function ParseVersionTokens(version)
|
||||
local tokens = {}
|
||||
local text = tostring(version or "")
|
||||
for number in string.gmatch(text, "(%d+)") do
|
||||
tokens[#tokens + 1] = tonumber(number) or 0
|
||||
end
|
||||
return tokens
|
||||
end
|
||||
|
||||
function HMGT:CompareAddonVersions(leftVersion, rightVersion)
|
||||
local left = ParseVersionTokens(leftVersion)
|
||||
local right = ParseVersionTokens(rightVersion)
|
||||
local count = math.max(#left, #right)
|
||||
for i = 1, count do
|
||||
local a = tonumber(left[i]) or 0
|
||||
local b = tonumber(right[i]) or 0
|
||||
if a ~= b then
|
||||
return (a < b) and -1 or 1
|
||||
end
|
||||
end
|
||||
|
||||
local leftText = tostring(leftVersion or "")
|
||||
local rightText = tostring(rightVersion or "")
|
||||
if leftText == rightText then
|
||||
return 0
|
||||
end
|
||||
if leftText < rightText then
|
||||
return -1
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function HMGT:IsPlayerGroupLeader()
|
||||
if not IsInGroup() and not IsInRaid() then
|
||||
return true
|
||||
end
|
||||
return UnitIsGroupLeader and UnitIsGroupLeader("player") or false
|
||||
end
|
||||
|
||||
function HMGT:SendOutdatedVersionWhisper(playerName, remoteVersion)
|
||||
local target = self:NormalizePlayerName(playerName)
|
||||
local localVersion = tostring(self.ADDON_VERSION or "dev")
|
||||
local remoteText = tostring(remoteVersion or "?")
|
||||
if not target or target == "" or not self:IsPlayerGroupLeader() then
|
||||
return false
|
||||
end
|
||||
if self:CompareAddonVersions(localVersion, remoteText) <= 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
local warningKey = string.format("%s|%s|%s", tostring(target), remoteText, localVersion)
|
||||
if self.versionWhisperWarnings[warningKey] then
|
||||
return false
|
||||
end
|
||||
self.versionWhisperWarnings[warningKey] = true
|
||||
|
||||
local message = string.format(
|
||||
L["VERSION_OUTDATED_WHISPER"] or "Your Hail Mary Guild Tools version is outdated. You have %s, the group leader has %s.",
|
||||
remoteText,
|
||||
localVersion
|
||||
)
|
||||
|
||||
if C_ChatInfo and type(C_ChatInfo.SendChatMessage) == "function" then
|
||||
C_ChatInfo.SendChatMessage(message, "WHISPER", nil, target)
|
||||
elseif type(SendChatMessage) == "function" then
|
||||
SendChatMessage(message, "WHISPER", nil, target)
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function HMGT:SendReliableAck(target, messageId)
|
||||
if not target or target == "" or not messageId or messageId == "" then
|
||||
return
|
||||
@@ -682,6 +756,12 @@ function HMGT:RegisterPeerVersion(playerName, version, protocol, sourceTag)
|
||||
if not playerName then return end
|
||||
self.peerVersions[playerName] = version
|
||||
self:RememberPeerProtocolVersion(playerName, protocol)
|
||||
if self.versionNoticeWindow and self.versionNoticeWindow.IsShown and self.versionNoticeWindow:IsShown() and self.RefreshVersionNoticeWindow then
|
||||
self:RefreshVersionNoticeWindow()
|
||||
end
|
||||
if version and version ~= "" then
|
||||
self:SendOutdatedVersionWhisper(playerName, version)
|
||||
end
|
||||
local mismatch = false
|
||||
local details = {}
|
||||
if version and version ~= "" and version ~= ADDON_VERSION then
|
||||
@@ -4436,11 +4516,17 @@ function HMGT:OnGroupRosterUpdate()
|
||||
self.remoteSpellStateRevisions[name] = nil
|
||||
self.peerVersions[name] = nil
|
||||
self.versionWarnings[name] = nil
|
||||
if self.peerProtocols then
|
||||
self.peerProtocols[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local count = 0
|
||||
for _ in pairs(validPlayers) do count = count + 1 end
|
||||
self:Debug("verbose", "OnGroupRosterUpdate validPlayers=%d", count)
|
||||
if self.versionNoticeWindow and self.versionNoticeWindow.IsShown and self.versionNoticeWindow:IsShown() and self.RefreshVersionNoticeWindow then
|
||||
self:RefreshVersionNoticeWindow()
|
||||
end
|
||||
if HMGT.TrackerManager and HMGT.TrackerManager.InvalidateAnchorLayout then
|
||||
HMGT.TrackerManager:InvalidateAnchorLayout()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user