rename Core -> HailMaryGuildTools_Bridge
This commit is contained in:
145
HailMaryGuildTools_Bridge.lua
Normal file
145
HailMaryGuildTools_Bridge.lua
Normal file
@@ -0,0 +1,145 @@
|
||||
local ADDON_NAME = ...
|
||||
local HMGT = _G.HailMaryGuildTools
|
||||
if not HMGT then return end
|
||||
|
||||
local Bridge = {
|
||||
name = ADDON_NAME or "HailMaryGuildTools_Bridge",
|
||||
adapters = {},
|
||||
stats = {
|
||||
received = 0,
|
||||
hello = 0,
|
||||
helloSync = 0,
|
||||
kick = 0,
|
||||
appliedKnown = 0,
|
||||
appliedSpec = 0,
|
||||
appliedCooldown = 0,
|
||||
rejected = 0,
|
||||
},
|
||||
}
|
||||
|
||||
_G.HMGT_Bridge = Bridge
|
||||
HMGT.Bridge = Bridge
|
||||
|
||||
local function SafeText(value)
|
||||
if type(issecretvalue) == "function" and issecretvalue(value) then
|
||||
return nil
|
||||
end
|
||||
return tostring(value or "")
|
||||
end
|
||||
|
||||
function Bridge:RegisterAdapter(adapter)
|
||||
if type(adapter) ~= "table" or not adapter.key then
|
||||
return false
|
||||
end
|
||||
self.adapters[adapter.key] = adapter
|
||||
return true
|
||||
end
|
||||
|
||||
function Bridge:Count(key)
|
||||
self.stats = self.stats or {}
|
||||
self.stats[key] = (tonumber(self.stats[key]) or 0) + 1
|
||||
end
|
||||
|
||||
function Bridge:RememberResult(action, ok, reason, details)
|
||||
self.lastResult = {
|
||||
action = action,
|
||||
ok = ok and true or false,
|
||||
reason = reason,
|
||||
details = details,
|
||||
time = time and time() or nil,
|
||||
}
|
||||
|
||||
if ok then
|
||||
if action == "known" then
|
||||
self:Count("appliedKnown")
|
||||
elseif action == "spec" then
|
||||
self:Count("appliedSpec")
|
||||
elseif action == "cooldown" then
|
||||
self:Count("appliedCooldown")
|
||||
end
|
||||
else
|
||||
self:Count("rejected")
|
||||
end
|
||||
end
|
||||
|
||||
function Bridge:GetStatusLines()
|
||||
local stats = self.stats or {}
|
||||
local lines = {
|
||||
"HMGT Bridge status",
|
||||
string.format("Adapters: %d", self.adapters and (self.adapters["BliZzi_Interrupts"] and 1 or 0) or 0),
|
||||
string.format(
|
||||
"Messages: received=%d hello=%d helloSync=%d kick=%d",
|
||||
tonumber(stats.received) or 0,
|
||||
tonumber(stats.hello) or 0,
|
||||
tonumber(stats.helloSync) or 0,
|
||||
tonumber(stats.kick) or 0
|
||||
),
|
||||
string.format(
|
||||
"Applied: known=%d spec=%d cooldown=%d rejected=%d",
|
||||
tonumber(stats.appliedKnown) or 0,
|
||||
tonumber(stats.appliedSpec) or 0,
|
||||
tonumber(stats.appliedCooldown) or 0,
|
||||
tonumber(stats.rejected) or 0
|
||||
),
|
||||
}
|
||||
|
||||
if self.lastResult then
|
||||
local result = self.lastResult
|
||||
lines[#lines + 1] = string.format(
|
||||
"Last: action=%s ok=%s reason=%s details=%s",
|
||||
tostring(result.action or "?"),
|
||||
tostring(result.ok),
|
||||
tostring(result.reason or "-"),
|
||||
tostring(result.details or "-")
|
||||
)
|
||||
else
|
||||
lines[#lines + 1] = "Last: no BliZzi message seen yet"
|
||||
end
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
function Bridge:GetAdapter(key)
|
||||
return self.adapters[key]
|
||||
end
|
||||
|
||||
function Bridge:NormalizePlayerName(name)
|
||||
if HMGT and HMGT.NormalizePlayerName then
|
||||
return HMGT:NormalizePlayerName(name)
|
||||
end
|
||||
return SafeText(name)
|
||||
end
|
||||
|
||||
function Bridge:ApplyKnownSpell(sourceName, playerName, spellId, class, cooldown)
|
||||
if HMGT and HMGT.ApplyExternalKnownSpell then
|
||||
local ok, reason = HMGT:ApplyExternalKnownSpell(sourceName, playerName, spellId, class, cooldown)
|
||||
self:RememberResult("known", ok, reason, string.format("%s:%s", tostring(playerName), tostring(spellId)))
|
||||
return ok, reason
|
||||
end
|
||||
self:RememberResult("known", false, "hmgt_api_missing")
|
||||
return false, "hmgt_api_missing"
|
||||
end
|
||||
|
||||
function Bridge:ApplySpecInfo(sourceName, playerName, class, specId, talentString)
|
||||
if HMGT and HMGT.ApplyExternalSpecInfo then
|
||||
local ok, reason = HMGT:ApplyExternalSpecInfo(sourceName, playerName, class, specId, talentString)
|
||||
self:RememberResult("spec", ok, reason, string.format("%s:%s", tostring(playerName), tostring(specId)))
|
||||
return ok, reason
|
||||
end
|
||||
self:RememberResult("spec", false, "hmgt_api_missing")
|
||||
return false, "hmgt_api_missing"
|
||||
end
|
||||
|
||||
function Bridge:ApplyCooldown(sourceName, playerName, spellId, cooldown)
|
||||
if HMGT and HMGT.ApplyExternalCooldown then
|
||||
local ok, reason = HMGT:ApplyExternalCooldown(sourceName, playerName, spellId, cooldown)
|
||||
self:RememberResult("cooldown", ok, reason, string.format("%s:%s:%s", tostring(playerName), tostring(spellId), tostring(cooldown)))
|
||||
return ok, reason
|
||||
end
|
||||
self:RememberResult("cooldown", false, "hmgt_api_missing")
|
||||
return false, "hmgt_api_missing"
|
||||
end
|
||||
|
||||
function Bridge:SafeText(value)
|
||||
return SafeText(value)
|
||||
end
|
||||
Reference in New Issue
Block a user