From 02a6e60e773aa4d52c8d4bfe6c3a5c99e26b5353 Mon Sep 17 00:00:00 2001 From: psynct Date: Fri, 12 Jun 2020 02:16:34 -0700 Subject: [PATCH] copy repo to new location --- .gitignore | 42 + ArcaniteCoordinator.lua | 382 ++ ArcaniteCoordinator.toc | 10 + Libs/Ace3.lua | 110 + Libs/Ace3.toc | 27 + Libs/AceAddon-3.0/AceAddon-3.0.lua | 643 +++ Libs/AceAddon-3.0/AceAddon-3.0.xml | 4 + Libs/AceComm-3.0/AceComm-3.0.lua | 305 ++ Libs/AceComm-3.0/AceComm-3.0.xml | 5 + Libs/AceComm-3.0/ChatThrottleLib.lua | 534 +++ Libs/AceConfig-3.0/AceConfig-3.0.lua | 58 + Libs/AceConfig-3.0/AceConfig-3.0.xml | 8 + .../AceConfigCmd-3.0/AceConfigCmd-3.0.lua | 794 ++++ .../AceConfigCmd-3.0/AceConfigCmd-3.0.xml | 4 + .../AceConfigDialog-3.0.lua | 2015 ++++++++++ .../AceConfigDialog-3.0.xml | 4 + .../AceConfigRegistry-3.0.lua | 371 ++ .../AceConfigRegistry-3.0.xml | 4 + Libs/AceConsole-3.0/AceConsole-3.0.lua | 250 ++ Libs/AceConsole-3.0/AceConsole-3.0.xml | 4 + Libs/AceDB-3.0/AceDB-3.0.lua | 744 ++++ Libs/AceDB-3.0/AceDB-3.0.xml | 4 + Libs/AceDBOptions-3.0/AceDBOptions-3.0.lua | 460 +++ Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml | 4 + Libs/AceEvent-3.0/AceEvent-3.0.lua | 126 + Libs/AceEvent-3.0/AceEvent-3.0.xml | 4 + Libs/AceGUI-3.0/AceGUI-3.0.lua | 1026 +++++ Libs/AceGUI-3.0/AceGUI-3.0.xml | 28 + .../AceGUIContainer-BlizOptionsGroup.lua | 138 + .../widgets/AceGUIContainer-DropDownGroup.lua | 157 + .../widgets/AceGUIContainer-Frame.lua | 316 ++ .../widgets/AceGUIContainer-InlineGroup.lua | 103 + .../widgets/AceGUIContainer-ScrollFrame.lua | 215 + .../widgets/AceGUIContainer-SimpleGroup.lua | 69 + .../widgets/AceGUIContainer-TabGroup.lua | 349 ++ .../widgets/AceGUIContainer-TreeGroup.lua | 715 ++++ .../widgets/AceGUIContainer-Window.lua | 336 ++ .../widgets/AceGUIWidget-Button.lua | 103 + .../widgets/AceGUIWidget-CheckBox.lua | 296 ++ .../widgets/AceGUIWidget-ColorPicker.lua | 190 + .../widgets/AceGUIWidget-DropDown-Items.lua | 471 +++ .../widgets/AceGUIWidget-DropDown.lua | 742 ++++ .../widgets/AceGUIWidget-EditBox.lua | 263 ++ .../widgets/AceGUIWidget-Heading.lua | 78 + Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua | 140 + .../widgets/AceGUIWidget-InteractiveLabel.lua | 94 + .../widgets/AceGUIWidget-Keybinding.lua | 249 ++ .../AceGUI-3.0/widgets/AceGUIWidget-Label.lua | 179 + .../widgets/AceGUIWidget-MultiLineEditBox.lua | 366 ++ .../widgets/AceGUIWidget-Slider.lua | 284 ++ Libs/AceLocale-3.0/AceLocale-3.0.lua | 137 + Libs/AceLocale-3.0/AceLocale-3.0.xml | 4 + Libs/AceTimer-3.0/AceTimer-3.0.lua | 278 ++ Libs/AceTimer-3.0/AceTimer-3.0.xml | 4 + Libs/Bindings.xml | 5 + Libs/CHANGES.txt | 58 + .../CallbackHandler-1.0.lua | 212 + .../CallbackHandler-1.0.xml | 4 + Libs/LICENSE.txt | 29 + Libs/LibDBIcon-1.0/LibDBIcon-1.0.lua | 470 +++ Libs/LibDBIcon-1.0/lib.xml | 7 + Libs/LibDataBroker-1.1/LibDataBroker-1.1.lua | 90 + Libs/LibDataBroker-1.1/README.textile | 13 + Libs/LibDeflate/LICENSE.txt | 147 + Libs/LibDeflate/LibDeflate.lua | 3525 +++++++++++++++++ Libs/LibDeflate/LibDeflate.toc | 11 + Libs/LibDeflate/LibStub/LibStub.lua | 51 + Libs/LibDeflate/LibStub/LibStub.toc | 9 + Libs/LibDeflate/LibStub/tests/test.lua | 41 + Libs/LibDeflate/LibStub/tests/test2.lua | 27 + Libs/LibDeflate/LibStub/tests/test3.lua | 14 + Libs/LibDeflate/LibStub/tests/test4.lua | 41 + Libs/LibDeflate/README.md | 205 + Libs/LibDeflate/changelog.md | 50 + Libs/LibDeflate/lib.xml | 4 + Libs/LibStub/LibStub.lua | 30 + Libs/changelog.txt | 427 ++ Locale/Locales.xml | 15 + Locale/enUS.lua | 28 + Locale/ruRU.lua | 28 + README.md | 2 +- embeds.xml | 17 + 82 files changed, 19805 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 ArcaniteCoordinator.lua create mode 100644 ArcaniteCoordinator.toc create mode 100644 Libs/Ace3.lua create mode 100644 Libs/Ace3.toc create mode 100644 Libs/AceAddon-3.0/AceAddon-3.0.lua create mode 100644 Libs/AceAddon-3.0/AceAddon-3.0.xml create mode 100644 Libs/AceComm-3.0/AceComm-3.0.lua create mode 100644 Libs/AceComm-3.0/AceComm-3.0.xml create mode 100644 Libs/AceComm-3.0/ChatThrottleLib.lua create mode 100644 Libs/AceConfig-3.0/AceConfig-3.0.lua create mode 100644 Libs/AceConfig-3.0/AceConfig-3.0.xml create mode 100644 Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.lua create mode 100644 Libs/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml create mode 100644 Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua create mode 100644 Libs/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml create mode 100644 Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua create mode 100644 Libs/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml create mode 100644 Libs/AceConsole-3.0/AceConsole-3.0.lua create mode 100644 Libs/AceConsole-3.0/AceConsole-3.0.xml create mode 100644 Libs/AceDB-3.0/AceDB-3.0.lua create mode 100644 Libs/AceDB-3.0/AceDB-3.0.xml create mode 100644 Libs/AceDBOptions-3.0/AceDBOptions-3.0.lua create mode 100644 Libs/AceDBOptions-3.0/AceDBOptions-3.0.xml create mode 100644 Libs/AceEvent-3.0/AceEvent-3.0.lua create mode 100644 Libs/AceEvent-3.0/AceEvent-3.0.xml create mode 100644 Libs/AceGUI-3.0/AceGUI-3.0.lua create mode 100644 Libs/AceGUI-3.0/AceGUI-3.0.xml create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-BlizOptionsGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-Frame.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-InlineGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-ScrollFrame.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-SimpleGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-TabGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIContainer-Window.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Button.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown-Items.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-EditBox.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Heading.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Label.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-MultiLineEditBox.lua create mode 100644 Libs/AceGUI-3.0/widgets/AceGUIWidget-Slider.lua create mode 100644 Libs/AceLocale-3.0/AceLocale-3.0.lua create mode 100644 Libs/AceLocale-3.0/AceLocale-3.0.xml create mode 100644 Libs/AceTimer-3.0/AceTimer-3.0.lua create mode 100644 Libs/AceTimer-3.0/AceTimer-3.0.xml create mode 100644 Libs/Bindings.xml create mode 100644 Libs/CHANGES.txt create mode 100644 Libs/CallbackHandler-1.0/CallbackHandler-1.0.lua create mode 100644 Libs/CallbackHandler-1.0/CallbackHandler-1.0.xml create mode 100644 Libs/LICENSE.txt create mode 100644 Libs/LibDBIcon-1.0/LibDBIcon-1.0.lua create mode 100644 Libs/LibDBIcon-1.0/lib.xml create mode 100644 Libs/LibDataBroker-1.1/LibDataBroker-1.1.lua create mode 100644 Libs/LibDataBroker-1.1/README.textile create mode 100644 Libs/LibDeflate/LICENSE.txt create mode 100644 Libs/LibDeflate/LibDeflate.lua create mode 100644 Libs/LibDeflate/LibDeflate.toc create mode 100644 Libs/LibDeflate/LibStub/LibStub.lua create mode 100644 Libs/LibDeflate/LibStub/LibStub.toc create mode 100644 Libs/LibDeflate/LibStub/tests/test.lua create mode 100644 Libs/LibDeflate/LibStub/tests/test2.lua create mode 100644 Libs/LibDeflate/LibStub/tests/test3.lua create mode 100644 Libs/LibDeflate/LibStub/tests/test4.lua create mode 100644 Libs/LibDeflate/README.md create mode 100644 Libs/LibDeflate/changelog.md create mode 100644 Libs/LibDeflate/lib.xml create mode 100644 Libs/LibStub/LibStub.lua create mode 100644 Libs/changelog.txt create mode 100644 Locale/Locales.xml create mode 100644 Locale/enUS.lua create mode 100644 Locale/ruRU.lua create mode 100644 embeds.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2b2e4a --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# Compiled Lua sources +luac.out + +# luarocks build files +*.src.rock +*.zip +*.tar.gz + +# Object files +*.o +*.os +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo +*.def +*.exp + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +.idea diff --git a/ArcaniteCoordinator.lua b/ArcaniteCoordinator.lua new file mode 100644 index 0000000..982901f --- /dev/null +++ b/ArcaniteCoordinator.lua @@ -0,0 +1,382 @@ +AC = LibStub("AceAddon-3.0"):NewAddon("ArcaniteCoordinator", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0", "AceTimer-3.0") +AC.Dialog = LibStub("AceConfigDialog-3.0") +AC.LibDeflate = LibStub("LibDeflate") + +local L = LibStub("AceLocale-3.0"):GetLocale("ArcaniteCoordinator") + +AC:RegisterChatCommand(L["arc"], "ChatCommand") +AC.VERSION = 108 +AC.COMMS_VER = 4 +AC.ICON = "Interface/Icons/inv_misc_stonetablet_05" + +function GetVersionString(ver) + if ver >= 10 then + return GetVersionString(floor(ver/10)) .. "." .. tostring(ver % 10) + else + return "v" .. tostring(ver) + end +end + +AC.options = { + name = format("|T%s:24:24:0:5|t ", AC.ICON) .. L["Arcanite Coordinator"] .. " " .. GetVersionString(AC.VERSION), + handler = AC, + type = 'group', + args = { + desc = { + type = "description", + name = "|CffDEDE42" .. format(L["optionsDesc"], L["arc"], L["config"]), + fontSize = "medium", + order = 1, + }, + minimap = { + type = "toggle", + name = L["Minimap Button"], + desc = L["minimapDesc"], + order = 3, + get = function() + return not AC.db.profile.minimap.hide + end, + set = function (info, value) + AC.db.profile.minimap.hide = not value + if AC.db.profile.minimap.hide then + AC.icon:Hide("ArcaniteCoordinator") + else + AC.icon:Show("ArcaniteCoordinator") + end + end, + }, + }, +} + +AC.optionDefaults = { + profile = { + minimap = { + hide = false, + }, + }, + factionrealm = { + knownCooldowns = {}, + }, +} + +function splitString(inputstr, sep) + local t={} + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + table.insert(t, str) + end + return t +end + +AC.QuestionCooldowns = "AC_qc" +AC.SendKnownCooldown = "AC_skc" +AC.SendAllCooldowns = "AC_sac" + +AC.CHAT_PREFIX = format("|cFFFF69B4[%s]|r ", L["ArcaniteCoordinator"]) +AC.foundOldVersion = false +AC.ARCANITE_SPELL_ID = 17187 +AC.ALCHEMY_300_SPELL_ID = 11611 +AC.FORGET_COOLDOWN_SECS = 7 * 24 * 60 * 60 +AC.DEBUG = false + +local sendAllCooldownsTimer +local requestCooldownsTimer + +function AC:OnInitialize() + AC.ArcaniteCoordinatorLauncher = LibStub("LibDataBroker-1.1"):NewDataObject("ArcaniteCoordinator", { + type = "launcher", + text = L["Arcanite Coordinator"], + icon = AC.ICON, + OnClick = function(self, button) + if button == "LeftButton" then + AC:PrintCooldowns() + elseif button == "RightButton" then + AC:ToggleConfigWindow() + end + end, + OnEnter = function(self) + GameTooltip:SetOwner(self, "ANCHOR_LEFT") + GameTooltip:AddDoubleLine(format("|cFFFFFFFF%s|r", L["Arcanite Coordinator"]), format("|cFF777777%s|r", GetVersionString(AC.VERSION))) + GameTooltip:AddLine(L["minimapLeftClickAction"]) + GameTooltip:AddLine(L["minimapRightClickAction"]) + GameTooltip:Show() + end, + OnLeave = function(self) + GameTooltip:Hide() + end + }) + + AC.db = LibStub("AceDB-3.0"):New("ArcaniteCoordinatorDB", AC.optionDefaults, "Default") + LibStub("AceConfig-3.0"):RegisterOptionsTable("ArcaniteCoordinator", AC.options) + AC.ArcaniteCoordinatorOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("ArcaniteCoordinator", L["Arcanite Coordinator"]) + + AC.icon = LibStub("LibDBIcon-1.0") + AC.icon:Register("ArcaniteCoordinator", AC.ArcaniteCoordinatorLauncher, AC.db.profile.minimap) + + AC:RegisterEvent("PLAYER_LOGIN") + AC:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") + AC:RegisterComm(AC.QuestionCooldowns, "OnQuestionCooldowns") + AC:RegisterComm(AC.SendKnownCooldown, "OnSendKnownCooldown") + AC:RegisterComm(AC.SendAllCooldowns, "OnSendAllCooldowns") +end + +function AC:PLAYER_LOGIN() + AC:UpdateAndSendMyCooldown() + AC:CleanupCooldowns() + if requestCooldownsTimer then AC:CancelTimer(requestCooldownsTimer, true); requestCooldownsTimer = nil; end + requestCooldownsTimer = AC:ScheduleTimer(function() + AC:RequestCooldowns() + end, 5) +end + +function AC:UNIT_SPELLCAST_SUCCEEDED(_, _, _, spellId) + if spellId == AC.ARCANITE_SPELL_ID then + AC:UpdateAndSendMyCooldown() + end +end + +function AC:UpdateMyCooldown() + local myName = UnitName("player") + local hasAlchemy275 = false + if IsSpellKnown(AC.ALCHEMY_300_SPELL_ID) then + local alchemySpellName = GetSpellInfo(AC.ALCHEMY_300_SPELL_ID) + for i = 1, GetNumSkillLines() do + local skillName, _, _, skillRank = GetSkillLineInfo(i) + skillRank = tonumber(skillRank) + if alchemySpellName == skillName and skillRank ~= nil then + hasAlchemy275 = (skillRank >= 275) + break + end + end + end + if hasAlchemy275 then + local start, duration = GetSpellCooldown(AC.ARCANITE_SPELL_ID) + if start > (2^31 + 2^30) / 1000 then + -- WORKAROUND wow wraps around negative values that are too big + start = start - 2^32 / 1000 + end + local finish + if start == 0 then + finish = 0 + else + local durationRemaining = start + duration - GetTime() + finish = floor(GetServerTime() + durationRemaining) + end + if not AC.db.factionrealm.knownCooldowns[myName] or abs(finish - AC.db.factionrealm.knownCooldowns[myName]["finish"]) > 60 then + AC.db.factionrealm.knownCooldowns[myName] = { + ["finish"] = finish, + ["lastUpdate"] = GetServerTime(), + } + return true + end + else + AC.db.factionrealm.knownCooldowns[myName] = nil + end + return false +end + +function AC:UpdateAndSendMyCooldown() + if AC:UpdateMyCooldown() then + local myName = UnitName("player") + local cooldownData = AC.db.factionrealm.knownCooldowns[myName] + AC:SendMessage(AC.SendKnownCooldown, AC.VERSION .. "#" .. AC.COMMS_VER .. "#" .. myName .. ":" .. cooldownData["finish"] .. ":" .. cooldownData["lastUpdate"], "GUILD") + end +end + +function AC:CleanupCooldowns() + for player, cooldownData in pairs(AC.db.factionrealm.knownCooldowns) do + if GetServerTime() - cooldownData["lastUpdate"] > AC.FORGET_COOLDOWN_SECS then + AC.db.factionrealm.knownCooldowns[player] = nil + elseif cooldownData["finish"] > 0 and GetServerTime() > cooldownData["finish"] then + AC.db.factionrealm.knownCooldowns[player]["finish"] = 0 + end + end +end + +function AC:SendMessage(prefix, msg, distribution, target) + if distribution == "GUILD" and not IsInGuild() then + return + end + if AC.DEBUG then + print("SEND:" .. prefix .. " " .. UnitName("player") .. " " .. msg) + end + msg = AC.LibDeflate:EncodeForWoWAddonChannel(AC.LibDeflate:CompressDeflate(msg)) + AC:SendCommMessage(prefix, msg, distribution, target) +end + +function AC:RequestCooldowns() + AC:SendMessage(AC.QuestionCooldowns, AC.VERSION .. "#" .. AC.COMMS_VER, "GUILD") +end + +function AC:FormatTime(duration) + if duration < 60 then + return format("%ds", duration) + end + if duration < 60 * 60 then + return format("%dm %02ds", duration/60, math.fmod(duration, 60)) + end + return format("%dh %dm", duration/(60 * 60), math.fmod(duration/60, 60)) +end + +function AC:PrintCooldowns() + AC:UpdateMyCooldown() + AC:CleanupCooldowns() + local cooldownsAtZero = {} + local remainingCooldowns = {} + for player, cooldownData in pairs(AC.db.factionrealm.knownCooldowns) do + if cooldownData["finish"] == 0 then + table.insert(cooldownsAtZero, player) + else + table.insert(remainingCooldowns, {player, cooldownData["finish"]}) + end + end + table.sort(cooldownsAtZero) + if #cooldownsAtZero > 0 then + print(AC.CHAT_PREFIX .. format("%s: %s", L["Players with cooldown ready"], table.concat(cooldownsAtZero, ", "))) + end + local function compare(a,b) + return a[2] > b[2] + end + table.sort(remainingCooldowns, compare) + if #remainingCooldowns > 0 then + local playerStrings = {} + for _, c in pairs(remainingCooldowns) do + table.insert(playerStrings, c[1] .. " (" .. AC:FormatTime(c[2] - GetServerTime()) .. ")") + end + print(AC.CHAT_PREFIX .. format("%s: %s", L["Players on cooldown"], table.concat(playerStrings, ", "))) + end + if #cooldownsAtZero == 0 and #remainingCooldowns == 0 then + print(AC.CHAT_PREFIX .. L["No known cooldowns"]) + end +end + +function AC:IsVersionInvalidForComms(ver, commsVer) + ver = tonumber(ver) + commsVer = tonumber(commsVer) + if not AC.foundOldVersion and ver ~= nil and ver > AC.VERSION then + print(AC.CHAT_PREFIX .. format(L["oldVersionErr"], GetVersionString(AC.VERSION))) + AC.foundOldVersion = true + end + if commsVer ~= AC.COMMS_VER then + return true + end + return false +end + +function AC:OnQuestionCooldowns(prefix, msg, distribution, sender) + if sender == UnitName("player") then return end + msg = AC.LibDeflate:DecompressDeflate(AC.LibDeflate:DecodeForWoWAddonChannel(msg)) + local ver, commsVer = strsplit("#", msg) + if AC:IsVersionInvalidForComms(ver, commsVer) then return end + if AC.DEBUG then + print("REC:" .. prefix .. " " .. sender .. " " .. msg) + end + AC:UpdateMyCooldown() + AC:CleanupCooldowns() + local playersWithDurations = {} + for player, cooldownData in pairs(AC.db.factionrealm.knownCooldowns) do + table.insert(playersWithDurations, player .. ":" .. cooldownData["finish"] .. ":" .. cooldownData["lastUpdate"]) + end + if #playersWithDurations > 0 then + if sendAllCooldownsTimer then AC:CancelTimer(sendAllCooldownsTimer, true); sendAllCooldownsTimer = nil; end + sendAllCooldownsTimer = AC:ScheduleTimer(function() + AC:SendMessage(AC.SendAllCooldowns, AC.VERSION .. "#" .. AC.COMMS_VER .. "#" .. table.concat(playersWithDurations, ","), "GUILD") + sendAllCooldownsTimer = nil + end, random() * 10) + end +end + +function AC:OnSendKnownCooldown(prefix, msg, distribution, sender) + if sender == UnitName("player") then return end + msg = AC.LibDeflate:DecompressDeflate(AC.LibDeflate:DecodeForWoWAddonChannel(msg)) + local ver, commsVer, cooldownData = strsplit("#", msg) + if AC:IsVersionInvalidForComms(ver, commsVer) then return end + if AC.DEBUG then + print("REC:" .. prefix .. " " .. sender .. " " .. msg) + end + local player, finish, lastUpdate = strsplit(":", cooldownData) + finish = tonumber(finish) + lastUpdate = tonumber(lastUpdate) + AC.db.factionrealm.knownCooldowns[player] = { + ["finish"] = finish, + ["lastUpdate"] = lastUpdate + } +end + +function AC:OnSendAllCooldowns(prefix, msg, distribution, sender) + if sender == UnitName("player") then return end + msg = AC.LibDeflate:DecompressDeflate(AC.LibDeflate:DecodeForWoWAddonChannel(msg)) + local ver, commsVer, cooldownDatas = strsplit("#", msg) + if AC:IsVersionInvalidForComms(ver, commsVer) then return end + if AC.DEBUG then + print("REC:" .. prefix .. " " .. sender .. " " .. msg) + end + if requestCooldownsTimer then AC:CancelTimer(requestCooldownsTimer, true); requestCooldownsTimer = nil; end + if sendAllCooldownsTimer then AC:CancelTimer(sendAllCooldownsTimer, true); sendAllCooldownsTimer = nil; end + AC:UpdateMyCooldown() + AC:CleanupCooldowns() + local sentPlayers = {} + local newerDataNum = 0 + for _, cooldownData in pairs(splitString(cooldownDatas, ",")) do + local player, finish, lastUpdate = strsplit(":", cooldownData) + finish = tonumber(finish) + lastUpdate = tonumber(lastUpdate) + sentPlayers[player] = true + local storedCooldownData = AC.db.factionrealm.knownCooldowns[player] + if not storedCooldownData then + AC.db.factionrealm.knownCooldowns[player] = { + ["finish"] = finish, + ["lastUpdate"] = lastUpdate, + } + elseif lastUpdate - storedCooldownData["lastUpdate"] > 60 then + storedCooldownData["finish"] = finish + storedCooldownData["lastUpdate"] = lastUpdate + elseif storedCooldownData["lastUpdate"] - lastUpdate > 60 then + newerDataNum = newerDataNum + 1 + end + end + for player, _ in pairs(AC.db.factionrealm.knownCooldowns) do + if not sentPlayers[player] then + newerDataNum = newerDataNum + 1 + end + end + if newerDataNum > 0 then + sendAllCooldownsTimer = AC:ScheduleTimer(function() + local playersWithDurations = {} + for player, cooldownData in pairs(AC.db.factionrealm.knownCooldowns) do + table.insert(playersWithDurations, player .. ":" .. cooldownData["finish"] .. ":" .. cooldownData["lastUpdate"]) + end + AC:SendMessage(AC.SendAllCooldowns, AC.VERSION .. "#" .. AC.COMMS_VER .. "#" .. table.concat(playersWithDurations, ","), "GUILD") + sendAllCooldownsTimer = nil + end, random() * 10) + end +end + +function AC:ChatCommand(input) + input = strtrim(input) + if input == L["config"] then + AC:ToggleConfigWindow() + elseif input == L["cds"] then + AC:PrintCooldowns() + elseif input == L["mmb"] then + local minimap = not AC:getMinimap() + AC:setMinimap(nil, minimap) + if minimap then + print(AC.CHAT_PREFIX .. L["minimapShown"]) + else + print(AC.CHAT_PREFIX .. L["minimapHidden"]) + end + else + print(format("/%s %s - %s\n/%s %s - %s\n/%s %s - %s", + L["arc"],L["config"], L["configConsole"], + L["arc"],L["cds"], L["cooldownsConsole"], + L["arc"],L["mmb"], L["toggleMinimapConsole"])) + end +end + +function AC:ToggleConfigWindow() + if AC.Dialog.OpenFrames["ArcaniteCoordinator"] then + AC.Dialog:Close("ArcaniteCoordinator") + else + AC.Dialog:Open("ArcaniteCoordinator") + end +end diff --git a/ArcaniteCoordinator.toc b/ArcaniteCoordinator.toc new file mode 100644 index 0000000..5276c59 --- /dev/null +++ b/ArcaniteCoordinator.toc @@ -0,0 +1,10 @@ +## Interface: 11304 +## Title: Arcanite Coordinator +## Author: psynct +## Version: 1.0.8 +## Notes: Coordinates arcanite cooldowns within your guild +## SavedVariables: ArcaniteCoordinatorDB + +embeds.xml +Locale\Locales.xml +ArcaniteCoordinator.lua diff --git a/Libs/Ace3.lua b/Libs/Ace3.lua new file mode 100644 index 0000000..3461a23 --- /dev/null +++ b/Libs/Ace3.lua @@ -0,0 +1,110 @@ + +-- This file is only there in standalone Ace3 and provides handy dev tool stuff I guess +-- for now only /rl to reload your UI :) +-- note the complete overkill use of AceAddon and console, ain't it cool? + +-- GLOBALS: next, loadstring, ReloadUI, geterrorhandler +-- GLOBALS: BINDING_HEADER_ACE3, BINDING_NAME_RELOADUI, Ace3, LibStub + +-- BINDINGs labels +BINDING_HEADER_ACE3 = "Ace3" +BINDING_NAME_RELOADUI = "ReloadUI" +-- + +local gui = LibStub("AceGUI-3.0") +local reg = LibStub("AceConfigRegistry-3.0") +local dialog = LibStub("AceConfigDialog-3.0") + +Ace3 = LibStub("AceAddon-3.0"):NewAddon("Ace3", "AceConsole-3.0") +local Ace3 = Ace3 + +local selectedgroup +local frame +local select +local status = {} +local configs = {} + +local function frameOnClose() + gui:Release(frame) + frame = nil +end + +local function RefreshConfigs() + for name in reg:IterateOptionsTables() do + configs[name] = name + end +end + +local function ConfigSelected(widget, event, value) + selectedgroup = value + dialog:Open(value, widget) +end + +local old_CloseSpecialWindows + +-- GLOBALS: CloseSpecialWindows, next +function Ace3:Open() + if not old_CloseSpecialWindows then + old_CloseSpecialWindows = CloseSpecialWindows + CloseSpecialWindows = function() + local found = old_CloseSpecialWindows() + if frame then + frame:Hide() + return true + end + return found + end + end + RefreshConfigs() + if next(configs) == nil then + self:Print("No Configs are Registered") + return + end + + if not frame then + frame = gui:Create("Frame") + frame:ReleaseChildren() + frame:SetTitle("Ace3 Options") + frame:SetLayout("FILL") + frame:SetCallback("OnClose", frameOnClose) + + select = gui:Create("DropdownGroup") + select:SetGroupList(configs) + select:SetCallback("OnGroupSelected", ConfigSelected) + frame:AddChild(select) + end + if not selectedgroup then + selectedgroup = next(configs) + end + select:SetGroup(selectedgroup) + frame:Show() +end + +local function RefreshOnUpdate(this) + select:SetGroup(selectedgroup) + this:SetScript("OnUpdate", nil) +end + +function Ace3:ConfigTableChanged(event, appName) + if selectedgroup == appName and frame then + frame.frame:SetScript("OnUpdate", RefreshOnUpdate) + end +end + +reg.RegisterCallback(Ace3, "ConfigTableChange", "ConfigTableChanged") + +function Ace3:PrintCmd(input) + input = input:trim():match("^(.-);*$") + local func, err = loadstring("LibStub(\"AceConsole-3.0\"):Print(" .. input .. ")") + if not func then + LibStub("AceConsole-3.0"):Print("Error: " .. err) + else + func() + end +end + +function Ace3:OnInitialize() + self:RegisterChatCommand("ace3", function() self:Open() end) + self:RegisterChatCommand("rl", function() ReloadUI() end) + self:RegisterChatCommand("print", "PrintCmd") +end diff --git a/Libs/Ace3.toc b/Libs/Ace3.toc new file mode 100644 index 0000000..c09238e --- /dev/null +++ b/Libs/Ace3.toc @@ -0,0 +1,27 @@ +## Interface: 80300 + +## Title: Lib: Ace3 +## Notes: AddOn development framework +## Author: Ace3 Development Team +## X-Website: http://www.wowace.com +## X-Category: Library +## X-License: Limited BSD + +LibStub\LibStub.lua +CallbackHandler-1.0\CallbackHandler-1.0.xml +AceAddon-3.0\AceAddon-3.0.xml +AceEvent-3.0\AceEvent-3.0.xml +AceTimer-3.0\AceTimer-3.0.xml +AceBucket-3.0\AceBucket-3.0.xml +AceHook-3.0\AceHook-3.0.xml +AceDB-3.0\AceDB-3.0.xml +AceDBOptions-3.0\AceDBOptions-3.0.xml +AceLocale-3.0\AceLocale-3.0.xml +AceConsole-3.0\AceConsole-3.0.xml +AceGUI-3.0\AceGUI-3.0.xml +AceConfig-3.0\AceConfig-3.0.xml +AceComm-3.0\AceComm-3.0.xml +AceTab-3.0\AceTab-3.0.xml +AceSerializer-3.0\AceSerializer-3.0.xml + +Ace3.lua diff --git a/Libs/AceAddon-3.0/AceAddon-3.0.lua b/Libs/AceAddon-3.0/AceAddon-3.0.lua new file mode 100644 index 0000000..2b2a00e --- /dev/null +++ b/Libs/AceAddon-3.0/AceAddon-3.0.lua @@ -0,0 +1,643 @@ +--- **AceAddon-3.0** provides a template for creating addon objects. +-- It'll provide you with a set of callback functions that allow you to simplify the loading +-- process of your addon.\\ +-- Callbacks provided are:\\ +-- * **OnInitialize**, which is called directly after the addon is fully loaded. +-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present. +-- * **OnDisable**, which is only called when your addon is manually being disabled. +-- @usage +-- -- A small (but complete) addon, that doesn't do anything, +-- -- but shows usage of the callbacks. +-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- +-- function MyAddon:OnInitialize() +-- -- do init tasks here, like loading the Saved Variables, +-- -- or setting up slash commands. +-- end +-- +-- function MyAddon:OnEnable() +-- -- Do more initialization here, that really enables the use of your addon. +-- -- Register Events, Hook functions, Create Frames, Get information from +-- -- the game that wasn't available in OnInitialize +-- end +-- +-- function MyAddon:OnDisable() +-- -- Unhook, Unregister Events, Hide frames that you created. +-- -- You would probably only use an OnDisable if you want to +-- -- build a "standby" mode, or be able to toggle modules on/off. +-- end +-- @class file +-- @name AceAddon-3.0.lua +-- @release $Id: AceAddon-3.0.lua 1202 2019-05-15 23:11:22Z nevcairiel $ + +local MAJOR, MINOR = "AceAddon-3.0", 12 +local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) + +if not AceAddon then return end -- No Upgrade needed. + +AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame +AceAddon.addons = AceAddon.addons or {} -- addons in general +AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon. +AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized +AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled +AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon + +-- Lua APIs +local tinsert, tconcat, tremove = table.insert, table.concat, table.remove +local fmt, tostring = string.format, tostring +local select, pairs, next, type, unpack = select, pairs, next, type, unpack +local loadstring, assert, error = loadstring, assert, error +local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget + +-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded +-- List them here for Mikk's FindGlobals script +-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler + +--[[ + xpcall safecall implementation +]] +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function safecall(func, ...) + -- we check to see if the func is passed is actually a function here and don't error when it isn't + -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not + -- present execution should continue without hinderance + if type(func) == "function" then + return xpcall(func, errorhandler, ...) + end +end + +-- local functions that will be implemented further down +local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype + +-- used in the addon metatable +local function addontostring( self ) return self.name end + +-- Check if the addon is queued for initialization +local function queuedForInitialization(addon) + for i = 1, #AceAddon.initializequeue do + if AceAddon.initializequeue[i] == addon then + return true + end + end + return false +end + +--- Create a new AceAddon-3.0 addon. +-- Any libraries you specified will be embeded, and the addon will be scheduled for +-- its OnInitialize and OnEnable callbacks. +-- The final addon object, with all libraries embeded, will be returned. +-- @paramsig [object ,]name[, lib, ...] +-- @param object Table to use as a base for the addon (optional) +-- @param name Name of the addon object to create +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a simple addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0") +-- +-- -- Create a Addon object based on the table of a frame +-- local MyFrame = CreateFrame("Frame") +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") +function AceAddon:NewAddon(objectorname, ...) + local object,name + local i=1 + if type(objectorname)=="table" then + object=objectorname + name=... + i=2 + else + name=objectorname + end + if type(name)~="string" then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) + end + if self.addons[name] then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2) + end + + object = object or {} + object.name = name + + local addonmeta = {} + local oldmeta = getmetatable(object) + if oldmeta then + for k, v in pairs(oldmeta) do addonmeta[k] = v end + end + addonmeta.__tostring = addontostring + + setmetatable( object, addonmeta ) + self.addons[name] = object + object.modules = {} + object.orderedModules = {} + object.defaultModuleLibraries = {} + Embed( object ) -- embed NewModule, GetModule methods + self:EmbedLibraries(object, select(i,...)) + + -- add to queue of addons to be initialized upon ADDON_LOADED + tinsert(self.initializequeue, object) + return object +end + + +--- Get the addon object by its name from the internal AceAddon registry. +-- Throws an error if the addon object cannot be found (except if silent is set). +-- @param name unique name of the addon object +-- @param silent if true, the addon is optional, silently return nil if its not found +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +function AceAddon:GetAddon(name, silent) + if not silent and not self.addons[name] then + error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2) + end + return self.addons[name] +end + +-- - Embed a list of libraries into the specified addon. +-- This function will try to embed all of the listed libraries into the addon +-- and error if a single one fails. +-- +-- **Note:** This function is for internal use by :NewAddon/:NewModule +-- @paramsig addon, [lib, ...] +-- @param addon addon object to embed the libs in +-- @param lib List of libraries to embed into the addon +function AceAddon:EmbedLibraries(addon, ...) + for i=1,select("#", ... ) do + local libname = select(i, ...) + self:EmbedLibrary(addon, libname, false, 4) + end +end + +-- - Embed a library into the addon object. +-- This function will check if the specified library is registered with LibStub +-- and if it has a :Embed function to call. It'll error if any of those conditions +-- fails. +-- +-- **Note:** This function is for internal use by :EmbedLibraries +-- @paramsig addon, libname[, silent[, offset]] +-- @param addon addon object to embed the library in +-- @param libname name of the library to embed +-- @param silent marks an embed to fail silently if the library doesn't exist (optional) +-- @param offset will push the error messages back to said offset, defaults to 2 (optional) +function AceAddon:EmbedLibrary(addon, libname, silent, offset) + local lib = LibStub:GetLibrary(libname, true) + if not lib and not silent then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2) + elseif lib and type(lib.Embed) == "function" then + lib:Embed(addon) + tinsert(self.embeds[addon], libname) + return true + elseif lib then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2) + end +end + +--- Return the specified module from an addon object. +-- Throws an error if the addon object cannot be found (except if silent is set) +-- @name //addon//:GetModule +-- @paramsig name[, silent] +-- @param name unique name of the module +-- @param silent if true, the module is optional, silently return nil if its not found (optional) +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- -- Get the Module +-- MyModule = MyAddon:GetModule("MyModule") +function GetModule(self, name, silent) + if not self.modules[name] and not silent then + error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2) + end + return self.modules[name] +end + +local function IsModuleTrue(self) return true end + +--- Create a new module for the addon. +-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\ +-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as +-- an addon object. +-- @name //addon//:NewModule +-- @paramsig name[, prototype|lib[, lib, ...]] +-- @param name unique name of the module +-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional) +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a module with some embeded libraries +-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0") +-- +-- -- Create a module with a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") +function NewModule(self, name, prototype, ...) + if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end + if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end + + if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end + + -- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. + -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is. + local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name)) + + module.IsModule = IsModuleTrue + module:SetEnabledState(self.defaultModuleState) + module.moduleName = name + + if type(prototype) == "string" then + AceAddon:EmbedLibraries(module, prototype, ...) + else + AceAddon:EmbedLibraries(module, ...) + end + AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) + + if not prototype or type(prototype) == "string" then + prototype = self.defaultModulePrototype or nil + end + + if type(prototype) == "table" then + local mt = getmetatable(module) + mt.__index = prototype + setmetatable(module, mt) -- More of a Base class type feel. + end + + safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. + self.modules[name] = module + tinsert(self.orderedModules, module) + + return module +end + +--- Returns the real name of the addon or module, without any prefix. +-- @name //addon//:GetName +-- @paramsig +-- @usage +-- print(MyAddon:GetName()) +-- -- prints "MyAddon" +function GetName(self) + return self.moduleName or self.name +end + +--- Enables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback +-- and enabling all modules of the addon (unless explicitly disabled).\\ +-- :Enable() also sets the internal `enableState` variable to true +-- @name //addon//:Enable +-- @paramsig +-- @usage +-- -- Enable MyModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +function Enable(self) + self:SetEnabledState(true) + + -- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still + -- it'll be enabled after the init process + if not queuedForInitialization(self) then + return AceAddon:EnableAddon(self) + end +end + +--- Disables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback +-- and disabling all modules of the addon.\\ +-- :Disable() also sets the internal `enableState` variable to false +-- @name //addon//:Disable +-- @paramsig +-- @usage +-- -- Disable MyAddon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:Disable() +function Disable(self) + self:SetEnabledState(false) + return AceAddon:DisableAddon(self) +end + +--- Enables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object. +-- @name //addon//:EnableModule +-- @paramsig name +-- @usage +-- -- Enable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +-- +-- -- Enable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:EnableModule("MyModule") +function EnableModule(self, name) + local module = self:GetModule( name ) + return module:Enable() +end + +--- Disables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object. +-- @name //addon//:DisableModule +-- @paramsig name +-- @usage +-- -- Disable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Disable() +-- +-- -- Disable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:DisableModule("MyModule") +function DisableModule(self, name) + local module = self:GetModule( name ) + return module:Disable() +end + +--- Set the default libraries to be mixed into all modules created by this object. +-- Note that you can only change the default module libraries before any module is created. +-- @name //addon//:SetDefaultModuleLibraries +-- @paramsig lib[, lib, ...] +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Configure default libraries for modules (all modules need AceEvent-3.0) +-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0") +-- -- Create a module +-- MyModule = MyAddon:NewModule("MyModule") +function SetDefaultModuleLibraries(self, ...) + if next(self.modules) then + error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleLibraries = {...} +end + +--- Set the default state in which new modules are being created. +-- Note that you can only change the default state before any module is created. +-- @name //addon//:SetDefaultModuleState +-- @paramsig state +-- @param state Default state for new modules, true for enabled, false for disabled +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Set the default state to "disabled" +-- MyAddon:SetDefaultModuleState(false) +-- -- Create a module and explicilty enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +function SetDefaultModuleState(self, state) + if next(self.modules) then + error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleState = state +end + +--- Set the default prototype to use for new modules on creation. +-- Note that you can only change the default prototype before any module is created. +-- @name //addon//:SetDefaultModulePrototype +-- @paramsig prototype +-- @param prototype Default prototype for the new modules (table) +-- @usage +-- -- Define a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- -- Set the default prototype +-- MyAddon:SetDefaultModulePrototype(prototype) +-- -- Create a module and explicitly Enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +-- -- should print "OnEnable called!" now +-- @see NewModule +function SetDefaultModulePrototype(self, prototype) + if next(self.modules) then + error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) + end + if type(prototype) ~= "table" then + error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2) + end + self.defaultModulePrototype = prototype +end + +--- Set the state of an addon or module +-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize. +-- @name //addon//:SetEnabledState +-- @paramsig state +-- @param state the state of an addon or module (enabled=true, disabled=false) +function SetEnabledState(self, state) + self.enabledState = state +end + + +--- Return an iterator of all modules associated to the addon. +-- @name //addon//:IterateModules +-- @paramsig +-- @usage +-- -- Enable all modules +-- for name, module in MyAddon:IterateModules() do +-- module:Enable() +-- end +local function IterateModules(self) return pairs(self.modules) end + +-- Returns an iterator of all embeds in the addon +-- @name //addon//:IterateEmbeds +-- @paramsig +local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end + +--- Query the enabledState of an addon. +-- @name //addon//:IsEnabled +-- @paramsig +-- @usage +-- if MyAddon:IsEnabled() then +-- MyAddon:Disable() +-- end +local function IsEnabled(self) return self.enabledState end +local mixins = { + NewModule = NewModule, + GetModule = GetModule, + Enable = Enable, + Disable = Disable, + EnableModule = EnableModule, + DisableModule = DisableModule, + IsEnabled = IsEnabled, + SetDefaultModuleLibraries = SetDefaultModuleLibraries, + SetDefaultModuleState = SetDefaultModuleState, + SetDefaultModulePrototype = SetDefaultModulePrototype, + SetEnabledState = SetEnabledState, + IterateModules = IterateModules, + IterateEmbeds = IterateEmbeds, + GetName = GetName, +} +local function IsModule(self) return false end +local pmixins = { + defaultModuleState = true, + enabledState = true, + IsModule = IsModule, +} +-- Embed( target ) +-- target (object) - target object to embed aceaddon in +-- +-- this is a local function specifically since it's meant to be only called internally +function Embed(target, skipPMixins) + for k, v in pairs(mixins) do + target[k] = v + end + if not skipPMixins then + for k, v in pairs(pmixins) do + target[k] = target[k] or v + end + end +end + + +-- - Initialize the addon after creation. +-- This function is only used internally during the ADDON_LOADED event +-- It will call the **OnInitialize** function on the addon object (if present), +-- and the **OnEmbedInitialize** function on all embeded libraries. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- @param addon addon object to intialize +function AceAddon:InitializeAddon(addon) + safecall(addon.OnInitialize, addon) + + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedInitialize, lib, addon) end + end + + -- we don't call InitializeAddon on modules specifically, this is handled + -- from the event handler and only done _once_ +end + +-- - Enable the addon after creation. +-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED, +-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons. +-- It will call the **OnEnable** function on the addon object (if present), +-- and the **OnEmbedEnable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Enable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:EnableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if self.statuses[addon.name] or not addon.enabledState then return false end + + -- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable. + self.statuses[addon.name] = true + + safecall(addon.OnEnable, addon) + + -- make sure we're still enabled before continueing + if self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedEnable, lib, addon) end + end + + -- enable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:EnableAddon(modules[i]) + end + end + return self.statuses[addon.name] -- return true if we're disabled +end + +-- - Disable the addon +-- Note: This function is only used internally. +-- It will call the **OnDisable** function on the addon object (if present), +-- and the **OnEmbedDisable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Disable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:DisableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if not self.statuses[addon.name] then return false end + + -- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable. + self.statuses[addon.name] = false + + safecall( addon.OnDisable, addon ) + + -- make sure we're still disabling... + if not self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedDisable, lib, addon) end + end + -- disable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:DisableAddon(modules[i]) + end + end + + return not self.statuses[addon.name] -- return true if we're disabled +end + +--- Get an iterator over all registered addons. +-- @usage +-- -- Print a list of all installed AceAddon's +-- for name, addon in AceAddon:IterateAddons() do +-- print("Addon: " .. name) +-- end +function AceAddon:IterateAddons() return pairs(self.addons) end + +--- Get an iterator over the internal status registry. +-- @usage +-- -- Print a list of all enabled addons +-- for name, status in AceAddon:IterateAddonStatus() do +-- if status then +-- print("EnabledAddon: " .. name) +-- end +-- end +function AceAddon:IterateAddonStatus() return pairs(self.statuses) end + +-- Following Iterators are deprecated, and their addon specific versions should be used +-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon) +function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end +function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end + +-- Event Handling +local function onEvent(this, event, arg1) + -- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up + if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then + -- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration + while(#AceAddon.initializequeue > 0) do + local addon = tremove(AceAddon.initializequeue, 1) + -- this might be an issue with recursion - TODO: validate + if event == "ADDON_LOADED" then addon.baseName = arg1 end + AceAddon:InitializeAddon(addon) + tinsert(AceAddon.enablequeue, addon) + end + + if IsLoggedIn() then + while(#AceAddon.enablequeue > 0) do + local addon = tremove(AceAddon.enablequeue, 1) + AceAddon:EnableAddon(addon) + end + end + end +end + +AceAddon.frame:RegisterEvent("ADDON_LOADED") +AceAddon.frame:RegisterEvent("PLAYER_LOGIN") +AceAddon.frame:SetScript("OnEvent", onEvent) + +-- upgrade embeded +for name, addon in pairs(AceAddon.addons) do + Embed(addon, true) +end + +-- 2010-10-27 nevcairiel - add new "orderedModules" table +if oldminor and oldminor < 10 then + for name, addon in pairs(AceAddon.addons) do + addon.orderedModules = {} + for module_name, module in pairs(addon.modules) do + tinsert(addon.orderedModules, module) + end + end +end diff --git a/Libs/AceAddon-3.0/AceAddon-3.0.xml b/Libs/AceAddon-3.0/AceAddon-3.0.xml new file mode 100644 index 0000000..dcf24c7 --- /dev/null +++ b/Libs/AceAddon-3.0/AceAddon-3.0.xml @@ -0,0 +1,4 @@ + +