adam@0: local _, AskMrRobot = ... yellowfive@11: local L = AskMrRobot.L; adam@0: adam@17: -- initialize the CombatLogTab class adam@0: AskMrRobot.CombatLogTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame) adam@0: adam@17: -- these are valid keys in AmrDb.LogData, all others will be deleted yellowfive@11: local _logDataKeys = { yellowfive@11: ["_logging"] = true, yellowfive@11: ["_autoLog"] = true, yellowfive@11: ["_lastZone"] = true, yellowfive@11: ["_lastDiff"] = true, yellowfive@11: ["_current2"] = true, yellowfive@11: ["_history2"] = true, yellowfive@11: ["_wipes"] = true, yellowfive@11: ["_lastWipe"] = true, yellowfive@11: ["_currentExtra"] = true, yellowfive@11: ["_historyExtra"] = true yellowfive@11: }; yellowfive@11: yellowfive@11: local _undoButton = false yellowfive@11: adam@0: -- helper to create text for this tab adam@0: local function CreateText(tab, font, relativeTo, xOffset, yOffset, text) adam@0: local t = tab:CreateFontString(nil, "ARTWORK", font) adam@0: t:SetPoint("TOPLEFT", relativeTo, "BOTTOMLEFT", xOffset, yOffset) yellowfive@11: t:SetPoint("RIGHT", tab, "RIGHT", -5, 0) adam@0: t:SetWidth(t:GetWidth()) adam@0: t:SetJustifyH("LEFT") adam@0: t:SetText(text) adam@0: adam@0: return t adam@0: end adam@0: adam@0: local function newCheckbox(tab, label, tooltipTitle, description, onClick) adam@0: local check = CreateFrame("CheckButton", "AmrCheck" .. label, tab, "InterfaceOptionsCheckButtonTemplate") adam@0: check:SetScript("OnClick", function(self) adam@0: PlaySound(self:GetChecked() and "igMainMenuOptionCheckBoxOn" or "igMainMenuOptionCheckBoxOff") adam@0: onClick(self, self:GetChecked() and true or false) adam@0: end) adam@0: check.label = _G[check:GetName() .. "Text"] adam@0: check.label:SetText(label) adam@0: check.tooltipText = tooltipTitle adam@0: check.tooltipRequirement = description adam@0: return check adam@0: end adam@0: adam@0: function AskMrRobot.CombatLogTab:new(parent) adam@0: yellowfive@11: local tab = AskMrRobot.Frame:new(nil, parent) adam@0: setmetatable(tab, { __index = AskMrRobot.CombatLogTab }) adam@0: tab:SetPoint("TOPLEFT") adam@0: tab:SetPoint("BOTTOMRIGHT") adam@0: tab:Hide() adam@0: yellowfive@11: -- tab header adam@0: local text = tab:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") adam@0: text:SetPoint("TOPLEFT", 0, -5) yellowfive@49: text:SetText(L.AMR_COMBATLOGTAB_COMBAT_LOGGING) yellowfive@11: yellowfive@11: --scrollframe yellowfive@11: tab.scrollframe = AskMrRobot.ScrollFrame:new(nil, tab) yellowfive@11: tab.scrollframe:SetPoint("TOPLEFT", tab, "TOPLEFT", 0, -30) yellowfive@11: tab.scrollframe:SetPoint("BOTTOMRIGHT", tab, "BOTTOMRIGHT", -30, 10) yellowfive@11: yellowfive@11: local content = tab.scrollframe.content yellowfive@11: content:SetHeight(730) adam@0: yellowfive@11: local btn = CreateFrame("Button", "AmrCombatLogStart", content, "UIPanelButtonTemplate") yellowfive@11: btn:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0) adam@0: btn:SetText("Start Logging") adam@0: btn:SetWidth(120) adam@0: btn:SetHeight(30) adam@0: tab.btnStart = btn adam@0: adam@0: btn:SetScript("OnClick", function() yellowfive@11: tab:ToggleLogging() adam@0: end) adam@0: adam@0: yellowfive@11: text = content:CreateFontString(nil, "ARTWORK", "GameFontWhite") yellowfive@11: text:SetPoint("LEFT", btn, "RIGHT", 10, 0) yellowfive@11: tab.loggingStatus = text; adam@0: TuhMuffinMan>@51: local hmAutoChk = newCheckbox(content, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_LABEL, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_TOOLTIP_TITLE, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_HM_DESCRIPTION, adam@0: function(self, value) adam@0: if value then TuhMuffinMan>@51: AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] = "enabled" adam@0: else TuhMuffinMan>@51: AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] = "disabled" adam@0: end adam@0: adam@17: AmrDb.LogData._lastZone = nil adam@17: AmrDb.LogData._lastDiff = nil adam@0: tab:UpdateAutoLogging() adam@0: end adam@0: ) TuhMuffinMan>@51: hmAutoChk:SetChecked(AmrDb.LogData._autoLog[AskMrRobot.instanceIds.Highmaul] == "enabled") TuhMuffinMan>@51: hmAutoChk:SetPoint("TOPLEFT", btn, "BOTTOMLEFT", 0, -10) TuhMuffinMan>@51: hmAutoChk:SetHeight(30) TuhMuffinMan>@51: TuhMuffinMan>@51: local brfAutoChk = newCheckbox(content, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_LABEL, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_TOOLTIP_TITLE, TuhMuffinMan>@51: L.AMR_COMBATLOGTAB_CHECKBOX_AUTOLOG_BRF_DESCRIPTION, TuhMuffinMan>@51: function(self, value) TuhMuffinMan>@51: if value then TuhMuffinMan>@51: AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] = "enabled" TuhMuffinMan>@51: else TuhMuffinMan>@51: AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] = "disabled" TuhMuffinMan>@51: end adam@0: TuhMuffinMan>@51: AmrDb.LogData._lastZone = nil TuhMuffinMan>@51: AmrDb.LogData._lastDiff = nil TuhMuffinMan>@51: tab:UpdateAutoLogging() TuhMuffinMan>@51: end TuhMuffinMan>@51: ) TuhMuffinMan>@51: brfAutoChk:SetChecked(AmrDb.LogData._autoLog[AskMrRobot.instanceIds.BlackrockFoundry] == "enabled") TuhMuffinMan>@51: brfAutoChk:SetPoint("TOPLEFT", hmAutoChk, "BOTTOMLEFT", 0, -10) TuhMuffinMan>@51: brfAutoChk:SetHeight(30) adam@0: TuhMuffinMan>@51: local text = CreateText(content, "GameFontNormalLarge", brfAutoChk, 0, -20, L.AMR_COMBATLOGTAB_INFIGHT) yellowfive@11: TuhMuffinMan>@51: btn = CreateFrame("Button", "AmrCombatLogWipe", brfAutoChk, "UIPanelButtonTemplate") yellowfive@11: btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -10) yellowfive@11: btn:SetText("Wipe") yellowfive@11: btn:SetWidth(70) yellowfive@11: btn:SetHeight(30) yellowfive@11: btn:SetScript("OnClick", function() yellowfive@11: tab:LogWipe() yellowfive@11: end) yellowfive@11: yellowfive@11: tab.btnWipe = btn yellowfive@11: yellowfive@11: local text2 = CreateText(content, "GameFontWhite", text, 80, -12, L.AMR_COMBATLOGTAB_WIPE_1) yellowfive@11: text2 = CreateText(content, "GameFontWhite", text2, 0, -2, L.AMR_COMBATLOGTAB_WIPE_2) yellowfive@11: text2 = CreateText(content, "GameFontWhite", text2, 0, -2, L.AMR_COMBATLOGTAB_WIPE_3) yellowfive@11: yellowfive@11: btn = CreateFrame("Button", "AmrCombatLogUnWipe", content, "UIPanelButtonTemplate") yellowfive@11: btn:SetPoint("LEFT", text, "LEFT", 0, 0) yellowfive@11: btn:SetPoint("TOP", text2, "BOTTOM", 0, -10) yellowfive@11: btn:SetText("Undo") yellowfive@11: btn:SetWidth(70) yellowfive@11: btn:SetHeight(30) yellowfive@11: btn:Hide() -- initially hidden yellowfive@11: btn:SetScript("OnClick", function() yellowfive@11: tab:LogUnwipe() yellowfive@11: end) yellowfive@11: tab.btnUnwipe = btn yellowfive@11: yellowfive@11: text = content:CreateFontString(nil, "ARTWORK", "GameFontWhite") yellowfive@11: text:SetPoint("LEFT", btn, "LEFT", 80, 0) yellowfive@11: tab.lastWipeLabel = text yellowfive@11: yellowfive@11: text = CreateText(tab, "GameFontNormalLarge", btn, 0, -20, L.AMR_COMBATLOGTAB_HEADLINE_OVER_BUTTON) yellowfive@11: yellowfive@11: btn = CreateFrame("Button", "AmrCombatLogSaveCharData", content, "UIPanelButtonTemplate") adam@0: btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -5) yellowfive@11: btn:SetText(L.AMR_COMBATLOGTAB_SAVE_CHARACTER) adam@0: btn:SetWidth(150) adam@0: btn:SetHeight(30) adam@0: yellowfive@11: -- reload the UI will save character data to disk yellowfive@11: btn:SetScript("OnClick", ReloadUI) adam@0: yellowfive@11: text = CreateText(content, "GameFontWhite", btn, 0, -15, L.AMR_COMBATLOGTAB_SAVE_CHARACTER_INFO) adam@0: yellowfive@11: text = CreateText(content, "GameFontNormalLarge", text, 0, -30, L.AMR_COMBATLOGTAB_INSTRUCTIONS) yellowfive@11: text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_1) yellowfive@11: text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_2) yellowfive@11: text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_3) yellowfive@11: text = CreateText(content, "GameFontWhite", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_4) yellowfive@11: yellowfive@11: text = CreateText(content, "GameFontNormalSmall", text, 0, -30, L.AMR_COMBATLOGTAB_INSTRUCTIONS_5) yellowfive@11: text = CreateText(content, "GameFontNormalSmall", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_6) yellowfive@11: text = CreateText(content, "GameFontNormalSmall", text, 0, -10, L.AMR_COMBATLOGTAB_INSTRUCTIONS_7) adam@0: yellowfive@15: --[[ adam@0: btn = CreateFrame("Button", "AmrCombatLogTest", tab, "UIPanelButtonTemplate") adam@0: btn:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -15) adam@0: btn:SetText("Test") adam@0: btn:SetWidth(120) adam@0: btn:SetHeight(30) adam@0: adam@0: btn:SetScript("OnClick", function() yellowfive@11: yellowfive@11: local t = time() yellowfive@11: AskMrRobot.SaveAll() yellowfive@11: AskMrRobot.ExportToAddonChat(t) adam@17: AskMrRobot.CombatLogTab.SaveExtras(t) adam@0: end) yellowfive@15: ]] adam@0: adam@0: -- when we start up, ensure that logging is still enabled if it was enabled when they last used the addon adam@17: if (AskMrRobot.CombatLogTab.IsLogging()) then adam@0: SetCVar("advancedCombatLogging", 1) adam@0: LoggingCombat(true) adam@0: end adam@0: adam@0: -- if auto-logging is enabled, do a check when the addon is loaded to make sure that state is set correctly yellowfive@53: if tab:IsAutoLoggingEnabled() then adam@0: tab:UpdateAutoLogging() adam@0: end adam@0: adam@0: tab:SetScript("OnShow", function() adam@0: tab:Update() adam@0: end) adam@0: adam@0: return tab adam@0: end adam@0: adam@17: function AskMrRobot.CombatLogTab.IsLogging() adam@17: return AmrDb.LogData._logging == true adam@0: end adam@0: adam@0: function AskMrRobot.CombatLogTab:StartLogging() adam@0: yellowfive@11: local now = time() yellowfive@11: local oldDuration = 60 * 60 * 24 * 10 yellowfive@11: adam@0: -- archive the current logging session so that users don't accidentally blow away data before uploading it adam@17: if AmrDb.LogData._current2 ~= nil then adam@17: if not AmrDb.LogData._history2 then AmrDb.LogData._history2 = {} end adam@0: adam@0: -- add new entries adam@17: for name, timeList in AskMrRobot.spairs(AmrDb.LogData._current2) do adam@17: if not AmrDb.LogData._history2[name] then AmrDb.LogData._history2[name] = {} end adam@0: for timestamp, dataString in AskMrRobot.spairs(timeList) do adam@17: AmrDb.LogData._history2[name][timestamp] = dataString adam@0: end adam@0: end adam@0: adam@0: -- delete entries that are more than 10 days old adam@17: for name, timeList in AskMrRobot.spairs(AmrDb.LogData._history2) do adam@0: for timestamp, dataString in AskMrRobot.spairs(timeList) do yellowfive@11: if difftime(now, tonumber(timestamp)) > oldDuration then adam@0: timeList[timestamp] = nil adam@0: end adam@0: end adam@0: adam@0: local count = 0 adam@0: for timestamp, dataString in pairs(timeList) do adam@0: count = count + 1 adam@0: end adam@0: if count == 0 then adam@17: AmrDb.LogData._history2[name] = nil adam@0: end adam@0: end adam@0: end adam@0: yellowfive@11: -- same idea with extra info (auras, pets, whatever we end up adding to it) adam@17: if AmrDb.LogData._currentExtra ~= nil then adam@17: if not AmrDb.LogData._historyExtra then AmrDb.LogData._historyExtra = {} end yellowfive@11: yellowfive@11: -- add new entries adam@17: for name, timeList in AskMrRobot.spairs(AmrDb.LogData._currentExtra) do adam@17: if not AmrDb.LogData._historyExtra[name] then AmrDb.LogData._historyExtra[name] = {} end yellowfive@11: for timestamp, dataString in AskMrRobot.spairs(timeList) do adam@17: AmrDb.LogData._historyExtra[name][timestamp] = dataString yellowfive@11: end yellowfive@11: end yellowfive@11: yellowfive@11: -- delete entries that are more than 10 days old adam@17: for name, timeList in AskMrRobot.spairs(AmrDb.LogData._historyExtra) do yellowfive@11: for timestamp, dataString in AskMrRobot.spairs(timeList) do yellowfive@11: if difftime(now, tonumber(timestamp)) > oldDuration then yellowfive@11: timeList[timestamp] = nil yellowfive@11: end yellowfive@11: end yellowfive@11: yellowfive@11: local count = 0 yellowfive@11: for timestamp, dataString in pairs(timeList) do yellowfive@11: count = count + 1 yellowfive@11: end yellowfive@11: if count == 0 then adam@17: AmrDb.LogData._historyExtra[name] = nil yellowfive@11: end yellowfive@11: end yellowfive@11: end yellowfive@11: yellowfive@11: yellowfive@11: -- delete _wipes entries that are more than 10 days old adam@17: if AmrDb.LogData._wipes then yellowfive@11: local i = 1 adam@17: while i <= #AmrDb.LogData._wipes do adam@17: local t = AmrDb.LogData._wipes[i] yellowfive@11: if difftime(now, t) > oldDuration then adam@17: tremove(AmrDb.LogData._wipes, i) yellowfive@11: else yellowfive@11: i = i + 1 yellowfive@11: end yellowfive@11: end yellowfive@11: end yellowfive@11: yellowfive@11: -- delete the _lastWipe if it is more than 10 days old adam@17: if AmrDb.LogData._lastWipe and difftime(now, AmrDb.LogData._lastWipe) > oldDuration then adam@17: AmrDb.LogData_lastWipe = nil yellowfive@11: end yellowfive@11: adam@0: -- clean up old-style logging data from previous versions of the addon adam@17: for k, v in AskMrRobot.spairs(AmrDb.LogData) do yellowfive@11: if not _logDataKeys[k] then adam@17: AmrDb.LogData[k] = nil adam@0: end adam@0: end adam@0: adam@0: -- start a new logging session adam@17: AmrDb.LogData._current2 = {} adam@17: AmrDb.LogData._currentExtra = {} adam@17: AmrDb.LogData._logging = true adam@0: adam@0: -- always enable advanced combat logging via our addon, gathers more detailed data for better analysis adam@0: SetCVar("advancedCombatLogging", 1) adam@0: adam@0: LoggingCombat(true) adam@0: self:Update() yellowfive@11: yellowfive@11: AskMrRobot.AmrUpdateMinimap() adam@0: yellowfive@11: print(L.AMR_COMBATLOGTAB_IS_LOGGING) adam@0: end adam@0: adam@0: function AskMrRobot.CombatLogTab:StopLogging() adam@0: LoggingCombat(false) adam@17: AmrDb.LogData._logging = false adam@0: self:Update() adam@0: yellowfive@11: AskMrRobot.AmrUpdateMinimap() yellowfive@11: yellowfive@11: print(L.AMR_COMBATLOGTAB_STOPPED_LOGGING) yellowfive@11: end yellowfive@11: yellowfive@11: function AskMrRobot.CombatLogTab:ToggleLogging() adam@17: if AskMrRobot.CombatLogTab.IsLogging() then yellowfive@11: self:StopLogging() yellowfive@11: else yellowfive@11: self:StartLogging() yellowfive@11: end adam@0: end adam@0: adam@0: -- update the panel and state adam@0: function AskMrRobot.CombatLogTab:Update() adam@17: local isLogging = AskMrRobot.CombatLogTab.IsLogging() adam@0: adam@0: if isLogging then yellowfive@11: self.btnStart:SetText(L.AMR_COMBATLOGTAB_STOP_LOGGING) yellowfive@11: self.loggingStatus:SetText(L.AMR_COMBATLOGTAB_CURRENTLY_LOGGING) adam@0: else yellowfive@11: self.btnStart:SetText(L.AMR_COMBATLOGTAB_START_LOGGING) yellowfive@11: self.loggingStatus:SetText("") adam@0: end yellowfive@11: adam@17: if AmrDb.LogData._lastWipe then adam@17: self.lastWipeLabel:SetText(L.AMR_COMBATLOGTAB_LASTWIPE:format(date('%B %d', AmrDb.LogData._lastWipe), date('%I:%M %p', AmrDb.LogData._lastWipe))) yellowfive@11: self.btnUnwipe:Show() yellowfive@11: else yellowfive@11: self.lastWipeLabel:SetText("") yellowfive@11: self.btnUnwipe:Hide() yellowfive@11: end yellowfive@11: adam@0: end adam@0: yellowfive@53: -- returns true if any auto-logging options are enabled yellowfive@53: function AskMrRobot.CombatLogTab:IsAutoLoggingEnabled() yellowfive@53: -- see if any auto-logging is enabled yellowfive@53: for k,v in pairs(AmrDb.LogData._autoLog) do yellowfive@53: if v == "enabled" then yellowfive@53: return true yellowfive@53: end yellowfive@53: end yellowfive@53: return false yellowfive@53: end yellowfive@53: adam@0: -- called to update logging state when auto-logging is enabled adam@0: function AskMrRobot.CombatLogTab:UpdateAutoLogging() adam@0: adam@0: -- get the info about the instance adam@0: --local zone, zonetype, difficultyIndex, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID = GetInstanceInfo() adam@0: local zone, _, difficultyIndex, _, _, _, _, instanceMapID = GetInstanceInfo() adam@0: --local difficulty = difficultyIndex adam@0: -- Unless Blizzard fixes scenarios to not return nil, let's hardcode this into returning "scenario" -Znuff adam@0: --if zonetype == nil and difficultyIndex == 1 then adam@0: --zonetype = "scenario" adam@0: --end adam@0: adam@17: if zone == AmrDb.LogData._lastZone and difficultyIndex == AmrDb.LogData._lastDiff then adam@0: -- do nothing if the zone hasn't actually changed, otherwise we may override the user's manual enable/disable adam@0: return adam@0: end adam@0: adam@17: AmrDb.LogData._lastZone = zone adam@17: AmrDb.LogData._lastDiff = difficultyIndex adam@0: yellowfive@53: if self:IsAutoLoggingEnabled() then yellowfive@53: if AskMrRobot.IsSupportedInstanceId(instanceMapID) and AmrDb.LogData._autoLog[tonumber(instanceMapID)] == "enabled" then yellowfive@53: -- we are in a supported zone that we want to auto-log, turn logging on yellowfive@53: -- (supported check is probably redundant, but just in case someone has old settings lying around) adam@17: if not AskMrRobot.CombatLogTab.IsLogging() then adam@0: self:StartLogging() adam@0: end adam@0: else yellowfive@53: -- not in a zone that we want to auto-log, turn logging off adam@17: if AskMrRobot.CombatLogTab.IsLogging() then adam@0: self:StopLogging() adam@0: end adam@0: end adam@0: end adam@0: adam@0: end adam@0: yellowfive@11: local function RaidChatType() yellowfive@11: if UnitIsGroupAssistant("player") or UnitIsGroupLeader("player") then yellowfive@11: return "RAID_WARNING" yellowfive@11: else yellowfive@11: return "RAID" yellowfive@11: end yellowfive@11: end yellowfive@11: adam@17: -- used to store wipes to AmrDb.LogData so that we trim data after the wipe yellowfive@11: function AskMrRobot.CombatLogTab:LogWipe() yellowfive@11: local t = time() adam@17: tinsert(AmrDb.LogData._wipes, t) adam@17: AmrDb.LogData._lastWipe = t yellowfive@11: adam@17: --if GetNumGroupMembers() > 0 then adam@17: -- SendChatMessage(L.AMR_COMBATLOGTAB_WIPE_CHAT, RaidChatType()) adam@17: --end yellowfive@11: print(string.format(L.AMR_COMBATLOGTAB_WIPE_MSG, date('%I:%M %p', t))) yellowfive@11: yellowfive@11: self:Update() yellowfive@11: end yellowfive@11: yellowfive@11: -- used to undo the wipe command yellowfive@11: function AskMrRobot.CombatLogTab:LogUnwipe() adam@17: local t = AmrDb.LogData._lastWipe yellowfive@11: if not t then yellowfive@11: print(L.AMR_COMBATLOGTAB_NOWIPES) yellowfive@11: else adam@17: tremove(AmrDb.LogData._wipes) adam@17: AmrDb.LogData._lastWipe = nil yellowfive@11: print(string.format(L.AMR_COMBATLOGTAB_UNWIPE_MSG, date('%I:%M %p', t))) yellowfive@11: end yellowfive@11: self:Update() yellowfive@11: end yellowfive@11: adam@17: -- initialize the AmrDb.LogData variable yellowfive@11: function AskMrRobot.CombatLogTab.InitializeVariable() adam@17: if not AmrDb.LogData then AmrDb.LogData = {} end adam@17: if not AmrDb.LogData._autoLog then AmrDb.LogData._autoLog = {} end yellowfive@53: yellowfive@53: for k,v in pairs(AskMrRobot.supportedInstanceIds) do yellowfive@53: if not AmrDb.LogData._autoLog[k] then yellowfive@53: AmrDb.LogData._autoLog[k] = "disabled" yellowfive@53: end yellowfive@11: end yellowfive@53: adam@17: AmrDb.LogData._wipes = AmrDb.LogData._wipes or {} yellowfive@11: end yellowfive@11: yellowfive@41: local function GetPlayerExtraData(data, unitId, petId) adam@17: adam@17: local guid = UnitGUID(unitId) adam@17: if guid == nil then yellowfive@41: return adam@17: end adam@17: adam@17: local fields = {} adam@17: adam@17: local buffs = {} adam@17: for i=1,40 do adam@17: local _,_,_,count,_,_,_,_,_,_,spellId = UnitAura(unitId, i, "HELPFUL") adam@17: table.insert(buffs, spellId) adam@17: end adam@17: if #buffs == 0 then adam@17: table.insert(fields, "_") adam@17: else adam@17: table.insert(fields, AskMrRobot.toCompressedNumberList(buffs)) adam@17: end adam@17: yellowfive@41: local petGuid = UnitGUID(petId) adam@17: if petGuid then adam@17: table.insert(fields, guid .. "," .. petGuid) adam@17: else adam@17: table.insert(fields, '_') adam@17: end adam@17: yellowfive@41: local name = GetUnitName(unitId, true) -- GetRaidRosterInfo(rosterIndex) adam@17: local realm = GetRealmName() yellowfive@41: local region = AskMrRobot.regionNames[GetCurrentRegion()] adam@17: local splitPos = string.find(name, "-") adam@17: if splitPos ~= nil then adam@17: realm = string.sub(name, splitPos + 1) adam@17: name = string.sub(name, 1, splitPos - 1) adam@17: end adam@17: yellowfive@41: data[region .. ":" .. realm .. ":" .. name] = table.concat(fields, ";") adam@17: end adam@17: adam@17: function AskMrRobot.CombatLogTab.SaveExtras(timestamp) adam@17: adam@17: if not AskMrRobot.CombatLogTab.IsLogging() then adam@17: return adam@17: end adam@17: yellowfive@41: local units = {} yellowfive@41: local petUnits = {} yellowfive@41: yellowfive@41: if IsInRaid() then yellowfive@41: for i = 1,40 do yellowfive@41: table.insert(units, "raid" .. i) yellowfive@41: table.insert(petUnits, "raidpet" .. i) yellowfive@41: end yellowfive@41: elseif IsInGroup() then yellowfive@41: table.insert(units, "player") yellowfive@41: table.insert(petUnits, "pet") yellowfive@41: for i = 1,4 do yellowfive@41: table.insert(units, "party" .. i) yellowfive@41: table.insert(petUnits, "partypet" .. i) yellowfive@41: end yellowfive@41: else yellowfive@41: return yellowfive@41: end adam@17: adam@17: local data = {} yellowfive@41: for i = 1,#units do yellowfive@41: GetPlayerExtraData(data, units[i], petUnits[i]) yellowfive@41: end adam@17: yellowfive@11: for name,val in pairs(data) do yellowfive@11: -- record aura stuff, we never check for duplicates, need to know it at each point in time adam@17: if AmrDb.LogData._currentExtra[name] == nil then adam@17: AmrDb.LogData._currentExtra[name] = {} yellowfive@11: end adam@17: AmrDb.LogData._currentExtra[name][timestamp] = val yellowfive@11: end yellowfive@11: end yellowfive@11: adam@0: -- read a message sent to the addon channel with a player's info at the time an encounter started adam@0: function AskMrRobot.CombatLogTab:ReadAddonMessage(message) adam@0: yellowfive@41: -- message will be of format: timestamp\nregion\nrealm\nname\n[stuff] adam@0: local parts = {} adam@0: for part in string.gmatch(message, "([^\n]+)") do adam@0: tinsert(parts, part) adam@0: end adam@0: adam@0: local timestamp = parts[1] yellowfive@41: local name = parts[2] .. ":" .. parts[3] .. ":" .. parts[4] yellowfive@41: local data = parts[5] adam@0: adam@0: if (data == "done") then adam@0: -- we have finished receiving this message; now process it to reduce the amount of duplicate data adam@17: local setup = AmrDb.LogData._current2[name][timestamp] yellowfive@11: adam@17: if (AmrDb.LogData._previousSetup == nil) then adam@17: AmrDb.LogData._previousSetup = {} adam@0: end adam@0: adam@17: local previousSetup = AmrDb.LogData._previousSetup[name] adam@0: adam@0: if (previousSetup == setup) then adam@0: -- if the last-seen setup for this player is the same as the current one, we don't need this entry adam@17: AmrDb.LogData._current2[name][timestamp] = nil adam@0: else adam@0: -- record the last-seen setup adam@17: AmrDb.LogData._previousSetup[name] = setup adam@0: end yellowfive@11: adam@0: else adam@0: -- concatenate messages with the same timestamp+name adam@17: if (AmrDb.LogData._current2[name] == nil) then adam@17: AmrDb.LogData._current2[name] = {} adam@0: end adam@0: adam@17: if (AmrDb.LogData._current2[name][timestamp] == nil) then adam@17: AmrDb.LogData._current2[name][timestamp] = data adam@0: else adam@17: AmrDb.LogData._current2[name][timestamp] = AmrDb.LogData._current2[name][timestamp] .. data adam@0: end adam@0: end adam@0: end