initial commit

This commit is contained in:
pepopo978
2024-05-26 15:26:51 -07:00
commit 0c8d273b60
44 changed files with 17516 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
+18
View File
@@ -0,0 +1,18 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JsonStandardCompliance" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="3">
<item index="0" class="java.lang.String" itemvalue="wsgiref" />
<item index="1" class="java.lang.String" itemvalue="whitenoise" />
<item index="2" class="java.lang.String" itemvalue="gunicorn" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
+6
View File
@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.8 (yahtzee)" />
</component>
<component name="NodePackageJsonFileManager">
<packageJsonPaths />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (yahtzee)" project-jdk-type="Python SDK" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Cursive.iml" filepath="$PROJECT_DIR$/.idea/Cursive.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+33
View File
@@ -0,0 +1,33 @@
## Interface: 11200
## Title: Cursive
## Author: Pepopo
## Notes: Uses SuperWoW GUIDs to show units in combat and track curses
## Version: 1.0
## SavedVariablesPerCharacter: CursiveDB
## X-Embeds: Ace2, FuBarPlugin-2.0, CompostLib, DewDropLib, TabletLib
Libs\AceOO-2.0\AceOO-2.0.lua
Libs\AceAddon-2.0\AceAddon-2.0.lua
Libs\AceConsole-2.0\AceConsole-2.0.lua
Libs\AceHook-2.1\AceHook-2.1.lua
Libs\AceDB-2.0\AceDB-2.0.lua
Libs\AceDebug-2.0\AceDebug-2.0.lua
Libs\AceEvent-2.0\AceEvent-2.0.lua
Libs\AceLocale-2.2\AceLocale-2.2.lua
Libs\AceModuleCore-2.0\AceModuleCore-2.0.lua
Libs\Dewdrop\Dewdrop-2.0.lua
Libs\Tablet\Tablet-2.0.lua
Libs\FuBarPlugin\FuBarPlugin-2.0.lua
global.lua
utils.lua
settings.lua
core.lua
spells\druid.lua
spells\hunter.lua
spells\mage.lua
spells\warlock.lua
curses.lua
filter.lua
ui.lua
commands.lua
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2024 Eric Mauser (Shagu)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+17
View File
@@ -0,0 +1,17 @@
# Cursive
> [!IMPORTANT]
>
> **This addon requires you to have [SuperWoW](https://github.com/balakethelock/SuperWoW) installed.**
>
> It won't work without it. Really.
Cursive combines ShaguScan unit scanning with curse tracking similar to DotTimer and the ability to automatically curse targets similar to Decursive.
`/cursive` for commands, minimap icon to edit options.
`/cursive curse <spellName:str>|<guid?:str>|<noFailureWarning:int[0,1]`: Casts spell if not already on target/guid",
EXAMPLE: `/cursive curse Corruption|target|1` will attempt to cast Corruption on your target if it's not already on them and won't warn you if it does nothing.
`/cursive multicurse <spellName:str>|<priority?:str>|<noFailureWarning:int[0,1]`: Picks target based on priority and casts spell if not already on target. Priority options: HIGHEST_HP, RAID_MARK.",
EXAMPLE: `/cursive multicurse Corruption|HIGHEST_HP` will attempt to cast Corruption picking the target with the highest HP that doesn't already have it and will warn you if it does nothing.
+228
View File
@@ -0,0 +1,228 @@
local curseCommands = "|cffffcc00Cursive:|cffffaaaa Commands:"
local commands = {
["curse"] = "/cursive curse <spellName:str>|<guid?:str>|<noFailureWarning:int[0,1]: Casts spell if not already on target/guid",
["multicurse"] = "/cursive multicurse <spellName:str>|<priority?:str>|<noFailureWarning:int[0,1]: Picks target based on priority and casts spell if not already on target. Priority options: HIGHEST_HP, RAID_MARK.",
}
local curseNoTarget = "|cffffcc00Cursive:|cffffaaaa Couldn't find a target to curse."
local function handleSlashCommands(msg, editbox)
if not msg or msg == "" then
DEFAULT_CHAT_FRAME:AddMessage(curseCommands)
for command, description in pairs(commands) do
DEFAULT_CHAT_FRAME:AddMessage(description)
end
return
end
-- get first word in string
local _, _, command, args = string.find(msg, "(%w+) (.*)")
if command == "curse" then
local spellName, targetedGuid, noFailureWarning = Cursive.utils.strsplit("|", args)
Cursive:Curse(spellName, targetedGuid, noFailureWarning)
elseif command == "multicurse" then
local spellName, priority, noFailureWarning = Cursive.utils.strsplit("|", args)
Cursive:Multicurse(spellName, priority, noFailureWarning)
end
end
local crowdControlledSpellIds = {
[700] = { name = "Sleep", rank = 1, duration = 20 },
[1090] = { name = "Sleep", rank = 2, duration = 30 },
[2937] = { name = "Sleep", rank = 3, duration = 40 },
[339] = { name = "Entangling Roots", rank = 1, duration = 12 },
[1062] = { name = "Entangling Roots", rank = 2, duration = 15 },
[5195] = { name = "Entangling Roots", rank = 3, duration = 18 },
[5196] = { name = "Entangling Roots", rank = 4, duration = 21 },
[9852] = { name = "Entangling Roots", rank = 5, duration = 24 },
[9853] = { name = "Entangling Roots", rank = 6, duration = 27 },
[1425] = { name = "Shackle Undead", rank = 1, duration = 30 },
[9486] = { name = "Shackle Undead", rank = 2, duration = 40 },
[10956] = { name = "Shackle Undead", rank = 3, duration = 50 },
-- polymorph
[118] = { name = "Polymorph", rank = "Rank 1", duration = 20 },
[12824] = { name = "Polymorph", rank = "Rank 2", duration = 30 },
[12825] = { name = "Polymorph", rank = "Rank 3", duration = 40 },
[12826] = { name = "Polymorph", rank = "Rank 4", duration = 50 },
[28270] = { name = "Polymorph: Cow", rank = "Rank 1", duration = 50 },
[28271] = { name = "Polymorph: Turtle", rank = "Rank 1", duration = 50 },
[28272] = { name = "Polymorph: Pig", rank = "Rank 1", duration = 50 },
[2878] = { name = "Turn Undead", rank = 1, duration = 10 },
[5627] = { name = "Turn Undead", rank = 2, duration = 15 },
[10326] = { name = "Turn Undead", rank = 3, duration = 20 },
[2094] = { name = "Blind", rank = 1, duration = 10 },
[21060] = { name = "Blind", rank = 1, duration = 10 },
[6770] = { name = "Sap", rank = 1, duration = 25 },
[2070] = { name = "Sap", rank = 2, duration = 35 },
[11297] = { name = "Sap", rank = 3, duration = 45 },
[1776] = { name = "Gouge", rank = 1, duration = 4 },
[1777] = { name = "Gouge", rank = 2, duration = 4 },
[8629] = { name = "Gouge", rank = 3, duration = 4 },
[11285] = { name = "Gouge", rank = 4, duration = 4 },
[11286] = { name = "Gouge", rank = 5, duration = 4 },
}
local function isMobCrowdControlled(guid)
-- check if mob is CC'ed
-- check debuffs
for i = 1, 16 do
local _, _, _, spellId = UnitDebuff(guid, i)
if spellId then
if crowdControlledSpellIds[spellId] then
return true
end
else
break
end
end
-- check buffs
for i = 1, 32 do
local _, _, spellId = UnitBuff(guid, i)
if spellId then
if crowdControlledSpellIds[spellId] then
return true
end
else
break
end
end
return false
end
local function pickHighestHpTarget(selectedPriority, spellNameNoRank, skipCheckRange)
-- Curse the target with the highest HP
local highestHP = 0
local targetedGuid = nil
for guid, time in pairs(Cursive.core.guids) do
-- apply filters
local shouldDisplay = Cursive:ShouldDisplayGuid(guid)
-- check if target exists/displayed/infight
if UnitExists(guid) and shouldDisplay and Cursive.filter.infight(guid) then
if not skipCheckRange and CheckInteractDistance(guid, 4) then
-- check if the target has the curse
if not Cursive.curses:HasCurse(spellNameNoRank, guid) and not isMobCrowdControlled(guid) then
local health = UnitHealth(guid)
if health > highestHP then
highestHP = health
targetedGuid = guid
end
end
end
end
end
-- run again if no target found ignoring range
if not targetedGuid and not skipCheckRange then
targetedGuid = pickHighestHpTarget(selectedPriority, spellNameNoRank, true)
end
return targetedGuid
end
local function pickRaidMarkTarget(selectedPriority, spellNameNoRank, skipCheckRange)
-- Curse the target with the highest raid mark
local highestMark = 0
local targetedGuid = nil
for guid, time in pairs(Cursive.core.guids) do
-- apply filters
local shouldDisplay = Cursive:ShouldDisplayGuid(guid)
-- check if target exists/displayed/infight
if UnitExists(guid) and shouldDisplay and Cursive.filter.infight(guid) then
if not skipCheckRange and CheckInteractDistance(guid, 4) then
-- check if the target has the curse
if not Cursive.curses:HasCurse(spellNameNoRank, guid) and not isMobCrowdControlled(guid) then
local raidMark = GetRaidTargetIndex(guid)
if not raidMark or raidMark == 0 then
if highestMark == 0 then
targetedGuid = guid
end
else
if raidMark > highestMark then
highestMark = raidMark
targetedGuid = guid
end
end
end
end
end
end
-- run again if no target found ignoring range
if not targetedGuid and not skipCheckRange then
targetedGuid = pickRaidMarkTarget(selectedPriority, spellNameNoRank, true)
end
return targetedGuid
end
function Cursive:Curse(spellName, targetedGuid, noFailureWarning)
if not spellName or not targetedGuid then
DEFAULT_CHAT_FRAME:AddMessage(commands["curse"])
return
end
if targetedGuid and string.sub(targetedGuid, 1, 2) ~= "0x" then
_, targetedGuid = UnitExists(targetedGuid)
if not targetedGuid then
if not (noFailureWarning and noFailureWarning == "1") then
DEFAULT_CHAT_FRAME:AddMessage(curseNoTarget)
end
return
end
end
-- remove (Rank x) from spellName if it exists
local spellNameNoRank = string.gsub(spellName, "%(.+%)", "")
if targetedGuid and not Cursive.curses:HasCurse(spellNameNoRank, targetedGuid) and not isMobCrowdControlled(targetedGuid) then
CastSpellByName(spellName, targetedGuid)
elseif not (noFailureWarning and noFailureWarning == "1") then
DEFAULT_CHAT_FRAME:AddMessage(curseNoTarget)
end
end
function Cursive:Multicurse(spellName, priority, noFailureWarning)
if not spellName then
DEFAULT_CHAT_FRAME:AddMessage(commands["multicurse"])
return
end
local selectedPriority = priority or "HIGHEST_HP"
-- remove (Rank x) from spellName if it exists
local spellNameNoRank = string.gsub(spellName, "%(.+%)", "")
if not targetedGuid then
if selectedPriority == "HIGHEST_HP" then
targetedGuid = pickHighestHpTarget(selectedPriority, spellNameNoRank)
elseif selectedPriority == "RAID_MARK" then
targetedGuid = pickRaidMarkTarget(selectedPriority, spellNameNoRank)
else
DEFAULT_CHAT_FRAME:AddMessage(multiCurseUsage)
return
end
end
if targetedGuid then
CastSpellByName(spellName, targetedGuid)
elseif not (noFailureWarning and noFailureWarning == "1") then
DEFAULT_CHAT_FRAME:AddMessage(curseNoTarget)
end
end
SLASH_CURSIVE1 = "/cursive" --creating the slash command
SlashCmdList["CURSIVE"] = handleSlashCommands --associating the function with the slash command
+60
View File
@@ -0,0 +1,60 @@
if not Cursive.superwow then
return
end
-- add (1) for first stack of buffs/debuffs
-- other addons already do this, avoid having to parse both formats
AURAADDEDOTHERHELPFUL = "%s gains %s (1)."
AURAADDEDOTHERHARMFUL = "%s is afflicted by %s (1)."
AURAADDEDSELFHARMFUL = "You are afflicted by %s (1)."
AURAADDEDSELFHELPFUL = "You gain %s (1)."
Cursive.core = CreateFrame("Frame", "Cursive", UIParent)
Cursive.core:RegisterEvent("ADDON_LOADED")
Cursive.core.guids = {}
Cursive.core.add = function(unit)
local _, guid = UnitExists(unit)
if guid then
Cursive.core.guids[guid] = GetTime()
end
end
Cursive.core.addGuid = function(guid)
-- check if first two characters are 0x
if string.sub(guid, 1, 2) ~= "0x" then
return
end
Cursive.core.guids[guid] = GetTime()
end
Cursive.core.remove = function(guid)
Cursive.core.guids[guid] = nil
end
Cursive.core.enable = function()
-- unitstr
Cursive.core:RegisterEvent("PLAYER_TARGET_CHANGED")
-- arg1
Cursive.core:RegisterEvent("UNIT_COMBAT") -- this can get called with player/target/raid1 etc
Cursive.core:RegisterEvent("UNIT_MODEL_CHANGED")
end
Cursive.core.disable = function()
Cursive.core:UnregisterAllEvents()
Cursive.core.guids = {}
end
Cursive.core:SetScript("OnEvent", function()
if event == "ADDON_LOADED" and arg1 == "Cursive" then
if Cursive.db.profile.enabled then
Cursive.core.enable()
end
elseif event == "PLAYER_TARGET_CHANGED" then
this.add("target")
else
-- arg1 is guid
this.addGuid(arg1)
end
end)
+100
View File
@@ -0,0 +1,100 @@
local curses = {
trackedCurseIds = {},
trackedCurseNamesToTextures = {},
guids = {},
}
Cursive.curses = curses
-- combat events for curses
local afflict_test = "^(.+) is afflicted by (.+) %((%d+)%)" -- for stacks 2-5 will be "Fire Vulnerability (2)".
local gains_test = "^(.+) gains (.+) %((%d+)%)" -- for stacks 2-5 will be "Fire Vulnerability (2)".
local fades_test = "(.+) fades from (.+)."
local resist_test = "Your (.+) was resisted by (.+)"
local lastGuid = nil
-- curses to track
local _, className = UnitClass("player")
if className == "WARLOCK" then
curses.trackedCurseIds = getWarlockSpells()
elseif className == "PRIEST" then
curses.trackedCurseIds = getPriestSpells()
elseif className == "MAGE" then
curses.trackedCurseIds = getMageSpells()
elseif className == "DRUID" then
curses.trackedCurseIds = getDruidSpells()
elseif className == "HUNTER" then
curses.trackedCurseIds = getHunterSpells()
elseif className == "ROGUE" then
curses.trackedCurseIds = getRogueSpells()
end
curses.trackedCurseNamesToTextures = {}
for id, data in pairs(curses.trackedCurseIds) do
-- get the texture
local name, rank, texture = SpellInfo(id)
-- update trackedCurseNamesToTextures
curses.trackedCurseNamesToTextures[data.name] = texture
-- update trackedCurseIds
curses.trackedCurseIds[id].texture = texture
end
Cursive:RegisterEvent("UNIT_CASTEVENT", function(casterGuid, targetGuid, event, spellID, castDuration)
-- immolate will fire both start and cast
if event == "CAST" then
local _, guid = UnitExists("player")
if casterGuid ~= guid then
return
end
if curses.trackedCurseIds[spellID] then
lastGuid = targetGuid
Cursive:ScheduleEvent("addCurse" .. targetGuid .. curses.trackedCurseIds[spellID].name, curses.ApplyCurse, 0.2, self, spellID, targetGuid, GetTime())
end
end
end)
Cursive:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE",
function(message)
-- check for resist
local _, _, spell, target = string.find(message, resist_test)
if spell and target then
if curses.trackedCurseNamesToTextures[spell] and lastGuid then
Cursive:CancelScheduledEvent("addCurse" .. lastGuid .. spell)
end
end
end
) -- resists
function curses:TimeRemaining(curseData)
return math.ceil(curseData.duration - (GetTime() - curseData.start))
end
function curses:HasCurse(spellName, targetGuid)
if curses.guids[targetGuid] and curses.guids[targetGuid][spellName] then
local remaining = Cursive.curses:TimeRemaining(curses.guids[targetGuid][spellName])
return remaining > 0
end
return false
end
function curses:ApplyCurse(spellID, targetGuid, startTime)
local name = curses.trackedCurseIds[spellID].name
local rank = curses.trackedCurseIds[spellID].rank
local duration = curses.trackedCurseIds[spellID].duration
if not curses.guids[targetGuid] then
curses.guids[targetGuid] = {}
end
curses.guids[targetGuid][name] = {
rank = rank,
duration = duration,
start = startTime,
spellID = spellID,
}
end
function curses:RemoveGuid(guid)
curses.guids[guid] = nil
end
+76
View File
@@ -0,0 +1,76 @@
if not Cursive.superwow then
return
end
local filter = {
"infight",
"alive",
"hostile",
"attackable",
}
filter.attackable = function(unit)
return UnitCanAttack("player", unit) and true or false
end
filter.infight = function(unit)
return UnitAffectingCombat(unit) and true or false
end
filter.alive = function(unit)
return not UnitIsDead(unit) and true or false
end
filter.range = function(unit)
return CheckInteractDistance(unit, 4) and true or false
end
filter.icon = function(unit)
return GetRaidTargetIndex(unit) and true or false
end
filter.normal = function(unit)
local elite = UnitClassification(unit)
return elite == "normal" and true or false
end
filter.elite = function(unit)
local elite = UnitClassification(unit)
return (elite == "elite" or elite == "rareelite") and true or false
end
filter.hostile = function(unit)
return UnitIsEnemy("player", unit) and true or false
end
filter.range = function(unit)
return CheckInteractDistance(unit, 4) and true or false
end
Cursive.filter = filter
function Cursive:ShouldDisplayGuid(guid)
local exists, targetGuid = UnitExists("target")
-- always show target if attackable
if (targetGuid == guid) == true and filter.attackable(guid) then
return true
end
-- always show raid marks if attackable
if filter.icon(guid) and filter.attackable(guid) then
return true
end
-- apply filters
local shouldDisplay = true -- default to true
-- otherwise apply filters
for id, filter_name in pairs(Cursive.filter) do
if filter[filter_name] then
shouldDisplay = shouldDisplay and filter[filter_name](guid)
end
end
return shouldDisplay
end
+17
View File
@@ -0,0 +1,17 @@
Cursive = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceDebug-2.0", "AceModuleCore-2.0", "AceConsole-2.0", "AceDB-2.0", "AceHook-2.1")
Cursive.superwow = true
if not GetPlayerBuffID or not CombatLogAdd or not SpellInfo then
local notify = CreateFrame("Frame", nil, UIParent)
notify:SetScript("OnUpdate", function()
DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00Cursive:|cffffaaaa Couldn't detect SuperWoW.")
this:Hide()
end)
Cursive.superwow = false
end
-- onload
function Cursive:OnInitialize()
DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00Cursive:|cffffaaaa Loaded. /cursive for commands and minimap icon for options.")
end
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+238
View File
@@ -0,0 +1,238 @@
--[[
Name: AceDebug-2.0
Revision: $Rev: 15024 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Ace 1.x by Turan (turan@gryphon.com)
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceDebug-2.0
SVN: http://svn.wowace.com/root/trunk/Ace2/AceDebug-2.0
Description: Mixin to allow for simple debugging capabilities.
Dependencies: AceLibrary, AceOO-2.0
]]
local MAJOR_VERSION = "AceDebug-2.0"
local MINOR_VERSION = "$Revision: 15024 $"
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
local DEBUGGING, TOGGLE_DEBUGGING
if GetLocale() == "frFR" then
DEBUGGING = "D\195\169boguage"
TOGGLE_DEBUGGING = "Activer/d\195\169sactiver le d\195\169boguage"
elseif GetLocale() == "deDE" then
DEBUGGING = "Debuggen"
TOGGLE_DEBUGGING = "Aktiviert/Deaktiviert Debugging"
elseif GetLocale() == "koKR" then
DEBUGGING = "디버깅"
TOGGLE_DEBUGGING = "디버깅 기능 사용함/사용안함"
elseif GetLocale() == "zhTW" then
DEBUGGING = "除錯"
TOGGLE_DEBUGGING = "啟用/停用除錯功能"
elseif GetLocale() == "zhCN" then
DEBUGGING = "\232\176\131\232\175\149"
TOGGLE_DEBUGGING = "\229\144\175\231\148\168/\231\166\129\231\148\168 \232\176\131\232\175\149"
else -- enUS
DEBUGGING = "Debugging"
TOGGLE_DEBUGGING = "Enable/disable debugging"
end
local table_setn
do
local version = GetBuildInfo()
if string.find(version, "^2%.") then
-- 2.0.0
table_setn = function() end
else
table_setn = table.setn
end
end
local math_mod = math.mod or math.fmod
local AceOO = AceLibrary:GetInstance("AceOO-2.0")
local AceDebug = AceOO.Mixin {"Debug", "CustomDebug", "IsDebugging", "SetDebugging", "SetDebugLevel", "LevelDebug", "CustomLevelDebug", "GetDebugLevel"}
local function print(text, r, g, b, frame, delay)
(frame or DEFAULT_CHAT_FRAME):AddMessage(text, r, g, b, 1, delay or 5)
end
local tmp
function AceDebug:CustomDebug(r, g, b, frame, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not self.debugging then return end
local output = string.format("|cff7fff7f(DEBUG) %s:[%s%3d]|r", tostring(self), date("%H:%M:%S"), math_mod(GetTime(), 1) * 1000)
if string.find(tostring(a1), "%%") then
output = output .. " " .. string.format(tostring(a1), tostring(a2), tostring(a3), tostring(a4), tostring(a5), tostring(a6), tostring(a7), tostring(a8), tostring(a9), tostring(a10), tostring(a11), tostring(a12), tostring(a13), tostring(a14), tostring(a15), tostring(a16), tostring(a17), tostring(a18), tostring(a19), tostring(a20))
else
if not tmp then
tmp = {}
end
-- This block dynamically rebuilds the tmp array stopping on the first nil.
table.insert(tmp, output)
table.insert(tmp, tostring(a1))
table.insert(tmp, a2)
table.insert(tmp, a3)
table.insert(tmp, a4)
table.insert(tmp, a5)
table.insert(tmp, a6)
table.insert(tmp, a7)
table.insert(tmp, a8)
table.insert(tmp, a9)
table.insert(tmp, a10)
table.insert(tmp, a11)
table.insert(tmp, a12)
table.insert(tmp, a13)
table.insert(tmp, a14)
table.insert(tmp, a15)
table.insert(tmp, a16)
table.insert(tmp, a17)
table.insert(tmp, a18)
table.insert(tmp, a19)
table.insert(tmp, a20)
while tmp[table.getn(tmp)] == nil do
table.remove(tmp)
end
for k = 1, table.getn(tmp) do
tmp[k] = tostring(tmp[k])
end
output = table.concat(tmp, " ")
for k,v in pairs(tmp) do
tmp[k] = nil
end
table_setn(tmp, 0)
end
print(output, r, g, b, frame or self.debugFrame, delay)
end
function AceDebug:Debug(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
AceDebug.CustomDebug(self, nil, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
function AceDebug:IsDebugging()
return self.debugging
end
function AceDebug:SetDebugging(debugging)
self.debugging = debugging
end
-- Takes a number 1-3
-- Level 1: Critical messages that every user should receive
-- Level 2: Should be used for local debugging (function calls, etc)
-- Level 3: Very verbose debugging, will dump everything and anything
-- If set to nil, you will receive no debug information
function AceDebug:SetDebugLevel(level)
AceDebug:argCheck(level, 1, "number", "nil")
if not level then
self.debuglevel = nil
return
end
if level < 1 or level > 3 then
AceDebug:error("Bad argument #1 to `SetDebugLevel`, must be a number 1-3")
end
self.debuglevel = level
end
function AceDebug:GetDebugLevel()
return self.debuglevel
end
function AceDebug:CustomLevelDebug(level, r, g, b, frame, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not self.debugging or not self.debuglevel then return end
AceDebug:argCheck(level, 1, "number")
if level < 1 or level > 3 then
AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3")
end
if level > self.debuglevel then return end
local output = string.format("|cff7fff7f(DEBUG) %s:[%s.%3d]|r", tostring(self), date("%H:%M:%S"), math_mod(GetTime(), 1) * 1000)
if string.find(tostring(a1), "%%") then
output = output .. " " .. string.format(tostring(a1), tostring(a2), tostring(a3), tostring(a4), tostring(a5), tostring(a6), tostring(a7), tostring(a8), tostring(a9), tostring(a10), tostring(a11), tostring(a12), tostring(a13), tostring(a14), tostring(a15), tostring(a16), tostring(a17), tostring(a18), tostring(a19), tostring(a20))
else
if not tmp then
tmp = {}
end
-- This block dynamically rebuilds the tmp array stopping on the first nil.
table.insert(tmp, output)
table.insert(tmp, tostring(a1))
table.insert(tmp, a2)
table.insert(tmp, a3)
table.insert(tmp, a4)
table.insert(tmp, a5)
table.insert(tmp, a6)
table.insert(tmp, a7)
table.insert(tmp, a8)
table.insert(tmp, a9)
table.insert(tmp, a10)
table.insert(tmp, a11)
table.insert(tmp, a12)
table.insert(tmp, a13)
table.insert(tmp, a14)
table.insert(tmp, a15)
table.insert(tmp, a16)
table.insert(tmp, a17)
table.insert(tmp, a18)
table.insert(tmp, a19)
table.insert(tmp, a20)
while tmp[table.getn(tmp)] == nil do
table.remove(tmp)
end
for k = 1, table.getn(tmp) do
tmp[k] = tostring(tmp[k])
end
output = table.concat(tmp, " ")
for k,v in pairs(tmp) do
tmp[k] = nil
end
table_setn(tmp, 0)
end
print(output, r, g, b, frame or self.debugFrame, delay)
end
function AceDebug:LevelDebug(level, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not self.debugging or not self.debuglevel then return end
AceDebug:argCheck(level, 1, "number")
if level < 1 or level > 3 then
AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3")
end
if level > self.debuglevel then return end
AceDebug.CustomLevelDebug(self, level, nil, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
local options
function AceDebug:GetAceOptionsDataTable(target)
if not options then
options = {
debug = {
name = DEBUGGING,
desc = TOGGLE_DEBUGGING,
type = "toggle",
get = "IsDebugging",
set = "SetDebugging",
order = -2,
}
}
end
return options
end
AceLibrary:Register(AceDebug, MAJOR_VERSION, MINOR_VERSION, AceDebug.activate)
AceDebug = AceLibrary(MAJOR_VERSION)
+973
View File
@@ -0,0 +1,973 @@
--[[
Name: AceEvent-2.0
Revision: $Rev: 17803 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Ace 1.x by Turan (turan@gryphon.com)
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceEvent-2.0
SVN: http://svn.wowace.com/root/trunk/Ace2/AceEvent-2.0
Description: Mixin to allow for event handling, scheduling, and inter-addon
communication.
Dependencies: AceLibrary, AceOO-2.0
]]
local MAJOR_VERSION = "AceEvent-2.0"
local MINOR_VERSION = "$Revision: 17803 $"
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
if loadstring("return function(...) return ... end") and AceLibrary:HasInstance(MAJOR_VERSION) then return end -- lua51 check
if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
local AceOO = AceLibrary:GetInstance("AceOO-2.0")
local Mixin = AceOO.Mixin
local AceEvent = Mixin {
"RegisterEvent",
"RegisterAllEvents",
"UnregisterEvent",
"UnregisterAllEvents",
"TriggerEvent",
"ScheduleEvent",
"ScheduleRepeatingEvent",
"CancelScheduledEvent",
"CancelAllScheduledEvents",
"IsEventRegistered",
"IsEventScheduled",
"RegisterBucketEvent",
"UnregisterBucketEvent",
"UnregisterAllBucketEvents",
"IsBucketEventRegistered",
}
local table_setn
do
local version = GetBuildInfo()
if string.find(version, "^2%.") then
-- 2.0.0
table_setn = function() end
else
table_setn = table.setn
end
end
local weakKey = {__mode="k"}
local new, del
do
local list = setmetatable({}, weakKey)
function new()
local t = next(list)
if t then
list[t] = nil
return t
else
return {}
end
end
function del(t)
setmetatable(t, nil)
for k in pairs(t) do
t[k] = nil
end
list[t] = true
end
end
local FAKE_NIL
local RATE
local eventsWhichHappenOnce = {
PLAYER_LOGIN = true,
AceEvent_FullyInitialized = true,
VARIABLES_LOADED = true,
PLAYER_LOGOUT = true,
}
local registeringFromAceEvent
function AceEvent:RegisterEvent(event, method, once)
AceEvent:argCheck(event, 2, "string")
if self == AceEvent and not registeringFromAceEvent then
AceEvent:argCheck(method, 3, "function")
self = method
else
AceEvent:argCheck(method, 3, "string", "function", "nil", "boolean", "number")
if type(method) == "boolean" or type(method) == "number" then
AceEvent:argCheck(once, 4, "nil")
once, method = method, event
end
end
AceEvent:argCheck(once, 4, "number", "boolean", "nil")
if eventsWhichHappenOnce[event] then
once = true
end
local throttleRate
if type(once) == "number" then
throttleRate, once = once
end
if not method then
method = event
end
if type(method) == "string" and type(self[method]) ~= "function" then
AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
else
assert(type(method) == "function" or type(method) == "string")
end
local AceEvent_registry = AceEvent.registry
if not AceEvent_registry[event] then
AceEvent_registry[event] = new()
AceEvent.frame:RegisterEvent(event)
end
local remember = true
if AceEvent_registry[event][self] then
remember = false
end
AceEvent_registry[event][self] = method
local AceEvent_onceRegistry = AceEvent.onceRegistry
if once then
if not AceEvent_onceRegistry then
AceEvent.onceRegistry = new()
AceEvent_onceRegistry = AceEvent.onceRegistry
end
if not AceEvent_onceRegistry[event] then
AceEvent_onceRegistry[event] = new()
end
AceEvent_onceRegistry[event][self] = true
else
if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
AceEvent_onceRegistry[event][self] = nil
if not next(AceEvent_onceRegistry[event]) then
AceEvent_onceRegistry[event] = del(AceEvent_onceRegistry[event])
end
end
end
local AceEvent_throttleRegistry = AceEvent.throttleRegistry
if throttleRate then
if not AceEvent_throttleRegistry then
AceEvent.throttleRegistry = new()
AceEvent_throttleRegistry = AceEvent.throttleRegistry
end
if not AceEvent_throttleRegistry[event] then
AceEvent_throttleRegistry[event] = new()
end
if AceEvent_throttleRegistry[event][self] then
AceEvent_throttleRegistry[event][self] = del(AceEvent_throttleRegistry[event][self])
end
AceEvent_throttleRegistry[event][self] = setmetatable(new(), weakKey)
local t = AceEvent_throttleRegistry[event][self]
t[RATE] = throttleRate
else
if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] then
if AceEvent_throttleRegistry[event][self] then
AceEvent_throttleRegistry[event][self] = del(AceEvent_throttleRegistry[event][self])
end
if not next(AceEvent_throttleRegistry[event]) then
AceEvent_throttleRegistry[event] = del(AceEvent_throttleRegistry[event])
end
end
end
if remember then
AceEvent:TriggerEvent("AceEvent_EventRegistered", self, event)
end
end
local ALL_EVENTS
function AceEvent:RegisterAllEvents(method)
if self == AceEvent then
AceEvent:argCheck(method, 1, "function")
self = method
else
AceEvent:argCheck(method, 1, "string", "function")
if type(method) == "string" and type(self[method]) ~= "function" then
AceEvent:error("Cannot register all events to method %q, it does not exist", method)
end
end
local AceEvent_registry = AceEvent.registry
if not AceEvent_registry[ALL_EVENTS] then
AceEvent_registry[ALL_EVENTS] = new()
AceEvent.frame:RegisterAllEvents()
end
AceEvent_registry[ALL_EVENTS][self] = method
end
local _G = getfenv(0)
local memstack, timestack = {}, {}
local memdiff, timediff
function AceEvent:TriggerEvent(event, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
AceEvent:argCheck(event, 2, "string")
local AceEvent_registry = AceEvent.registry
if (not AceEvent_registry[event] or not next(AceEvent_registry[event])) and (not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS])) then
return
end
local _G_event = _G.event
_G.event = event
local lastEvent = AceEvent.currentEvent
AceEvent.currentEvent = event
local AceEvent_onceRegistry = AceEvent.onceRegistry
local AceEvent_debugTable = AceEvent.debugTable
if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
local tmp = new()
for obj, method in pairs(AceEvent_onceRegistry[event]) do
tmp[obj] = AceEvent_registry[event] and AceEvent_registry[event][obj] or nil
end
local obj = next(tmp)
while obj do
local mem, time
if AceEvent_debugTable then
if not AceEvent_debugTable[event] then
AceEvent_debugTable[event] = new()
end
if not AceEvent_debugTable[event][obj] then
AceEvent_debugTable[event][obj] = new()
AceEvent_debugTable[event][obj].mem = 0
AceEvent_debugTable[event][obj].time = 0
AceEvent_debugTable[event][obj].count = 0
end
if memdiff then
table.insert(memstack, memdiff)
table.insert(timestack, timediff)
end
memdiff, timediff = 0, 0
mem, time = gcinfo(), GetTime()
end
local method = tmp[obj]
AceEvent.UnregisterEvent(obj, event)
if type(method) == "string" then
local obj_method = obj[method]
if obj_method then
obj_method(obj, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
elseif method then -- function
method(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
if AceEvent_debugTable then
local dmem, dtime = memdiff, timediff
mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
memdiff, timediff = table.remove(memstack), table.remove(timestack)
if memdiff then
memdiff = memdiff + mem + dmem
timediff = timediff + time + dtime
end
end
tmp[obj] = nil
obj = next(tmp)
end
del(tmp)
end
local AceEvent_throttleRegistry = AceEvent.throttleRegistry
local throttleTable = AceEvent_throttleRegistry and AceEvent_throttleRegistry[event]
if AceEvent_registry[event] then
local tmp = new()
for obj, method in pairs(AceEvent_registry[event]) do
tmp[obj] = method
end
local obj = next(tmp)
while obj do
local method = tmp[obj]
local continue = false
if throttleTable and throttleTable[obj] then
local a1 = a1
if a1 == nil then
a1 = FAKE_NIL
end
if not throttleTable[obj][a1] or GetTime() - throttleTable[obj][a1] >= throttleTable[obj][RATE] then
throttleTable[obj][a1] = GetTime()
else
continue = true
end
end
if not continue then
local mem, time
if AceEvent_debugTable then
if not AceEvent_debugTable[event] then
AceEvent_debugTable[event] = new()
end
if not AceEvent_debugTable[event][obj] then
AceEvent_debugTable[event][obj] = new()
AceEvent_debugTable[event][obj].mem = 0
AceEvent_debugTable[event][obj].time = 0
AceEvent_debugTable[event][obj].count = 0
end
if memdiff then
table.insert(memstack, memdiff)
table.insert(timestack, timediff)
end
memdiff, timediff = 0, 0
mem, time = gcinfo(), GetTime()
end
if type(method) == "string" then
local obj_method = obj[method]
if obj_method then
obj_method(obj, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
elseif method then -- function
method(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
if AceEvent_debugTable then
local dmem, dtime = memdiff, timediff
mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
memdiff, timediff = table.remove(memstack), table.remove(timestack)
if memdiff then
memdiff = memdiff + mem + dmem
timediff = timediff + time + dtime
end
end
end
tmp[obj] = nil
obj = next(tmp)
end
del(tmp)
end
if AceEvent_registry[ALL_EVENTS] then
local tmp = new()
for obj, method in pairs(AceEvent_registry[ALL_EVENTS]) do
tmp[obj] = method
end
local obj = next(tmp)
while obj do
local method = tmp[obj]
local mem, time
if AceEvent_debugTable then
if not AceEvent_debugTable[event] then
AceEvent_debugTable[event] = new()
end
if not AceEvent_debugTable[event][obj] then
AceEvent_debugTable[event][obj] = new()
AceEvent_debugTable[event][obj].mem = 0
AceEvent_debugTable[event][obj].time = 0
AceEvent_debugTable[event][obj].count = 0
end
if memdiff then
table.insert(memstack, memdiff)
table.insert(timestack, timediff)
end
memdiff, timediff = 0, 0
mem, time = gcinfo(), GetTime()
end
if type(method) == "string" then
local obj_method = obj[method]
if obj_method then
obj_method(obj, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
elseif method then -- function
method(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
if AceEvent_debugTable then
local dmem, dtime = memdiff, timediff
mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
memdiff, timediff = table.remove(memstack), table.remove(timestack)
if memdiff then
memdiff = memdiff + mem + dmem
timediff = timediff + time + dtime
end
end
tmp[obj] = nil
obj = next(tmp)
end
del(tmp)
end
_G.event = _G_event
AceEvent.currentEvent = lastEvent
end
-- local accessors
local getn = table.getn
local tinsert = table.insert
local tremove = table.remove
local floor = math.floor
local GetTime = GetTime
local next = next
local pairs = pairs
local unpack = unpack
local delayRegistry
local tmp = {}
local function OnUpdate()
local t = GetTime()
for k,v in pairs(delayRegistry) do
tmp[k] = true
end
for k in pairs(tmp) do
local v = delayRegistry[k]
if v then
local v_time = v.time
if not v_time then
delayRegistry[k] = del(v)
elseif v_time <= t then
local v_repeatDelay = v.repeatDelay
if v_repeatDelay then
-- use the event time, not the current time, else timing inaccuracies add up over time
v.time = v_time + v_repeatDelay
end
local event = v.event
local mem, time
if AceEvent_debugTable then
mem, time = gcinfo(), GetTime()
end
if type(event) == "function" then
event(unpack(v))
else
AceEvent:TriggerEvent(event, unpack(v))
end
if AceEvent_debugTable then
mem, time = gcinfo() - mem, GetTime() - time
v.mem = v.mem + mem
v.timeSpent = v.timeSpent + time
v.count = v.count + 1
end
if not v_repeatDelay then
local x = delayRegistry[k]
if x and x.time == v_time then -- check if it was manually reset
delayRegistry[k] = del(v)
end
end
end
end
end
for k in pairs(tmp) do
tmp[k] = nil
end
if not next(delayRegistry) then
AceEvent.frame:Hide()
end
end
local function ScheduleEvent(self, repeating, event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
local id
if type(event) == "string" or type(event) == "table" then
if type(event) == "table" then
if not delayRegistry or not delayRegistry[event] then
AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
end
end
if type(delay) ~= "number" then
id, event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 = event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20
AceEvent:argCheck(event, 3, "string", "function", --[[ so message is right ]] "number")
AceEvent:argCheck(delay, 4, "number")
self:CancelScheduledEvent(id)
end
else
AceEvent:argCheck(event, 2, "string", "function")
AceEvent:argCheck(delay, 3, "number")
end
if not delayRegistry then
AceEvent.delayRegistry = new()
delayRegistry = AceEvent.delayRegistry
AceEvent.frame:SetScript("OnUpdate", OnUpdate)
end
local t
if type(id) == "table" then
for k in pairs(id) do
id[k] = nil
end
t = id
else
t = new()
end
t[1] = a1
t[2] = a2
t[3] = a3
t[4] = a4
t[5] = a5
t[6] = a6
t[7] = a7
t[8] = a8
t[9] = a9
t[10] = a10
t[11] = a11
t[12] = a12
t[13] = a13
t[14] = a14
t[15] = a15
t[16] = a16
t[17] = a17
t[18] = a18
t[19] = a19
t[20] = a20
table_setn(t, 20)
t.event = event
t.time = GetTime() + delay
t.self = self
t.id = id or t
t.repeatDelay = repeating and delay
if AceEvent_debugTable then
t.mem = 0
t.count = 0
t.timeSpent = 0
end
delayRegistry[t.id] = t
AceEvent.frame:Show()
return t.id
end
function AceEvent:ScheduleEvent(event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if type(event) == "string" or type(event) == "table" then
if type(event) == "table" then
if not delayRegistry or not delayRegistry[event] then
AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
end
end
if type(delay) ~= "number" then
AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
AceEvent:argCheck(a1, 4, "number")
end
else
AceEvent:argCheck(event, 2, "string", "function")
AceEvent:argCheck(delay, 3, "number")
end
return ScheduleEvent(self, false, event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
function AceEvent:ScheduleRepeatingEvent(event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if type(event) == "string" or type(event) == "table" then
if type(event) == "table" then
if not delayRegistry or not delayRegistry[event] then
AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
end
end
if type(delay) ~= "number" then
AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
AceEvent:argCheck(a1, 4, "number")
end
else
AceEvent:argCheck(event, 2, "string", "function")
AceEvent:argCheck(delay, 3, "number")
end
return ScheduleEvent(self, true, event, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
end
function AceEvent:CancelScheduledEvent(t)
AceEvent:argCheck(t, 2, "string", "table")
if delayRegistry then
local v = delayRegistry[t]
if v then
delayRegistry[t] = del(v)
if not next(delayRegistry) then
AceEvent.frame:Hide()
end
return true
end
end
return false
end
function AceEvent:IsEventScheduled(t)
AceEvent:argCheck(t, 2, "string", "table")
if delayRegistry then
local v = delayRegistry[t]
if v then
return true, v.time - GetTime()
end
end
return false, nil
end
function AceEvent:UnregisterEvent(event)
AceEvent:argCheck(event, 2, "string")
local AceEvent_registry = AceEvent.registry
if AceEvent_registry[event] and AceEvent_registry[event][self] then
AceEvent_registry[event][self] = nil
local AceEvent_onceRegistry = AceEvent.onceRegistry
if AceEvent_onceRegistry and AceEvent_onceRegistry[event] and AceEvent_onceRegistry[event][self] then
AceEvent_onceRegistry[event][self] = nil
if not next(AceEvent_onceRegistry[event]) then
AceEvent_onceRegistry[event] = del(AceEvent_onceRegistry[event])
end
end
local AceEvent_throttleRegistry = AceEvent.throttleRegistry
if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] and AceEvent_throttleRegistry[event][self] then
AceEvent_throttleRegistry[event][self] = del(AceEvent_throttleRegistry[event][self])
if not next(AceEvent_throttleRegistry[event]) then
AceEvent_throttleRegistry[event] = del(AceEvent_throttleRegistry[event])
end
end
if not next(AceEvent_registry[event]) then
AceEvent_registry[event] = del(AceEvent_registry[event])
if not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS]) then
AceEvent.frame:UnregisterEvent(event)
end
end
else
if self == AceEvent then
error(string.format("Cannot unregister event %q. Improperly unregistering from AceEvent-2.0.", event), 2)
else
AceEvent:error("Cannot unregister event %q. %q is not registered with it.", event, self)
end
end
AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
end
function AceEvent:UnregisterAllEvents()
local AceEvent_registry = AceEvent.registry
if AceEvent_registry[ALL_EVENTS] and AceEvent_registry[ALL_EVENTS][self] then
AceEvent_registry[ALL_EVENTS][self] = nil
if not next(AceEvent_registry[ALL_EVENTS]) then
del(AceEvent_registry[ALL_EVENTS])
AceEvent.frame:UnregisterAllEvents()
for k,v in pairs(AceEvent_registry) do
if k ~= ALL_EVENTS then
AceEvent.frame:RegisterEvent(k)
end
end
AceEvent_registry[event] = nil
end
end
local first = true
for event, data in pairs(AceEvent_registry) do
if first then
if AceEvent_registry.AceEvent_EventUnregistered then
event = "AceEvent_EventUnregistered"
else
first = false
end
end
local x = data[self]
data[self] = nil
if x and event ~= ALL_EVENTS then
if not next(data) then
del(data)
if not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS]) then
AceEvent.frame:UnregisterEvent(event)
end
AceEvent_registry[event] = nil
end
AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
end
if first then
event = nil
end
end
if AceEvent.onceRegistry then
for event, data in pairs(AceEvent.onceRegistry) do
data[self] = nil
end
end
end
function AceEvent:CancelAllScheduledEvents()
if delayRegistry then
for k,v in pairs(delayRegistry) do
if v.self == self then
delayRegistry[k] = del(v)
end
end
if not next(delayRegistry) then
AceEvent.frame:Hide()
end
end
end
function AceEvent:IsEventRegistered(event)
AceEvent:argCheck(event, 2, "string")
local AceEvent_registry = AceEvent.registry
if self == AceEvent then
return AceEvent_registry[event] and next(AceEvent_registry[event]) and true or false
end
if AceEvent_registry[event] and AceEvent_registry[event][self] then
return true, AceEvent_registry[event][self]
end
return false, nil
end
local bucketfunc
function AceEvent:RegisterBucketEvent(event, delay, method)
AceEvent:argCheck(event, 2, "string", "table")
if type(event) == "table" then
for k,v in pairs(event) do
if type(k) ~= "number" then
AceEvent:error("All keys to argument #2 to `RegisterBucketEvent' must be numbers.")
elseif type(v) ~= "string" then
AceEvent:error("All values to argument #2 to `RegisterBucketEvent' must be strings.")
end
end
end
AceEvent:argCheck(delay, 3, "number")
if AceEvent == self then
AceEvent:argCheck(method, 4, "function")
self = method
else
if type(event) == "string" then
AceEvent:argCheck(method, 4, "string", "function", "nil")
if not method then
method = event
end
else
AceEvent:argCheck(method, 4, "string", "function")
end
if type(method) == "string" and type(self[method]) ~= "function" then
AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
end
end
if not AceEvent.buckets then
AceEvent.buckets = new()
end
if not AceEvent.buckets[event] then
AceEvent.buckets[event] = new()
end
if not AceEvent.buckets[event][self] then
AceEvent.buckets[event][self] = new()
AceEvent.buckets[event][self].current = new()
AceEvent.buckets[event][self].self = self
else
AceEvent.CancelScheduledEvent(self, AceEvent.buckets[event][self].id)
end
local bucket = AceEvent.buckets[event][self]
bucket.method = method
local func = function(arg1)
bucket.run = true
if arg1 then
bucket.current[arg1] = true
end
end
AceEvent.buckets[event][self].func = func
if type(event) == "string" then
AceEvent.RegisterEvent(self, event, func)
else
for _,v in ipairs(event) do
AceEvent.RegisterEvent(self, v, func)
end
end
if not bucketfunc then
bucketfunc = function(bucket)
local current = bucket.current
local method = bucket.method
local self = bucket.self
if bucket.run then
if type(method) == "string" then
self[method](self, current)
elseif method then -- function
method(current)
end
for k in pairs(current) do
current[k] = nil
k = nil
end
bucket.run = false
end
end
end
bucket.id = AceEvent.ScheduleRepeatingEvent(self, bucketfunc, delay, bucket)
end
function AceEvent:IsBucketEventRegistered(event)
AceEvent:argCheck(event, 2, "string", "table")
return AceEvent.buckets and AceEvent.buckets[event] and AceEvent.buckets[event][self]
end
function AceEvent:UnregisterBucketEvent(event)
AceEvent:argCheck(event, 2, "string", "table")
if not AceEvent.buckets or not AceEvent.buckets[event] or not AceEvent.buckets[event][self] then
AceEvent:error("Cannot unregister bucket event %q. %q is not registered with it.", event, self)
end
local bucket = AceEvent.buckets[event][self]
if type(event) == "string" then
AceEvent.UnregisterEvent(self, event)
else
for _,v in ipairs(event) do
AceEvent.UnregisterEvent(self, v)
end
end
AceEvent:CancelScheduledEvent(bucket.id)
del(bucket.current)
AceEvent.buckets[event][self] = del(AceEvent.buckets[event][self])
if not next(AceEvent.buckets[event]) then
AceEvent.buckets[event] = del(AceEvent.buckets[event])
end
end
function AceEvent:UnregisterAllBucketEvents()
if not AceEvent.buckets or not next(AceEvent.buckets) then
return
end
for k,v in pairs(AceEvent.buckets) do
if v == self then
AceEvent.UnregisterBucketEvent(self, k)
k = nil
end
end
end
function AceEvent:OnEmbedDisable(target)
self.UnregisterAllEvents(target)
self.CancelAllScheduledEvents(target)
self.UnregisterAllBucketEvents(target)
end
function AceEvent:EnableDebugging()
if not self.debugTable then
self.debugTable = new()
if delayRegistry then
for k,v in pairs(self.delayRegistry) do
if not v.mem then
v.mem = 0
v.count = 0
v.timeSpent = 0
end
end
end
end
end
function AceEvent:IsFullyInitialized()
return self.postInit or false
end
function AceEvent:IsPostPlayerLogin()
return self.playerLogin or false
end
function AceEvent:activate(oldLib, oldDeactivate)
AceEvent = self
if oldLib then
self.onceRegistry = oldLib.onceRegistry
self.throttleRegistry = oldLib.throttleRegistry
self.delayRegistry = oldLib.delayRegistry
self.buckets = oldLib.buckets
self.registry = oldLib.registry
self.frame = oldLib.frame
self.debugTable = oldLib.debugTable
self.playerLogin = oldLib.pew or DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.defaultLanguage and true
self.postInit = oldLib.postInit or self.playerLogin and ChatTypeInfo and ChatTypeInfo.WHISPER and ChatTypeInfo.WHISPER.r and true
self.ALL_EVENTS = oldLib.ALL_EVENTS
self.FAKE_NIL = oldLib.FAKE_NIL
self.RATE = oldLib.RATE
end
if not self.registry then
self.registry = {}
end
if not self.frame then
self.frame = CreateFrame("Frame", "AceEvent20Frame")
end
if not self.ALL_EVENTS then
self.ALL_EVENTS = {}
end
if not self.FAKE_NIL then
self.FAKE_NIL = {}
end
if not self.RATE then
self.RATE = {}
end
ALL_EVENTS = self.ALL_EVENTS
FAKE_NIL = self.FAKE_NIL
RATE = self.RATE
local inPlw = false
local blacklist = {
UNIT_INVENTORY_CHANGED = true,
BAG_UPDATE = true,
ITEM_LOCK_CHANGED = true,
ACTIONBAR_SLOT_CHANGED = true,
}
self.frame:SetScript("OnEvent", function()
local event = event
if event == "PLAYER_ENTERING_WORLD" then
inPlw = false
elseif event == "PLAYER_LEAVING_WORLD" then
inPlw = true
end
if event and (not inPlw or not blacklist[event]) then
self:TriggerEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end
end)
if self.delayRegistry then
delayRegistry = self.delayRegistry
self.frame:SetScript("OnUpdate", OnUpdate)
end
self:UnregisterAllEvents()
self:CancelAllScheduledEvents()
registeringFromAceEvent = true
self:RegisterEvent("LOOT_OPENED", function()
SendAddonMessage("LOOT_OPENED", "", "RAID")
end)
registeringFromAceEvent = nil
if not self.playerLogin then
registeringFromAceEvent = true
self:RegisterEvent("PLAYER_LOGIN", function()
self.playerLogin = true
end, true)
registeringFromAceEvent = nil
end
if not self.postInit then
local isReload = true
local function func()
self.postInit = true
self:TriggerEvent("AceEvent_FullyInitialized")
if self.registry["CHAT_MSG_CHANNEL_NOTICE"] and self.registry["CHAT_MSG_CHANNEL_NOTICE"][self] then
self:UnregisterEvent("CHAT_MSG_CHANNEL_NOTICE")
end
if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
self:UnregisterEvent("MEETINGSTONE_CHANGED")
end
if self.registry["MINIMAP_ZONE_CHANGED"] and self.registry["MINIMAP_ZONE_CHANGED"][self] then
self:UnregisterEvent("MINIMAP_ZONE_CHANGED")
end
if self.registry["LANGUAGE_LIST_CHANGED"] and self.registry["LANGUAGE_LIST_CHANGED"][self] then
self:UnregisterEvent("LANGUAGE_LIST_CHANGED")
end
end
registeringFromAceEvent = true
local f = function()
self.playerLogin = true
self:ScheduleEvent("AceEvent_FullyInitialized", func, 1)
end
self:RegisterEvent("MEETINGSTONE_CHANGED", f, true)
self:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE", function()
self:ScheduleEvent("AceEvent_FullyInitialized", func, 0.05)
end)
self:RegisterEvent("LANGUAGE_LIST_CHANGED", function()
if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
registeringFromAceEvent = true
self:UnregisterEvent("MEETINGSTONE_CHANGED")
self:RegisterEvent("MINIMAP_ZONE_CHANGED", f, true)
registeringFromAceEvent = nil
end
end)
self:ScheduleEvent("AceEvent_FullyInitialized", func, 10)
registeringFromAceEvent = nil
end
self.super.activate(self, oldLib, oldDeactivate)
if oldLib then
oldDeactivate(oldLib)
end
end
AceLibrary:Register(AceEvent, MAJOR_VERSION, MINOR_VERSION, AceEvent.activate)
AceEvent = AceLibrary(MAJOR_VERSION)
+569
View File
@@ -0,0 +1,569 @@
--[[
Name: AceHook-2.1
Revision: $Rev: 17638 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Ace 1.x by Turan (turan@gryphon.com)
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceHook-2.1
SVN: http://svn.wowace.com/root/trunk/Ace2/AceHook-2.1
Description: Mixin to allow for safe hooking of functions, methods, and scripts.
Dependencies: AceLibrary, AceOO-2.0
]]
local MAJOR_VERSION = "AceHook-2.1"
local MINOR_VERSION = "$Revision: 17638 $"
-- This ensures the code is only executed if the libary doesn't already exist, or is a newer version
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
if loadstring("return function(...) return ... end") and AceLibrary:HasInstance(MAJOR_VERSION) then return end -- lua51 check
if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
--[[---------------------------------------------------------------------------------
Create the library object
----------------------------------------------------------------------------------]]
local AceOO = AceLibrary:GetInstance("AceOO-2.0")
local AceHook = AceOO.Mixin {
"Hook",
"HookScript",
"SecureHook",
"Unhook",
"UnhookAll",
"HookReport",
"IsHooked",
}
--[[---------------------------------------------------------------------------------
Library Definitions
----------------------------------------------------------------------------------]]
local protFuncs = {
CameraOrSelectOrMoveStart = true, CameraOrSelectOrMoveStop = true,
TurnOrActionStart = true, TurnOrActionStop = true,
PitchUpStart = true, PitchUpStop = true,
PitchDownStart = true, PitchDownStop = true,
MoveBackwardStart = true, MoveBackwardStop = true,
MoveForwardStart = true, MoveForwardStop = true,
Jump = true, StrafeLeftStart = true,
StrafeLeftStop = true, StrafeRightStart = true,
StrafeRightStop = true, ToggleMouseMove = true,
ToggleRun = true, TurnLeftStart = true,
TurnLeftStop = true, TurnRightStart = true,
TurnRightStop = true,
}
local function issecurevariable(x)
if protFuncs[x] then
return 1
else
return nil
end
end
local _G = getfenv(0)
local function hooksecurefunc(arg1, arg2, arg3)
if type(arg1) == "string" then
arg1, arg2, arg3 = _G, arg1, arg2
end
local orig = arg1[arg2]
arg1[arg2] = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
local x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20 = orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
arg3(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
return x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20
end
end
local protectedScripts = {
OnClick = true,
}
local handlers, scripts, actives, registry
--[[---------------------------------------------------------------------------------
Private definitions (Not exposed)
----------------------------------------------------------------------------------]]
local new, del
do
local list = setmetatable({}, {__mode = "k"})
function new()
local t = next(list)
if not t then
return {}
end
list[t] = nil
return t
end
function del(t)
setmetatable(t, nil)
for k in pairs(t) do
t[k] = nil
end
list[t] = true
end
end
local function createFunctionHook(self, func, handler, orig, secure)
if not secure then
if type(handler) == "string" then
-- The handler is a method, need to self it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return self[handler](self, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
else
return orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
else
-- The handler is a function, just call it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return handler(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
else
return orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
end
else
-- secure hooks don't call the original method
if type(handler) == "string" then
-- The handler is a method, need to self it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return self[handler](self, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
else
-- The handler is a function, just call it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return handler(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
end
end
end
local function createMethodHook(self, object, method, handler, orig, secure, script)
if script then
if type(handler) == "string" then
local uid
uid = function()
if actives[uid] then
return self[handler](self, object)
else
return orig()
end
end
return uid
else
-- The handler is a function, just call it
local uid
uid = function()
if actives[uid] then
return handler(object)
else
return orig()
end
end
return uid
end
elseif not secure then
if type(handler) == "string" then
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return self[handler](self, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
else
return orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
else
-- The handler is a function, just call it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return handler(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
else
return orig(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
end
else
-- secure hooks don't call the original method
if type(handler) == "string" then
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return self[handler](self, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
else
-- The handler is a function, just call it
local uid
uid = function(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
if actives[uid] then
return handler(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20)
end
end
return uid
end
end
end
local function hookFunction(self, func, handler, secure)
local orig = _G[func]
if not orig or type(orig) ~= "function" then
AceHook:error("Attempt to hook a non-existant function %q", func)
end
if not handler then
handler = func
end
if registry[self][func] then
local uid = registry[self][func]
if actives[uid] then
-- We have an active hook from this source. Don't multi-hook
AceHook:error("%q already has an active hook from this source.", func)
end
if handlers[uid] == handler then
-- The hook is inactive, so reactivate it
actives[uid] = true
return
else
AceHook:error("There is a stale hook for %q can't hook or reactivate.", func)
end
end
if type(handler) == "string" then
if type(self[handler]) ~= "function" then
AceHook:error("Could not find the the handler %q when hooking function %q", handler, func)
end
elseif type(handler) ~= "function" then
AceHook:error("Could not find the handler you supplied when hooking %q", func)
end
local uid = createFunctionHook(self, func, handler, orig, secure)
registry[self][func] = uid
actives[uid] = true
handlers[uid] = handler
if not secure then
_G[func] = uid
self.hooks[func] = orig
else
hooksecurefunc(func, uid)
end
end
local function unhookFunction(self, func)
if not registry[self][func] then
AceHook:error("Tried to unhook %q which is not currently hooked.", func)
end
local uid = registry[self][func]
if actives[uid] then
-- See if we own the global function
if self.hooks[func] and _G[func] == uid then
_G[func] = self.hooks[func]
self.hooks[func] = nil
registry[self][func] = nil
handlers[uid] = nil
scripts[uid] = nil
actives[uid] = nil
-- Magically all-done
else
actives[uid] = nil
end
end
end
local function hookMethod(self, obj, method, handler, script, secure)
if not handler then
handler = method
end
if not obj or type(obj) ~= "table" then
AceHook:error("The object you supplied could not be found, or isn't a table.")
end
local uid = registry[self][obj] and registry[self][obj][method]
if uid then
if actives[uid] then
-- We have an active hook from this source. Don't multi-hook
AceHook:error("%q already has an active hook from this source.", method)
end
if handlers[uid] == handler then
-- The hook is inactive, reactivate it.
actives[uid] = true
return
else
AceHook:error("There is a stale hook for %q can't hook or reactivate.", method)
end
end
if type(handler) == "string" then
if type(self[handler]) ~= "function" then
AceHook:error("Could not find the handler %q you supplied when hooking method %q", handler, method)
end
elseif type(handler) ~= "function" then
AceHook:error("Could not find the handler you supplied when hooking method %q", method)
end
local orig
if script then
if not obj.GetScript then
AceHook:error("The object you supplied does not have a GetScript method.")
end
if not obj:HasScript(method) then
AceHook:error("The object you supplied doesn't allow the %q method.", method)
end
orig = obj:GetScript(method)
if type(orig) ~= "function" then
-- Sometimes there is not a original function for a script.
orig = function() end
end
else
orig = obj[method]
end
if not orig then
AceHook:error("Could not find the method or script %q you are trying to hook.", method)
end
if not registry[self][obj] then
registry[self][obj] = new()
end
if not self.hooks[obj] then
self.hooks[obj] = new()
end
local uid = createMethodHook(self, obj, method, handler, orig, secure, script)
registry[self][obj][method] = uid
actives[uid] = true
handlers[uid] = handler
scripts[uid] = script and true or nil
if script then
obj:SetScript(method, uid)
self.hooks[obj][method] = orig
elseif not secure then
obj[method] = uid
self.hooks[obj][method] = orig
else
hooksecurefunc(obj, method, uid)
end
end
local function unhookMethod(self, obj, method)
if not registry[self][obj] or not registry[self][obj][method] then
AceHook:error("Attempt to unhook a method %q that is not currently hooked.", method)
return
end
local uid = registry[self][obj][method]
if actives[uid] then
if scripts[uid] then -- If this is a script
if obj:GetScript(method) == uid then
-- We own the script. Revert to normal.
obj:SetScript(method, self.hooks[obj][method])
self.hooks[obj][method] = nil
registry[self][obj][method] = nil
handlers[uid] = nil
scripts[uid] = nil
actives[uid] = nil
else
actives[uid] = nil
end
else
if self.hooks[obj] and self.hooks[obj][method] and obj[method] == uid then
-- We own the method. Revert to normal.
obj[method] = self.hooks[obj][method]
self.hooks[obj][method] = nil
registry[self][obj][method] = nil
handlers[uid] = nil
actives[uid] = nil
else
actives[uid] = nil
end
end
end
if self.hooks[obj] and not next(self.hooks[obj]) then
self.hooks[obj] = del(self.hooks[obj])
end
if not next(registry[self][obj]) then
registry[self][obj] = del(registry[self][obj])
end
end
-- ("function" [, handler] [, hookSecure]) or (object, "method" [, handler] [, hookSecure])
function AceHook:Hook(object, method, handler, hookSecure)
if type(object) == "string" then
method, handler, hookSecure = object, method, handler
if handler == true then
handler, hookSecure = nil, true
end
if not hookSecure and issecurevariable(method) then
AceHook:error("Attempt to hook secure function %q. Use `SecureHook' or add `true' to the argument list to override.", method)
end
AceHook:argCheck(handler, 3, "function", "string", "nil")
AceHook:argCheck(hookSecure, 4, "boolean", "nil")
hookFunction(self, method, handler, false)
else
if handler == true then
handler, hookSecure = nil, true
end
if not hookSecure and issecurevariable(object, method) then
AceHook:error("Attempt to hook secure method %q. Use `SecureHook' or add `true' to the argument list to override.", method)
end
AceHook:argCheck(object, 2, "table")
AceHook:argCheck(method, 3, "string")
AceHook:argCheck(handler, 4, "function", "string", "nil")
AceHook:argCheck(hookSecure, 5, "boolean", "nil")
hookMethod(self, object, method, handler, false, false)
end
end
-- ("function", handler) or (object, "method", handler)
function AceHook:SecureHook(object, method, handler)
if type(object) == "string" then
method, handler = object, method
AceHook:argCheck(handler, 3, "function", "string", "nil")
hookFunction(self, method, handler, true)
else
AceHook:argCheck(object, 2, "table")
AceHook:argCheck(method, 3, "string")
AceHook:argCheck(handler, 4, "function", "string", "nil")
hookMethod(self, object, method, handler, false, true)
end
end
function AceHook:HookScript(frame, script, handler)
AceHook:argCheck(frame, 2, "table")
if not frame[0] or type(frame.IsFrameType) ~= "function" then
AceHook:error("Bad argument #2 to `HookScript'. Expected frame.")
end
AceHook:argCheck(script, 3, "string")
AceHook:argCheck(handler, 4, "function", "string", "nil")
hookMethod(self, frame, script, handler, true, false)
end
-- ("function") or (object, "method")
function AceHook:IsHooked(obj, method)
if type(obj) == "string" then
if registry[self][obj] and actives[registry[self][obj]] then
return true, handlers[registry[self][obj]]
end
else
AceHook:argCheck(obj, 2, "string", "table")
AceHook:argCheck(method, 3, "string")
if registry[self][obj] and registry[self][obj][method] and actives[registry[self][obj][method]] then
return true, handlers[registry[self][obj][method]]
end
end
return false, nil
end
-- ("function") or (object, "method")
function AceHook:Unhook(obj, method)
if type(obj) == "string" then
unhookFunction(self, obj)
else
AceHook:argCheck(obj, 2, "string", "table")
AceHook:argCheck(method, 3, "string")
unhookMethod(self, obj, method)
end
end
function AceHook:UnhookAll()
for key, value in pairs(registry[self]) do
if type(key) == "table" then
for method in pairs(value) do
self:Unhook(key, method)
end
else
self:Unhook(key)
end
end
end
function AceHook:HookReport()
DEFAULT_CHAT_FRAME:AddMessage("This is a list of all active hooks for this object:")
if not next(registry[self]) then
DEFAULT_CHAT_FRAME:AddMessage("No hooks")
end
for key, value in pairs(registry[self]) do
if type(value) == "table" then
for method, uid in pairs(value) do
DEFAULT_CHAT_FRAME:AddMessage(string.format("object: %s method: %q |cff%s|r%s", tostring(key), method, actives[uid] and "00ff00Active" or "ffff00Inactive", not self.hooks[key][method] and " |cff7f7fff-Secure-|r" or ""))
end
else
DEFAULT_CHAT_FRAME:AddMessage(string.format("function: %q |cff%s|r%s", tostring(key), actives[value] and "00ff00Active" or "ffff00Inactive", not self.hooks[key] and " |cff7f7fff-Secure-|r" or ""))
end
end
end
function AceHook:OnInstanceInit(object)
if not object.hooks then
object.hooks = new()
end
if not registry[object] then
registry[object] = new()
end
end
AceHook.OnManualEmbed = AceHook.OnInstanceInit
function AceHook:OnEmbedDisable(target)
self.UnhookAll(target)
end
local function activate(self, oldLib, oldDeactivate)
AceHook = self
self.handlers = oldLib and oldLib.handlers or {}
self.registry = oldLib and oldLib.registry or {}
self.scripts = oldLib and oldLib.scripts or {}
self.actives = oldLib and oldLib.actives or {}
handlers = self.handlers
registry = self.registry
scripts = self.scripts
actives = self.actives
AceHook.super.activate(self, oldLib, oldDeactivate)
if oldDeactivate then
oldDeactivate(oldLib)
end
end
AceLibrary:Register(AceHook, MAJOR_VERSION, MINOR_VERSION, activate)
+757
View File
@@ -0,0 +1,757 @@
--[[
Name: AceLibrary
Revision: $Rev: 17722 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Iriel (iriel@vigilance-committee.org)
Tekkub (tekkub@gmail.com)
Revision: $Rev: 17722 $
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceLibrary
SVN: http://svn.wowace.com/root/trunk/Ace2/AceLibrary
Description: Versioning library to handle other library instances, upgrading,
and proper access.
It also provides a base for libraries to work off of, providing
proper error tools. It is handy because all the errors occur in the
file that called it, not in the library file itself.
Dependencies: None
]]
local ACELIBRARY_MAJOR = "AceLibrary"
local ACELIBRARY_MINOR = "$Revision: 17722 $"
if loadstring("return function(...) return ... end") and AceLibrary and AceLibrary:HasInstance(ACELIBRARY_MAJOR) then return end -- lua51 check
local table_setn
do
local version = GetBuildInfo()
if string.find(version, "^2%.") then
-- 2.0.0
table_setn = function() end
else
table_setn = table.setn
end
end
local string_gfind = string.gmatch or string.gfind
local _G = getfenv(0)
local previous = _G[ACELIBRARY_MAJOR]
if previous and not previous:IsNewVersion(ACELIBRARY_MAJOR, ACELIBRARY_MINOR) then return end
local function safecall(func,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
local success, err = pcall(func,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
if not success then geterrorhandler()(err) end
end
-- @table AceLibrary
-- @brief System to handle all versioning of libraries.
local AceLibrary = {}
local AceLibrary_mt = {}
setmetatable(AceLibrary, AceLibrary_mt)
local tmp
local function error(self, message, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if type(self) ~= "table" then
_G.error(string.format("Bad argument #1 to `error' (table expected, got %s)", type(self)), 2)
end
if not tmp then
tmp = {}
else
for k in pairs(tmp) do tmp[k] = nil end
table_setn(tmp, 0)
end
table.insert(tmp, a1)
table.insert(tmp, a2)
table.insert(tmp, a3)
table.insert(tmp, a4)
table.insert(tmp, a5)
table.insert(tmp, a6)
table.insert(tmp, a7)
table.insert(tmp, a8)
table.insert(tmp, a9)
table.insert(tmp, a10)
table.insert(tmp, a11)
table.insert(tmp, a12)
table.insert(tmp, a13)
table.insert(tmp, a14)
table.insert(tmp, a15)
table.insert(tmp, a16)
table.insert(tmp, a17)
table.insert(tmp, a18)
table.insert(tmp, a19)
table.insert(tmp, a20)
local stack = debugstack()
if not message then
local _,_,second = string.find(stack, "\n(.-)\n")
message = "error raised! " .. second
else
for i = 1,table.getn(tmp) do
tmp[i] = tostring(tmp[i])
end
for i = 1,10 do
table.insert(tmp, "nil")
end
message = string.format(message, unpack(tmp))
end
if getmetatable(self) and getmetatable(self).__tostring then
message = string.format("%s: %s", tostring(self), message)
elseif type(rawget(self, 'GetLibraryVersion')) == "function" and AceLibrary:HasInstance(self:GetLibraryVersion()) then
message = string.format("%s: %s", self:GetLibraryVersion(), message)
elseif type(rawget(self, 'class')) == "table" and type(rawget(self.class, 'GetLibraryVersion')) == "function" and AceLibrary:HasInstance(self.class:GetLibraryVersion()) then
message = string.format("%s: %s", self.class:GetLibraryVersion(), message)
end
local first = string.gsub(stack, "\n.*", "")
local file = string.gsub(first, ".*\\(.*).lua:%d+: .*", "%1")
file = string.gsub(file, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1")
local i = 0
for s in string_gfind(stack, "\n([^\n]*)") do
i = i + 1
if not string.find(s, file .. "%.lua:%d+:") then
file = string.gsub(s, "^.*\\(.*).lua:%d+: .*", "%1")
file = string.gsub(file, "([%(%)%.%*%+%-%[%]%?%^%$%%])", "%%%1")
break
end
end
local j = 0
for s in string_gfind(stack, "\n([^\n]*)") do
j = j + 1
if j > i and not string.find(s, file .. "%.lua:%d+:") then
_G.error(message, j + 1)
return
end
end
_G.error(message, 2)
return
end
local function assert(self, condition, message, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not condition then
if not message then
local stack = debugstack()
local _,_,second = string.find(stack, "\n(.-)\n")
message = "assertion failed! " .. second
end
error(self, message, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
return
end
return condition
end
local function argCheck(self, arg, num, kind, kind2, kind3, kind4, kind5)
if type(num) ~= "number" then
error(self, "Bad argument #3 to `argCheck' (number expected, got %s)", type(num))
elseif type(kind) ~= "string" then
error(self, "Bad argument #4 to `argCheck' (string expected, got %s)", type(kind))
end
local errored = false
arg = type(arg)
if arg ~= kind and arg ~= kind2 and arg ~= kind3 and arg ~= kind4 and arg ~= kind5 then
local _,_,func = string.find(debugstack(), "`argCheck'.-([`<].-['>])")
if not func then
_,_,func = string.find(debugstack(), "([`<].-['>])")
end
if kind5 then
error(self, "Bad argument #%s to %s (%s, %s, %s, %s, or %s expected, got %s)", tonumber(num) or 0/0, func, kind, kind2, kind3, kind4, kind5, arg)
elseif kind4 then
error(self, "Bad argument #%s to %s (%s, %s, %s, or %s expected, got %s)", tonumber(num) or 0/0, func, kind, kind2, kind3, kind4, arg)
elseif kind3 then
error(self, "Bad argument #%s to %s (%s, %s, or %s expected, got %s)", tonumber(num) or 0/0, func, kind, kind2, kind3, arg)
elseif kind2 then
error(self, "Bad argument #%s to %s (%s or %s expected, got %s)", tonumber(num) or 0/0, func, kind, kind2, arg)
else
error(self, "Bad argument #%s to %s (%s expected, got %s)", tonumber(num) or 0/0, func, kind, arg)
end
end
end
local function pcall(self, func, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 = _G.pcall(func, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not a1 then
error(self, string.gsub(a2, ".-%.lua:%d-: ", ""))
else
return a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20
end
end
local recurse = {}
local function addToPositions(t, major)
if not AceLibrary.positions[t] or AceLibrary.positions[t] == major then
rawset(t, recurse, true)
AceLibrary.positions[t] = major
for k,v in pairs(t) do
if type(v) == "table" and not rawget(v, recurse) then
addToPositions(v, major)
end
if type(k) == "table" and not rawget(k, recurse) then
addToPositions(k, major)
end
end
local mt = getmetatable(t)
if mt and not rawget(mt, recurse) then
addToPositions(mt, major)
end
rawset(t, recurse, nil)
end
end
local function svnRevisionToNumber(text)
if type(text) == "string" then
if string.find(text, "^%$Revision: (%d+) %$$") then
return tonumber((string.gsub(text, "^%$Revision: (%d+) %$$", "%1")))
elseif string.find(text, "^%$Rev: (%d+) %$$") then
return tonumber((string.gsub(text, "^%$Rev: (%d+) %$$", "%1")))
elseif string.find(text, "^%$LastChangedRevision: (%d+) %$$") then
return tonumber((string.gsub(text, "^%$LastChangedRevision: (%d+) %$$", "%1")))
end
elseif type(text) == "number" then
return text
end
return nil
end
local crawlReplace
do
local recurse = {}
local function func(t, to, from)
if recurse[t] then
return
end
recurse[t] = true
local mt = getmetatable(t)
setmetatable(t, nil)
rawset(t, to, rawget(t, from))
rawset(t, from, nil)
for k,v in pairs(t) do
if v == from then
t[k] = to
elseif type(v) == "table" then
if not recurse[v] then
func(v, to, from)
end
end
if type(k) == "table" then
if not recurse[k] then
func(k, to, from)
end
end
end
setmetatable(t, mt)
if mt then
if mt == from then
setmetatable(t, to)
elseif not recurse[mt] then
func(mt, to, from)
end
end
end
function crawlReplace(t, to, from)
func(t, to, from)
for k in pairs(recurse) do
recurse[k] = nil
end
end
end
-- @function destroyTable
-- @brief remove all the contents of a table
-- @param t table to destroy
local function destroyTable(t)
setmetatable(t, nil)
for k,v in pairs(t) do t[k] = nil end
table_setn(t, 0)
end
local function isFrame(frame)
return type(frame) == "table" and type(rawget(frame, 0)) == "userdata" and type(rawget(frame, 'IsFrameType')) == "function" and getmetatable(frame) and type(rawget(getmetatable(frame), '__index')) == "function"
end
local new, del
do
local tables = setmetatable({}, {__mode = "k"})
function new()
local t = next(tables)
if t then
tables[t] = nil
return t
else
return {}
end
end
function del(t, depth)
if depth and depth > 0 then
for k,v in pairs(t) do
if type(v) == "table" and not isFrame(v) then
del(v, depth - 1)
end
end
end
destroyTable(t)
tables[t] = true
end
end
-- @function copyTable
-- @brief Create a shallow copy of a table and return it.
-- @param from The table to copy from
-- @return A shallow copy of the table
local function copyTable(from)
local to = new()
for k,v in pairs(from) do to[k] = v end
table_setn(to, table.getn(from))
setmetatable(to, getmetatable(from))
return to
end
-- @function deepTransfer
-- @brief Fully transfer all data, keeping proper previous table
-- backreferences stable.
-- @param to The table with which data is to be injected into
-- @param from The table whose data will be injected into the first
-- @param saveFields If available, a shallow copy of the basic data is saved
-- in here.
-- @param list The account of table references
-- @param list2 The current status on which tables have been traversed.
local deepTransfer
do
-- @function examine
-- @brief Take account of all the table references to be shared
-- between the to and from tables.
-- @param to The table with which data is to be injected into
-- @param from The table whose data will be injected into the first
-- @param list An account of the table references
local function examine(to, from, list, major)
list[from] = to
for k,v in pairs(from) do
if rawget(to, k) and type(from[k]) == "table" and type(to[k]) == "table" and not list[from[k]] then
if from[k] == to[k] then
list[from[k]] = to[k]
elseif AceLibrary.positions[from[v]] ~= major and AceLibrary.positions[from[v]] then
list[from[k]] = from[k]
elseif not list[from[k]] then
examine(to[k], from[k], list, major)
end
end
end
return list
end
function deepTransfer(to, from, saveFields, major, list, list2)
setmetatable(to, nil)
local createdList
if not list then
createdList = true
list = new()
list2 = new()
examine(to, from, list, major)
end
list2[to] = to
for k,v in pairs(to) do
if type(rawget(from, k)) ~= "table" or type(v) ~= "table" or isFrame(v) then
if saveFields then
saveFields[k] = v
end
to[k] = nil
elseif v ~= _G then
if saveFields then
saveFields[k] = copyTable(v)
end
end
end
for k in pairs(from) do
if rawget(to, k) and to[k] ~= from[k] and AceLibrary.positions[to[k]] == major and from[k] ~= _G then
if not list2[to[k]] then
deepTransfer(to[k], from[k], nil, major, list, list2)
end
to[k] = list[to[k]] or list2[to[k]]
else
rawset(to, k, from[k])
end
end
table_setn(to, table.getn(from))
setmetatable(to, getmetatable(from))
local mt = getmetatable(to)
if mt then
if list[mt] then
setmetatable(to, list[mt])
elseif mt.__index and list[mt.__index] then
mt.__index = list[mt.__index]
end
end
destroyTable(from)
if createdList then
del(list)
del(list2)
end
end
end
-- @method TryToLoadStandalone
-- @brief Attempt to find and load a standalone version of the requested library
-- @param major A string representing the major version
-- @return If library is found, return values from the call to LoadAddOn are returned
-- If the library has been requested previously, nil is returned.
local function TryToLoadStandalone(major)
if not AceLibrary.scannedlibs then AceLibrary.scannedlibs = {} end
if AceLibrary.scannedlibs[major] then return end
AceLibrary.scannedlibs[major] = true
local name, _, _, enabled, loadable = GetAddOnInfo(major)
if loadable then
return LoadAddOn(name)
end
for i=1,GetNumAddOns() do
if GetAddOnMetadata(i, "X-AceLibrary-"..major) then
local name, _, _, enabled, loadable = GetAddOnInfo(i)
if loadable then
return LoadAddOn(name)
end
end
end
end
-- @method IsNewVersion
-- @brief Obtain whether the supplied version would be an upgrade to the
-- current version. This allows for bypass code in library
-- declaration.
-- @param major A string representing the major version
-- @param minor An integer or an svn revision string representing the minor version
-- @return whether the supplied version would be newer than what is
-- currently available.
function AceLibrary:IsNewVersion(major, minor)
argCheck(self, major, 2, "string")
TryToLoadStandalone(major)
if type(minor) == "string" then
local m = svnRevisionToNumber(minor)
if m then
minor = m
else
_G.error(string.format("Bad argument #3 to `IsNewVersion'. Must be a number or SVN revision string. %q is not appropriate", minor), 2)
end
end
argCheck(self, minor, 3, "number")
local data = self.libs[major]
if not data then
return true
end
return data.minor < minor
end
-- @method HasInstance
-- @brief Returns whether an instance exists. This allows for optional support of a library.
-- @param major A string representing the major version.
-- @param minor (optional) An integer or an svn revision string representing the minor version.
-- @return Whether an instance exists.
function AceLibrary:HasInstance(major, minor)
argCheck(self, major, 2, "string")
TryToLoadStandalone(major)
if minor then
if type(minor) == "string" then
local m = svnRevisionToNumber(minor)
if m then
minor = m
else
_G.error(string.format("Bad argument #3 to `HasInstance'. Must be a number or SVN revision string. %q is not appropriate", minor), 2)
end
end
argCheck(self, minor, 3, "number")
if not self.libs[major] then
return
end
return self.libs[major].minor == minor
end
return self.libs[major] and true
end
-- @method GetInstance
-- @brief Returns the library with the given major/minor version.
-- @param major A string representing the major version.
-- @param minor (optional) An integer or an svn revision string representing the minor version.
-- @return The library with the given major/minor version.
function AceLibrary:GetInstance(major, minor)
argCheck(self, major, 2, "string")
TryToLoadStandalone(major)
local data = self.libs[major]
if not data then
_G.error(string.format("Cannot find a library instance of %s.", major), 2)
return
end
if minor then
if type(minor) == "string" then
local m = svnRevisionToNumber(minor)
if m then
minor = m
else
_G.error(string.format("Bad argument #3 to `GetInstance'. Must be a number or SVN revision string. %q is not appropriate", minor), 2)
end
end
argCheck(self, minor, 2, "number")
if data.minor ~= minor then
_G.error(string.format("Cannot find a library instance of %s, minor version %d.", major, minor), 2)
return
end
end
return data.instance
end
-- Syntax sugar. AceLibrary("FooBar-1.0")
AceLibrary_mt.__call = AceLibrary.GetInstance
local donothing
local AceEvent
-- @method Register
-- @brief Registers a new version of a given library.
-- @param newInstance the library to register
-- @param major the major version of the library
-- @param minor the minor version of the library
-- @param activateFunc (optional) A function to be called when the library is
-- fully activated. Takes the arguments
-- (newInstance [, oldInstance, oldDeactivateFunc]). If
-- oldInstance is given, you should probably call
-- oldDeactivateFunc(oldInstance).
-- @param deactivateFunc (optional) A function to be called by a newer library's
-- activateFunc.
-- @param externalFunc (optional) A function to be called whenever a new
-- library is registered.
function AceLibrary:Register(newInstance, major, minor, activateFunc, deactivateFunc, externalFunc)
argCheck(self, newInstance, 2, "table")
argCheck(self, major, 3, "string")
if type(minor) == "string" then
local m = svnRevisionToNumber(minor)
if m then
minor = m
else
_G.error(string.format("Bad argument #4 to `Register'. Must be a number or SVN revision string. %q is not appropriate", minor), 2)
end
end
argCheck(self, minor, 4, "number")
if math.floor(minor) ~= minor or minor < 0 then
error(self, "Bad argument #4 to `Register' (integer >= 0 expected, got %s)", minor)
end
argCheck(self, activateFunc, 5, "function", "nil")
argCheck(self, deactivateFunc, 6, "function", "nil")
argCheck(self, externalFunc, 7, "function", "nil")
if not deactivateFunc then
if not donothing then
donothing = function() end
end
deactivateFunc = donothing
end
local data = self.libs[major]
if not data then
-- This is new
local instance = copyTable(newInstance)
crawlReplace(instance, instance, newInstance)
destroyTable(newInstance)
if AceLibrary == newInstance then
self = instance
AceLibrary = instance
end
self.libs[major] = {
instance = instance,
minor = minor,
deactivateFunc = deactivateFunc,
externalFunc = externalFunc,
}
rawset(instance, 'GetLibraryVersion', function(self)
return major, minor
end)
if not rawget(instance, 'error') then
rawset(instance, 'error', error)
end
if not rawget(instance, 'assert') then
rawset(instance, 'assert', assert)
end
if not rawget(instance, 'argCheck') then
rawset(instance, 'argCheck', argCheck)
end
if not rawget(instance, 'pcall') then
rawset(instance, 'pcall', pcall)
end
addToPositions(instance, major)
if activateFunc then
safecall(activateFunc, instance, nil, nil) -- no old version, so explicit nil
end
if externalFunc then
for k,data in pairs(self.libs) do
if k ~= major then
safecall(externalFunc, instance, k, data.instance)
end
end
end
for k,data in pairs(self.libs) do
if k ~= major and data.externalFunc then
safecall(data.externalFunc, data.instance, major, instance)
end
end
if major == "AceEvent-2.0" then
AceEvent = instance
end
if AceEvent then
AceEvent.TriggerEvent(self, "AceLibrary_Register", major, instance)
end
return instance
end
local instance = data.instance
if minor <= data.minor then
-- This one is already obsolete, raise an error.
_G.error(string.format("Obsolete library registered. %s is already registered at version %d. You are trying to register version %d. Hint: if not AceLibrary:IsNewVersion(%q, %d) then return end", major, data.minor, minor, major, minor), 2)
return
end
-- This is an update
local oldInstance = new()
addToPositions(newInstance, major)
local isAceLibrary = (AceLibrary == newInstance)
local old_error, old_assert, old_argCheck, old_pcall
if isAceLibrary then
self = instance
AceLibrary = instance
old_error = instance.error
old_assert = instance.assert
old_argCheck = instance.argCheck
old_pcall = instance.pcall
self.error = error
self.assert = assert
self.argCheck = argCheck
self.pcall = pcall
end
deepTransfer(instance, newInstance, oldInstance, major)
crawlReplace(instance, instance, newInstance)
local oldDeactivateFunc = data.deactivateFunc
data.minor = minor
data.deactivateFunc = deactivateFunc
data.externalFunc = externalFunc
rawset(instance, 'GetLibraryVersion', function(self)
return major, minor
end)
if not rawget(instance, 'error') then
rawset(instance, 'error', error)
end
if not rawget(instance, 'assert') then
rawset(instance, 'assert', assert)
end
if not rawget(instance, 'argCheck') then
rawset(instance, 'argCheck', argCheck)
end
if not rawget(instance, 'pcall') then
rawset(instance, 'pcall', pcall)
end
if isAceLibrary then
for _,v in pairs(self.libs) do
local i = type(v) == "table" and v.instance
if type(i) == "table" then
if not rawget(i, 'error') or i.error == old_error then
rawset(i, 'error', error)
end
if not rawget(i, 'assert') or i.assert == old_assert then
rawset(i, 'assert', assert)
end
if not rawget(i, 'argCheck') or i.argCheck == old_argCheck then
rawset(i, 'argCheck', argCheck)
end
if not rawget(i, 'pcall') or i.pcall == old_pcall then
rawset(i, 'pcall', pcall)
end
end
end
end
if activateFunc then
safecall(activateFunc, instance, oldInstance, oldDeactivateFunc)
else
safecall(oldDeactivateFunc, oldInstance)
end
del(oldInstance)
if externalFunc then
for k,data in pairs(self.libs) do
if k ~= major then
safecall(externalFunc, instance, k, data.instance)
end
end
end
return instance
end
local iter
function AceLibrary:IterateLibraries()
if not iter then
local function iter(t, k)
k = next(t, k)
if not k then
return nil
else
return k, t[k].instance
end
end
end
return iter, self.libs, nil
end
-- @function Activate
-- @brief The activateFunc for AceLibrary itself. Called when
-- AceLibrary properly registers.
-- @param self Reference to AceLibrary
-- @param oldLib (optional) Reference to an old version of AceLibrary
-- @param oldDeactivate (optional) Function to deactivate the old lib
local function activate(self, oldLib, oldDeactivate)
if not self.libs then
if oldLib then
self.libs = oldLib.libs
self.scannedlibs = oldLib.scannedlibs
end
if not self.libs then
self.libs = {}
end
if not self.scannedlibs then
self.scannedlibs = {}
end
end
if not self.positions then
if oldLib then
self.positions = oldLib.positions
end
if not self.positions then
self.positions = setmetatable({}, { __mode = "k" })
end
end
-- Expose the library in the global environment
_G[ACELIBRARY_MAJOR] = self
if oldDeactivate then
oldDeactivate(oldLib)
end
end
if not previous then
previous = AceLibrary
end
if not previous.libs then
previous.libs = {}
end
AceLibrary.libs = previous.libs
if not previous.positions then
previous.positions = setmetatable({}, { __mode = "k" })
end
AceLibrary.positions = previous.positions
AceLibrary:Register(AceLibrary, ACELIBRARY_MAJOR, ACELIBRARY_MINOR, activate)
+538
View File
@@ -0,0 +1,538 @@
--[[
Name: AceLocale-2.2
Revision: $Rev: 17638 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Ace 1.x by Turan (turan@gryphon.com)
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceLocale-2.2
SVN: http://svn.wowace.com/root/trunk/Ace2/AceLocale-2.2
Description: Localization library for addons to use to handle proper
localization and internationalization.
Dependencies: AceLibrary
]]
local MAJOR_VERSION = "AceLocale-2.2"
local MINOR_VERSION = "$Revision: 17639 $"
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary.") end
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
if loadstring("return function(...) return ... end") and AceLibrary:HasInstance(MAJOR_VERSION) then return end -- lua51 check
local AceLocale = {}
local DEFAULT_LOCALE = "enUS"
local _G = getfenv(0)
local BASE_TRANSLATIONS, DEBUGGING, TRANSLATIONS, BASE_LOCALE, TRANSLATION_TABLES, REVERSE_TRANSLATIONS, STRICTNESS, DYNAMIC_LOCALES, CURRENT_LOCALE, NAME
local rawget = rawget
local rawset = rawset
local type = type
local newRegistries = {}
local scheduleClear
local lastSelf
local __index = function(self, key)
lastSelf = self
local value = (rawget(self, TRANSLATIONS) or AceLocale.prototype)[key]
rawset(self, key, value)
return value
end
local __newindex = function(self, k, v)
if type(v) ~= "function" and type(k) ~= "table" then
AceLocale.error(self, "Cannot change the values of an AceLocale instance.")
end
rawset(self, k, v)
end
local __tostring = function(self)
if type(rawget(self, 'GetLibraryVersion')) == "function" then
return self:GetLibraryVersion()
else
return "AceLocale(" .. self[NAME] .. ")"
end
end
local function clearCache(self)
if not rawget(self, BASE_TRANSLATIONS) then
return
end
local cache = self[BASE_TRANSLATIONS]
rawset(self, REVERSE_TRANSLATIONS, nil)
for k in pairs(self) do
if rawget(cache, k) ~= nil then
self[k] = nil
end
end
rawset(self, 'tmp', true)
self.tmp = nil
end
local function refixInstance(instance)
if getmetatable(instance) then
setmetatable(instance, nil)
end
local translations = instance[TRANSLATIONS]
if translations then
if getmetatable(translations) then
setmetatable(translations, nil)
end
local baseTranslations = instance[BASE_TRANSLATIONS]
if getmetatable(baseTranslations) then
setmetatable(baseTranslations, nil)
end
if translations == baseTranslations or instance[STRICTNESS] then
setmetatable(instance, {
__index = __index,
__newindex = __newindex,
__tostring = __tostring
})
setmetatable(translations, {
__index = AceLocale.prototype
})
else
setmetatable(instance, {
__index = __index,
__newindex = __newindex,
__tostring = __tostring
})
setmetatable(translations, {
__index = baseTranslations,
})
setmetatable(baseTranslations, {
__index = AceLocale.prototype,
})
end
else
setmetatable(instance, {
__index = __index,
__newindex = __newindex,
__tostring = __tostring,
})
end
clearCache(instance)
newRegistries[instance] = true
scheduleClear()
return instance
end
function AceLocale:new(name)
self:argCheck(name, 2, "string")
if self.registry[name] and type(rawget(self.registry[name], 'GetLibraryVersion')) ~= "function" then
return self.registry[name]
end
AceLocale.registry[name] = refixInstance({
[STRICTNESS] = false,
[NAME] = name,
})
newRegistries[AceLocale.registry[name]] = true
return AceLocale.registry[name]
end
AceLocale.prototype = { class = AceLocale }
function AceLocale.prototype:EnableDebugging()
if rawget(self, BASE_TRANSLATIONS) then
AceLocale.error(self, "Cannot enable debugging after a translation has been registered.")
end
rawset(self, DEBUGGING, true)
end
function AceLocale.prototype:EnableDynamicLocales(override)
AceLocale.argCheck(self, override, 2, "boolean", "nil")
if not override and rawget(self, BASE_TRANSLATIONS) then
AceLocale.error(self, "Cannot enable dynamic locales after a translation has been registered.")
end
if not rawget(self, DYNAMIC_LOCALES) then
rawset(self, DYNAMIC_LOCALES, true)
if rawget(self, BASE_LOCALE) then
if not rawget(self, TRANSLATION_TABLES) then
rawset(self, TRANSLATION_TABLES, {})
end
self[TRANSLATION_TABLES][self[BASE_LOCALE]] = self[BASE_TRANSLATIONS]
self[TRANSLATION_TABLES][self[CURRENT_LOCALE]] = self[TRANSLATIONS]
end
end
end
function AceLocale.prototype:RegisterTranslations(locale, func)
AceLocale.argCheck(self, locale, 2, "string")
AceLocale.argCheck(self, func, 3, "function")
if locale == rawget(self, BASE_LOCALE) then
AceLocale.error(self, "Cannot provide the same locale more than once. %q provided twice.", locale)
end
if rawget(self, BASE_TRANSLATIONS) and GetLocale() ~= locale then
if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then
if not rawget(self, TRANSLATION_TABLES) then
rawset(self, TRANSLATION_TABLES, {})
end
if self[TRANSLATION_TABLES][locale] then
AceLocale.error(self, "Cannot provide the same locale more than once. %q provided twice.", locale)
end
local t = func()
func = nil
if type(t) ~= "table" then
AceLocale.error(self, "Bad argument #3 to `RegisterTranslations'. function did not return a table. (expected table, got %s)", type(t))
end
self[TRANSLATION_TABLES][locale] = t
t = nil
end
func = nil
return
end
local t = func()
func = nil
if type(t) ~= "table" then
AceLocale.error(self, "Bad argument #3 to `RegisterTranslations'. function did not return a table. (expected table, got %s)", type(t))
end
rawset(self, TRANSLATIONS, t)
if not rawget(self, BASE_TRANSLATIONS) then
rawset(self, BASE_TRANSLATIONS, t)
rawset(self, BASE_LOCALE, locale)
for key,value in pairs(t) do
if value == true then
t[key] = key
end
end
else
for key, value in pairs(self[TRANSLATIONS]) do
if not rawget(self[BASE_TRANSLATIONS], key) then
AceLocale.error(self, "Improper translation exists. %q is likely misspelled for locale %s.", key, locale)
end
if value == true then
AceLocale.error(self, "Can only accept true as a value on the base locale. %q is the base locale, %q is not.", rawget(self, BASE_LOCALE), locale)
end
end
end
rawset(self, CURRENT_LOCALE, locale)
refixInstance(self)
if rawget(self, DEBUGGING) or rawget(self, DYNAMIC_LOCALES) then
if not rawget(self, TRANSLATION_TABLES) then
rawset(self, TRANSLATION_TABLES, {})
end
self[TRANSLATION_TABLES][locale] = t
end
t = nil
end
function AceLocale.prototype:SetLocale(locale)
AceLocale.argCheck(self, locale, 2, "string", "boolean")
if not rawget(self, DYNAMIC_LOCALES) then
AceLocale.error(self, "Cannot call `SetLocale' without first calling `EnableDynamicLocales'.")
end
if not rawget(self, TRANSLATION_TABLES) then
AceLocale.error(self, "Cannot call `SetLocale' without first calling `RegisterTranslations'.")
end
if locale == true then
locale = GetLocale()
if not self[TRANSLATION_TABLES][locale] then
locale = self[BASE_LOCALE]
end
end
if self[CURRENT_LOCALE] == locale then
return
end
if not self[TRANSLATION_TABLES][locale] then
AceLocale.error(self, "Locale %q not registered.", locale)
end
self[TRANSLATIONS] = self[TRANSLATION_TABLES][locale]
self[CURRENT_LOCALE] = locale
refixInstance(self)
end
function AceLocale.prototype:GetLocale()
if not rawget(self, TRANSLATION_TABLES) then
AceLocale.error(self, "Cannot call `GetLocale' without first calling `RegisterTranslations'.")
end
return self[CURRENT_LOCALE]
end
local function iter(t, position)
return (next(t, position))
end
function AceLocale.prototype:IterateAvailableLocales()
if not rawget(self, DYNAMIC_LOCALES) then
AceLocale.error(self, "Cannot call `IterateAvailableLocales' without first calling `EnableDynamicLocales'.")
end
if not rawget(self, TRANSLATION_TABLES) then
AceLocale.error(self, "Cannot call `IterateAvailableLocales' without first calling `RegisterTranslations'.")
end
return iter, self[TRANSLATION_TABLES], nil
end
function AceLocale.prototype:HasLocale(locale)
if not rawget(self, DYNAMIC_LOCALES) then
AceLocale.error(self, "Cannot call `HasLocale' without first calling `EnableDynamicLocales'.")
end
AceLocale.argCheck(self, locale, 2, "string")
return rawget(self, TRANSLATION_TABLES) and self[TRANSLATION_TABLES][locale] ~= nil
end
function AceLocale.prototype:SetStrictness(strict)
AceLocale.argCheck(self, strict, 2, "boolean")
local mt = getmetatable(self)
if not mt then
AceLocale.error(self, "Cannot call `SetStrictness' without a metatable.")
end
if not rawget(self, TRANSLATIONS) then
AceLocale.error(self, "No translations registered.")
end
rawset(self, STRICTNESS, strict)
refixInstance(self)
end
local function initReverse(self)
rawset(self, REVERSE_TRANSLATIONS, {})
local alpha = self[TRANSLATIONS]
local bravo = self[REVERSE_TRANSLATIONS]
for base, localized in pairs(alpha) do
bravo[localized] = base
end
end
function AceLocale.prototype:GetTranslation(text)
AceLocale.argCheck(self, text, 1, "string", "number")
if not rawget(self, TRANSLATIONS) then
AceLocale.error(self, "No translations registered")
end
return self[text]
end
function AceLocale.prototype:GetStrictTranslation(text)
AceLocale.argCheck(self, text, 1, "string", "number")
local x = rawget(self, TRANSLATIONS)
if not x then
AceLocale.error(self, "No translations registered")
end
local value = rawget(x, text)
if value == nil then
AceLocale.error(self, "Translation %q does not exist for locale %s", text, self[CURRENT_LOCALE])
end
return value
end
function AceLocale.prototype:GetReverseTranslation(text)
local x = rawget(self, REVERSE_TRANSLATIONS)
if not x then
if not rawget(self, TRANSLATIONS) then
AceLocale.error(self, "No translations registered")
end
initReverse(self)
x = self[REVERSE_TRANSLATIONS]
end
local translation = x[text]
if not translation then
AceLocale.error(self, "Reverse translation for %q does not exist", text)
end
return translation
end
function AceLocale.prototype:GetIterator()
local x = rawget(self, TRANSLATIONS)
if not x then
AceLocale.error(self, "No translations registered")
end
return next, x, nil
end
function AceLocale.prototype:GetReverseIterator()
local x = rawget(self, REVERSE_TRANSLATIONS)
if not x then
if not rawget(self, TRANSLATIONS) then
AceLocale.error(self, "No translations registered")
end
initReverse(self)
x = self[REVERSE_TRANSLATIONS]
end
return next, x, nil
end
function AceLocale.prototype:HasTranslation(text)
AceLocale.argCheck(self, text, 1, "string", "number")
local x = rawget(self, TRANSLATIONS)
if not x then
AceLocale.error(self, "No translations registered")
end
return rawget(x, text) and true
end
function AceLocale.prototype:HasReverseTranslation(text)
local x = rawget(self, REVERSE_TRANSLATIONS)
if not x then
if not rawget(self, TRANSLATIONS) then
AceLocale.error(self, "No translations registered")
end
initReverse(self)
x = self[REVERSE_TRANSLATIONS]
end
return x[text] and true
end
function AceLocale.prototype:Debug()
if not rawget(self, DEBUGGING) then
return
end
local words = {}
local locales = {"enUS", "ruRU", "deDE", "frFR", "koKR", "zhCN", "zhTW", "esES"}
local localizations = {}
DEFAULT_CHAT_FRAME:AddMessage("--- AceLocale Debug ---")
for _,locale in ipairs(locales) do
if not self[TRANSLATION_TABLES][locale] then
DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q not found", locale))
else
localizations[locale] = self[TRANSLATION_TABLES][locale]
end
end
local localeDebug = {}
for locale, localization in pairs(localizations) do
localeDebug[locale] = {}
for word in pairs(localization) do
if type(localization[word]) == "table" then
if type(words[word]) ~= "table" then
words[word] = {}
end
for bit in pairs(localization[word]) do
if type(localization[word][bit]) == "string" then
words[word][bit] = true
end
end
elseif type(localization[word]) == "string" then
words[word] = true
end
end
end
for word in pairs(words) do
if type(words[word]) == "table" then
for bit in pairs(words[word]) do
for locale, localization in pairs(localizations) do
if not rawget(localization, word) or not localization[word][bit] then
localeDebug[locale][word .. "::" .. bit] = true
end
end
end
else
for locale, localization in pairs(localizations) do
if not rawget(localization, word) then
localeDebug[locale][word] = true
end
end
end
end
for locale, t in pairs(localeDebug) do
if not next(t) then
DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q complete", locale))
else
DEFAULT_CHAT_FRAME:AddMessage(string.format("Locale %q missing:", locale))
for word in pairs(t) do
DEFAULT_CHAT_FRAME:AddMessage(string.format(" %q", word))
end
end
end
DEFAULT_CHAT_FRAME:AddMessage("--- End AceLocale Debug ---")
end
setmetatable(AceLocale.prototype, {
__index = function(self, k)
if type(k) ~= "table" and k ~= 0 and k ~= "GetLibraryVersion" and k ~= "error" and k ~= "assert" and k ~= "argCheck" and k ~= "pcall" then -- HACK: remove "GetLibraryVersion" and such later.
AceLocale.error(lastSelf or self, "Translation %q does not exist.", k)
end
return nil
end
})
local function activate(self, oldLib, oldDeactivate)
AceLocale = self
self.frame = oldLib and oldLib.frame or CreateFrame("Frame")
self.registry = oldLib and oldLib.registry or {}
self.BASE_TRANSLATIONS = oldLib and oldLib.BASE_TRANSLATIONS or {}
self.DEBUGGING = oldLib and oldLib.DEBUGGING or {}
self.TRANSLATIONS = oldLib and oldLib.TRANSLATIONS or {}
self.BASE_LOCALE = oldLib and oldLib.BASE_LOCALE or {}
self.TRANSLATION_TABLES = oldLib and oldLib.TRANSLATION_TABLES or {}
self.REVERSE_TRANSLATIONS = oldLib and oldLib.REVERSE_TRANSLATIONS or {}
self.STRICTNESS = oldLib and oldLib.STRICTNESS or {}
self.NAME = oldLib and oldLib.NAME or {}
self.DYNAMIC_LOCALES = oldLib and oldLib.DYNAMIC_LOCALES or {}
self.CURRENT_LOCALE = oldLib and oldLib.CURRENT_LOCALE or {}
BASE_TRANSLATIONS = self.BASE_TRANSLATIONS
DEBUGGING = self.DEBUGGING
TRANSLATIONS = self.TRANSLATIONS
BASE_LOCALE = self.BASE_LOCALE
TRANSLATION_TABLES = self.TRANSLATION_TABLES
REVERSE_TRANSLATIONS = self.REVERSE_TRANSLATIONS
STRICTNESS = self.STRICTNESS
NAME = self.NAME
DYNAMIC_LOCALES = self.DYNAMIC_LOCALES
CURRENT_LOCALE = self.CURRENT_LOCALE
local GetTime = GetTime
local timeUntilClear = GetTime() + 5
scheduleClear = function()
if next(newRegistries) then
self.frame:Show()
timeUntilClear = GetTime() + 5
end
end
if not self.registry then
self.registry = {}
else
for name, instance in pairs(self.registry) do
local name = name
local mt = getmetatable(instance)
setmetatable(instance, nil)
instance[NAME] = name
local strict
if instance[STRICTNESS] ~= nil then
strict = instance[STRICTNESS]
elseif instance[TRANSLATIONS] ~= instance[BASE_TRANSLATIONS] then
if getmetatable(instance[TRANSLATIONS]).__index == oldLib.prototype then
strict = true
end
end
instance[STRICTNESS] = strict and true or false
refixInstance(instance)
end
end
self.frame:SetScript("OnEvent", scheduleClear)
self.frame:SetScript("OnUpdate", function() -- (this, elapsed)
if timeUntilClear - GetTime() <= 0 then
self.frame:Hide()
for k in pairs(newRegistries) do
clearCache(k)
newRegistries[k] = nil
k = nil
end
end
end)
self.frame:UnregisterAllEvents()
self.frame:RegisterEvent("ADDON_LOADED")
self.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
self.frame:Show()
if oldDeactivate then
oldDeactivate(oldLib)
end
end
AceLibrary:Register(AceLocale, MAJOR_VERSION, MINOR_VERSION, activate)
@@ -0,0 +1,462 @@
--[[
Name: AceModuleCore-2.0
Revision: $Rev: 17998 $
Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
Inspired By: Ace 1.x by Turan (turan@gryphon.com)
Website: http://www.wowace.com/
Documentation: http://www.wowace.com/index.php/AceModuleCore-2.0
SVN: http://svn.wowace.com/root/trunk/Ace2/AceModuleCore-2.0
Description: Mixin to provide a module system so that modules or plugins can
use an addon as its core.
Dependencies: AceLibrary, AceOO-2.0, AceAddon-2.0, AceEvent-2.0 (optional), Compost-2.0 (optional)
]]
local MAJOR_VERSION = "AceModuleCore-2.0"
local MINOR_VERSION = "$Revision: 17998 $"
if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
if loadstring("return function(...) return ... end") and AceLibrary:HasInstance(MAJOR_VERSION) then return end -- lua51 check
if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
local function safecall(func,a,b,c,d,e,f,g)
local success, err = pcall(func,a,b,c,d,e,f,g)
if not success then geterrorhandler()(err) end
end
local table_setn
do
local version = GetBuildInfo()
if string.find(version, "^2%.") then
-- 2.0.0
table_setn = function() end
else
table_setn = table.setn
end
end
local new, del
do
local list = setmetatable({}, {__mode = 'k'})
function new()
local t = next(list)
if t then
list[t] = nil
return t
else
return {}
end
end
function del(t)
for k in pairs(t) do
t[k] = nil
end
table_setn(t, 0)
list[t] = true
return nil
end
end
local AceOO = AceLibrary:GetInstance("AceOO-2.0")
local AceModuleCore = AceOO.Mixin {
"NewModule",
"HasModule",
"GetModule",
"IsModule",
"IterateModules",
"SetModuleMixins",
"SetModuleClass",
"IsModuleActive",
"ToggleModuleActive"
}
local AceEvent
local Compost = AceLibrary:HasInstance("Compost-2.0") and AceLibrary("Compost-2.0")
local function getlibrary(lib)
if type(lib) == "string" then
return AceLibrary(lib)
else
return lib
end
end
local tmp
function AceModuleCore:NewModule(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if not self.modules then
AceModuleCore:error("CreatePrototype() must be called before attempting to create a new module.", 2)
end
AceModuleCore:argCheck(name, 2, "string")
if string.len(name) == 0 then
AceModuleCore:error("Bad argument #2 to `NewModule`, string must not be empty")
end
if self.modules[name] then
AceModuleCore:error("The module %q has already been registered", name)
end
if not tmp then
tmp = {}
end
if a1 then table.insert(tmp, a1)
if a2 then table.insert(tmp, a2)
if a3 then table.insert(tmp, a3)
if a4 then table.insert(tmp, a4)
if a5 then table.insert(tmp, a5)
if a6 then table.insert(tmp, a6)
if a7 then table.insert(tmp, a7)
if a8 then table.insert(tmp, a8)
if a9 then table.insert(tmp, a9)
if a10 then table.insert(tmp, a10)
if a11 then table.insert(tmp, a11)
if a12 then table.insert(tmp, a12)
if a13 then table.insert(tmp, a13)
if a14 then table.insert(tmp, a14)
if a15 then table.insert(tmp, a15)
if a16 then table.insert(tmp, a16)
if a17 then table.insert(tmp, a17)
if a18 then table.insert(tmp, a18)
if a19 then table.insert(tmp, a19)
if a20 then table.insert(tmp, a20)
end end end end end end end end end end end end end end end end end end end end
for k,v in ipairs(tmp) do
tmp[k] = getlibrary(v)
end
if self.moduleMixins then
for _,mixin in ipairs(self.moduleMixins) do
local exists = false
for _,v in ipairs(tmp) do
if mixin == v then
exists = true
break
end
end
if not exists then
table.insert(tmp, mixin)
end
end
end
local module = AceOO.Classpool(self.moduleClass, unpack(tmp)):new(name)
self.modules[name] = module
module.name = name
module.title = name
AceModuleCore.totalModules[module] = self
if AceEvent then
AceEvent:TriggerEvent("Ace2_ModuleCreated", module)
end
for k in pairs(tmp) do
tmp[k] = nil
end
table_setn(tmp, 0)
return module
end
function AceModuleCore:HasModule(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if a1 then if not self.modules[a1] then return false end
if a2 then if not self.modules[a2] then return false end
if a3 then if not self.modules[a3] then return false end
if a4 then if not self.modules[a4] then return false end
if a5 then if not self.modules[a5] then return false end
if a6 then if not self.modules[a6] then return false end
if a7 then if not self.modules[a7] then return false end
if a8 then if not self.modules[a8] then return false end
if a9 then if not self.modules[a9] then return false end
if a10 then if not self.modules[a10] then return false end
if a11 then if not self.modules[a11] then return false end
if a12 then if not self.modules[a12] then return false end
if a13 then if not self.modules[a13] then return false end
if a14 then if not self.modules[a14] then return false end
if a15 then if not self.modules[a15] then return false end
if a16 then if not self.modules[a16] then return false end
if a17 then if not self.modules[a17] then return false end
if a18 then if not self.modules[a18] then return false end
if a19 then if not self.modules[a19] then return false end
if a20 then if not self.modules[a20] then return false end
end end end end end end end end end end end end end end end end end end end end
return true
end
function AceModuleCore:GetModule(name)
if not self.modules then
AceModuleCore:error("Error initializing class. Please report error.")
end
if not self.modules[name] then
AceModuleCore:error("Cannot find module %q.", name)
end
return self.modules[name]
end
function AceModuleCore:IsModule(module)
if self == AceModuleCore then
return AceModuleCore.totalModules[module]
else
for k,v in pairs(self.modules) do
if v == module then
return true
end
end
return false
end
end
function AceModuleCore:IterateModules()
local t = new()
for k in pairs(self.modules) do
table.insert(t, k)
end
table.sort(t)
local i = 0
return function()
i = i + 1
local x = t[i]
if x then
return x, self.modules[x]
else
t = del(t)
return nil
end
end, nil, nil
end
function AceModuleCore:SetModuleMixins(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
if self.moduleMixins then
AceModuleCore:error('Cannot call "SetModuleMixins" twice')
elseif not self.modules then
AceModuleCore:error("Error initializing class. Please report error.")
elseif next(self.modules) then
AceModuleCore:error('Cannot call "SetModuleMixins" after "NewModule" has been called.')
end
self.moduleMixins = Compost and Compost:Acquire(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) or {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20}
for k,v in ipairs(self.moduleMixins) do
self.moduleMixins[k] = getlibrary(v)
end
end
function AceModuleCore:SetModuleClass(class)
class = getlibrary(class)
AceModuleCore:assert(AceOO.inherits(class, AceOO.Class), "Bad argument #2 to `SetModuleClass' (Class expected)")
if not self.modules then
AceModuleCore:error("Error initializing class. Please report error.")
end
if self.customModuleClass then
AceModuleCore:error("Cannot call `SetModuleClass' twice.")
end
self.customModuleClass = true
self.moduleClass = class
self.modulePrototype = class.prototype
end
function AceModuleCore:ToggleModuleActive(module, state)
AceModuleCore:argCheck(module, 2, "table", "string")
AceModuleCore:argCheck(state, 3, "nil", "boolean")
if type(module) == "string" then
if not self:HasModule(module) then
AceModuleCore:error("Cannot find module %q", module)
end
module = self:GetModule(module)
else
if not self:IsModule(module) then
AceModuleCore:error("%q is not a module", module)
end
end
local disable
if state == nil then
disable = self:IsModuleActive(module)
else
disable = not state
if disable ~= self:IsModuleActive(module) then
return
end
end
if type(module.ToggleActive) == "function" then
return module:ToggleActive(not disable)
elseif AceOO.inherits(self, "AceDB-2.0") then
if not self.db or not self.db.raw then
AceModuleCore:error("Cannot toggle a module until `RegisterDB' has been called and `ADDON_LOADED' has been fireed.")
end
if type(self.db.raw.disabledModules) ~= "table" then
self.db.raw.disabledModules = Compost and Compost:Acquire() or {}
end
local _,profile = self:GetProfile()
if type(self.db.raw.disabledModules[profile]) ~= "table" then
self.db.raw.disabledModules[profile] = Compost and Compost:Acquire() or {}
end
if type(self.db.raw.disabledModules[profile][module.name]) ~= "table" then
self.db.raw.disabledModules[profile][module.name] = disable or nil
end
if not disable then
if not next(self.db.raw.disabledModules[profile]) then
if Compost then
Compost:Reclaim(self.db.raw.disabledModules[profile])
end
self.db.raw.disabledModules[profile] = nil
end
if not next(self.db.raw.disabledModules) then
if Compost then
Compost:Reclaim(self.db.raw.disabledModules)
end
self.db.raw.disabledModules = nil
end
end
else
if type(self.disabledModules) ~= "table" then
self.disabledModules = Compost and Compost:Acquire() or {}
end
self.disabledModules[module.name] = disable or nil
end
if AceOO.inherits(module, "AceAddon-2.0") then
local AceAddon = AceLibrary("AceAddon-2.0")
if not AceAddon.addonsStarted[module] then
return
end
end
if not disable then
local current = module.class
while true do
if current == AceOO.Class then
break
end
if current.mixins then
for mixin in pairs(current.mixins) do
if type(mixin.OnEmbedEnable) == "function" then
safecall(mixin.OnEmbedEnable, mixin, module)
end
end
end
current = current.super
end
if type(module.OnEnable) == "function" then
safecall(module.OnEnable, module)
end
if AceEvent then
AceEvent:TriggerEvent("Ace2_AddonEnabled", module)
end
else
local current = module.class
while true do
if current == AceOO.Class then
break
end
if current.mixins then
for mixin in pairs(current.mixins) do
if type(mixin.OnEmbedDisable) == "function" then
safecall(mixin.OnEmbedDisable, mixin, module)
end
end
end
current = current.super
end
if type(module.OnDisable) == "function" then
safecall(module.OnDisable, module)
end
if AceEvent then
AceEvent:TriggerEvent("Ace2_AddonDisabled", module)
end
end
return not disable
end
function AceModuleCore:IsModuleActive(module)
AceModuleCore:argCheck(module, 2, "table", "string")
if AceModuleCore == self then
self:argCheck(module, 2, "table")
local core = AceModuleCore.totalModules[module]
if not core then
self:error("Bad argument #2 to `IsModuleActive'. Not a module")
end
return core:IsModuleActive(module)
end
if type(module) == "string" then
if not self:HasModule(module) then
AceModuleCore:error("Cannot find module %q", module)
end
module = self:GetModule(module)
else
if not self:IsModule(module) then
AceModuleCore:error("%q is not a module", module)
end
end
if type(module.IsActive) == "function" then
return module:IsActive()
elseif AceOO.inherits(self, "AceDB-2.0") then
local _,profile = self:GetProfile()
return not self.db or not self.db.raw or not self.db.raw.disabledModules or not self.db.raw.disabledModules[profile] or not self.db.raw.disabledModules[profile][module.name]
else
return not self.disabledModules or not self.disabledModules[module.name]
end
end
function AceModuleCore:OnInstanceInit(target)
if target.modules then
AceModuleCore:error("OnInstanceInit cannot be called twice")
end
target.modules = Compost and Compost:Acquire() or {}
target.moduleClass = AceOO.Class("AceAddon-2.0")
target.modulePrototype = target.moduleClass.prototype
end
AceModuleCore.OnManualEmbed = AceModuleCore.OnInstanceInit
function AceModuleCore.OnEmbedProfileDisable(AceModuleCore, self, newProfile)
if not AceOO.inherits(self, "AceDB-2.0") then
return
end
local _,currentProfile = self:GetProfile()
for k, module in pairs(self.modules) do
if type(module.IsActive) == "function" or type(module.ToggleActive) == "function" then
-- continue
else
local currentActive = not self.db or not self.db.raw or not self.db.raw.disabledModules or not self.db.raw.disabledModules[currentProfile] or not self.db.raw.disabledModules[currentProfile][module.name]
local newActive = not self.db or not self.db.raw or not self.db.raw.disabledModules or not self.db.raw.disabledModules[newProfile] or not self.db.raw.disabledModules[newProfile][module.name]
if currentActive ~= newActive then
self:ToggleModuleActive(module)
if not self.db.raw.disabledModules then
self.db.raw.disabledModules = {}
end
if not self.db.raw.disabledModules[currentProfile] then
self.db.raw.disabledModules[currentProfile] = {}
end
self.db.raw.disabledModules[currentProfile][module.name] = not currentActive or nil
end
end
end
end
local function activate(self, oldLib, oldDeactivate)
AceModuleCore = self
if oldLib then
self.totalModules = oldLib.totalModules
end
if not self.totalModules then
self.totalModules = {}
end
self.super.activate(self, oldLib, oldDeactivate)
end
local function external(self, major, instance)
if major == "Compost-2.0" then
Compost = instance
elseif major == "AceEvent-2.0" then
AceEvent = instance
end
end
AceLibrary:Register(AceModuleCore, MAJOR_VERSION, MINOR_VERSION, activate, nil, external)
AceModuleCore = AceLibrary(MAJOR_VERSION)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

+156
View File
@@ -0,0 +1,156 @@
if not Cursive.superwow then
return
end
Cursive:RegisterDB("CursiveDB")
Cursive:RegisterDefaults("profile", {
enabled = true,
caption = "Cursive",
anchor = "CENTER",
x = -240,
y = 120,
-- editable
scale = 1,
width = 100,
height = 14,
spacing = 4,
maxrow = 10,
maxcol = 1,
})
Cursive.cmdtable = {
type = "group",
handler = Cursive,
args = {
["enabled"] = {
type = "toggle",
name = "Enabled",
desc = "Enable/Disable Cursive",
order = 1,
get = function()
return Cursive.db.profile.enabled
end,
set = function(v)
Cursive.db.profile.enabled = v
if v == true then
Cursive.core.enable()
else
Cursive.core.disable()
end
end,
},
["barwidth"] = {
type = "range",
name = "Health Bar Width",
desc = "Health Bar Width",
order = 1,
min = 30,
max = 150,
step = 5,
get = function()
return Cursive.db.profile.width
end,
set = function(v)
Cursive.db.profile.width = v
end,
},
["barheight"] = {
type = "range",
name = "Health Bar Height",
desc = "Health Bar Height",
order = 1,
min = 10,
max = 30,
step = 2,
get = function()
return Cursive.db.profile.height
end,
set = function(v)
Cursive.db.profile.height = v
end,
},
["spacing"] = {
type = "range",
name = "Spacing",
desc = "Spacing",
order = 1,
min = 0,
max = 10,
step = 1,
get = function()
return Cursive.db.profile.spacing
end,
set = function(v)
Cursive.db.profile.spacing = v
end,
},
["maxrow"] = {
type = "range",
name = "Max Rows",
desc = "Max Rows",
order = 1,
min = 1,
max = 20,
step = 1,
get = function()
return Cursive.db.profile.maxrow
end,
set = function(v)
Cursive.db.profile.maxrow = v
end,
},
["maxcol"] = {
type = "range",
name = "Max Columns",
desc = "Max Columns",
order = 1,
min = 1,
max = 5,
step = 1,
get = function()
return Cursive.db.profile.maxcol
end,
set = function(v)
Cursive.db.profile.maxcol = v
end,
},
["scale"] = {
type = "range",
name = "Scale",
desc = "Scale",
order = 1,
min = 0.5,
max = 2,
step = 0.1,
get = function()
return Cursive.db.profile.scale
end,
set = function(v)
Cursive.db.profile.scale = v
end,
},
}
}
local deuce = Cursive:NewModule("Options Menu")
deuce.hasFuBar = IsAddOnLoaded("FuBar") and FuBar
deuce.consoleCmd = not deuce.hasFuBar
CursiveOptions = AceLibrary("AceAddon-2.0"):new("AceDB-2.0", "FuBarPlugin-2.0")
CursiveOptions.name = "FuBar - Cursive"
CursiveOptions:RegisterDB("CursiveDB")
CursiveOptions.hasIcon = "Interface\\Icons\\spell_shadow_deathcoil"
CursiveOptions.defaultMinimapPosition = 180
CursiveOptions.independentProfile = true
CursiveOptions.hideWithoutStandby = false
-- XXX total hack
CursiveOptions.OnMenuRequest = Cursive.cmdtable
local args = AceLibrary("FuBarPlugin-2.0"):GetAceOptionsDataTable(CursiveOptions)
for k, v in pairs(args) do
if CursiveOptions.OnMenuRequest.args[k] == nil then
CursiveOptions.OnMenuRequest.args[k] = v
end
end
-- XXX end hack
+82
View File
@@ -0,0 +1,82 @@
function getDruidSpells()
return {
[339] = { name = "Entangling Roots", rank = 1, duration = 12 },
[1062] = { name = "Entangling Roots", rank = 2, duration = 15 },
[5195] = { name = "Entangling Roots", rank = 3, duration = 18 },
[5196] = { name = "Entangling Roots", rank = 4, duration = 21 },
[9852] = { name = "Entangling Roots", rank = 5, duration = 24 },
[9853] = { name = "Entangling Roots", rank = 6, duration = 27 },
[700] = { name = "Sleep", rank = 1, duration = 20 },
[1090] = { name = "Sleep", rank = 2, duration = 30 },
[2937] = { name = "Sleep", rank = 3, duration = 40 },
[770] = { name = "Faerie Fire", rank = 1, duration = 40 },
[778] = { name = "Faerie Fire", rank = 2, duration = 40 },
[9749] = { name = "Faerie Fire", rank = 3, duration = 40 },
[9907] = { name = "Faerie Fire", rank = 4, duration = 40 },
[16855] = { name = "Faerie Fire (Bear)", rank = 1, duration = 40 },
[17387] = { name = "Faerie Fire (Bear)", rank = 2, duration = 40 },
[17388] = { name = "Faerie Fire (Bear)", rank = 3, duration = 40 },
[17389] = { name = "Faerie Fire (Bear)", rank = 4, duration = 40 },
[16857] = { name = "Faerie Fire (Feral)", rank = 1, duration = 40 },
[17390] = { name = "Faerie Fire (Feral)", rank = 2, duration = 40 },
[17391] = { name = "Faerie Fire (Feral)", rank = 3, duration = 40 },
[17392] = { name = "Faerie Fire (Feral)", rank = 4, duration = 40 },
[2637] = { name = "Hibernate", rank = 1, duration = 20 },
[18657] = { name = "Hibernate", rank = 2, duration = 30 },
[18658] = { name = "Hibernate", rank = 3, duration = 40 },
[5570] = { name = "Insect Swarm", rank = 1, duration = 12 },
[24974] = { name = "Insect Swarm", rank = 2, duration = 12 },
[24975] = { name = "Insect Swarm", rank = 3, duration = 12 },
[24976] = { name = "Insect Swarm", rank = 4, duration = 12 },
[24977] = { name = "Insect Swarm", rank = 5, duration = 12 },
[8921] = { name = "Moonfire", rank = 1, duration = 9 },
[8924] = { name = "Moonfire", rank = 2, duration = 9 },
[8925] = { name = "Moonfire", rank = 3, duration = 9 },
[8926] = { name = "Moonfire", rank = 4, duration = 9 },
[8927] = { name = "Moonfire", rank = 5, duration = 9 },
[8928] = { name = "Moonfire", rank = 6, duration = 9 },
[8929] = { name = "Moonfire", rank = 7, duration = 9 },
[9833] = { name = "Moonfire", rank = 8, duration = 9 },
[9834] = { name = "Moonfire", rank = 9, duration = 9 },
[9835] = { name = "Moonfire", rank = 10, duration = 9 },
[1822] = { name = "Rake", rank = 1, duration = 9 },
[1823] = { name = "Rake", rank = 2, duration = 9 },
[1824] = { name = "Rake", rank = 3, duration = 9 },
[9904] = { name = "Rake", rank = 4, duration = 9 },
[1079] = { name = "Rip", rank = 1, duration = 12 },
[9492] = { name = "Rip", rank = 2, duration = 12 },
[9493] = { name = "Rip", rank = 3, duration = 12 },
[9752] = { name = "Rip", rank = 4, duration = 12 },
[9894] = { name = "Rip", rank = 5, duration = 12 },
[9896] = { name = "Rip", rank = 6, duration = 12 },
[2908] = { name = "Soothe Animal", rank = 1, duration = 15 },
[8955] = { name = "Soothe Animal", rank = 2, duration = 15 },
[9901] = { name = "Soothe Animal", rank = 3, duration = 15 },
[5211] = { name = "Bash", rank = 1, duration = 2 },
[6798] = { name = "Bash", rank = 2, duration = 3 },
[8983] = { name = "Bash", rank = 3, duration = 4 },
[22570] = { name = "Maim", rank = 1, duration = 5 },
[49802] = { name = "Maim", rank = 2, duration = 5 },
[49803] = { name = "Maim", rank = 3, duration = 5 },
[99] = { name = "Demoralizing Roar", rank = 1, duration = 30 },
[1735] = { name = "Demoralizing Roar", rank = 2, duration = 30 },
[9490] = { name = "Demoralizing Roar", rank = 3, duration = 30 },
[9747] = { name = "Demoralizing Roar", rank = 4, duration = 30 },
[9898] = { name = "Demoralizing Roar", rank = 5, duration = 30 },
[5209] = { name = "Challenging Roar", rank = 1, duration = 6 },
}
end
+41
View File
@@ -0,0 +1,41 @@
function getHunterSpells()
return {
[3043] = { name = "Scorpid Sting", rank = 1, duration = 20 },
[14275] = { name = "Scorpid Sting", rank = 2, duration = 20 },
[14276] = { name = "Scorpid Sting", rank = 3, duration = 20 },
[14277] = { name = "Scorpid Sting", rank = 4, duration = 20 },
[1978] = { name = "Serpent Sting", rank = 1, duration = 15 },
[13549] = { name = "Serpent Sting", rank = 2, duration = 15 },
[13550] = { name = "Serpent Sting", rank = 3, duration = 15 },
[13551] = { name = "Serpent Sting", rank = 4, duration = 15 },
[13552] = { name = "Serpent Sting", rank = 5, duration = 15 },
[13553] = { name = "Serpent Sting", rank = 6, duration = 15 },
[13554] = { name = "Serpent Sting", rank = 7, duration = 15 },
[13555] = { name = "Serpent Sting", rank = 8, duration = 15 },
[25295] = { name = "Serpent Sting", rank = 9, duration = 15 },
[3034] = { name = "Viper Sting", rank = 1, duration = 8 },
[14279] = { name = "Viper Sting", rank = 2, duration = 8 },
[14280] = { name = "Viper Sting", rank = 3, duration = 8 },
[2974] = { name = "Wing Clip", rank = 1, duration = 10 },
[14267] = { name = "Wing Clip", rank = 2, duration = 10 },
[14268] = { name = "Wing Clip", rank = 3, duration = 10 },
[5116] = { name = "Concussive Shot", rank = 1, duration = 4 },
[19386] = { name = "Wyvern Sting", rank = 1, duration = 12 },
[24132] = { name = "Wyvern Sting", rank = 2, duration = 12 },
[24133] = { name = "Wyvern Sting", rank = 3, duration = 12 },
[19306] = { name = "Counterattack", rank = 1, duration = 5 },
[20909] = { name = "Counterattack", rank = 2, duration = 5 },
[20910] = { name = "Counterattack", rank = 3, duration = 5 },
[1130] = { name = "Hunter\'s Mark", rank = 1, duration = 120 },
[14323] = { name = "Hunter\'s Mark", rank = 2, duration = 120 },
[14324] = { name = "Hunter\'s Mark", rank = 3, duration = 120 },
[14325] = { name = "Hunter\'s Mark", rank = 4, duration = 120 },
}
end
+12
View File
@@ -0,0 +1,12 @@
function getMageSpells()
return {
[118] = { name = "Polymorph", rank = "Rank 1", duration = 20 },
[12824] = { name = "Polymorph", rank = "Rank 2", duration = 30 },
[12825] = { name = "Polymorph", rank = "Rank 3", duration = 40 },
[12826] = { name = "Polymorph", rank = "Rank 4", duration = 50 },
[28270] = { name = "Polymorph: Cow", rank = "Rank 1", duration = 50 },
[28271] = { name = "Polymorph: Turtle", rank = "Rank 1", duration = 50 },
[28272] = { name = "Polymorph: Pig", rank = "Rank 1", duration = 50 },
}
end
+40
View File
@@ -0,0 +1,40 @@
function getPriestSpells()
return {
[1425] = { name = "Shackle Undead", rank = 1, duration = 30 },
[9486] = { name = "Shackle Undead", rank = 2, duration = 40 },
[10956] = { name = "Shackle Undead", rank = 3, duration = 50 },
[453] = { name = "Mind Soothe", rank = 1, duration = 15 },
[8192] = { name = "Mind Soothe", rank = 2, duration = 15 },
[10953] = { name = "Mind Soothe", rank = 3, duration = 15 },
[605] = { name = "Mind Control", rank = 1, duration = 60 },
[10911] = { name = "Mind Control", rank = 2, duration = 30 },
[10912] = { name = "Mind Control", rank = 3, duration = 30 },
[2944] = { name = "Devouring Plague", rank = 1, duration = 24 },
[19276] = { name = "Devouring Plague", rank = 2, duration = 24 },
[19277] = { name = "Devouring Plague", rank = 3, duration = 24 },
[19278] = { name = "Devouring Plague", rank = 4, duration = 24 },
[19279] = { name = "Devouring Plague", rank = 5, duration = 24 },
[19280] = { name = "Devouring Plague", rank = 6, duration = 24 },
[9035] = { name = "Hex of Weakness", rank = 1, duration = 120 },
[19281] = { name = "Hex of Weakness", rank = 2, duration = 120 },
[19282] = { name = "Hex of Weakness", rank = 3, duration = 120 },
[19283] = { name = "Hex of Weakness", rank = 4, duration = 120 },
[19284] = { name = "Hex of Weakness", rank = 5, duration = 120 },
[19285] = { name = "Hex of Weakness", rank = 6, duration = 120 },
[589] = { name = "Shadow Word: Pain", rank = 1, duration = 24 }, -- assume they have talent
[594] = { name = "Shadow Word: Pain", rank = 2, duration = 24 },
[970] = { name = "Shadow Word: Pain", rank = 3, duration = 24 },
[992] = { name = "Shadow Word: Pain", rank = 4, duration = 24 },
[2767] = { name = "Shadow Word: Pain", rank = 5, duration = 24 },
[10892] = { name = "Shadow Word: Pain", rank = 6, duration = 24 },
[10893] = { name = "Shadow Word: Pain", rank = 7, duration = 24 },
[10894] = { name = "Shadow Word: Pain", rank = 8, duration = 24 },
[15286] = { name = "Vampiric Embrace", rank = 1, duration = 60 },
}
end
+16
View File
@@ -0,0 +1,16 @@
function getRogueSpells()
return {
[2094] = { name = "Blind", rank = 1, duration = 10 },
[21060] = { name = "Blind", rank = 1, duration = 10 },
[6770] = { name = "Sap", rank = 1, duration = 25 },
[2070] = { name = "Sap", rank = 2, duration = 35 },
[11297] = { name = "Sap", rank = 3, duration = 45 },
[1776] = { name = "Gouge", rank = 1, duration = 4 },
[1777] = { name = "Gouge", rank = 2, duration = 4 },
[8629] = { name = "Gouge", rank = 3, duration = 4 },
[11285] = { name = "Gouge", rank = 4, duration = 4 },
[11286] = { name = "Gouge", rank = 5, duration = 4 },
}
end
+60
View File
@@ -0,0 +1,60 @@
function getWarlockSpells()
return {
[172] = { name = "Corruption", rank = 1, duration = 12 },
[6222] = { name = "Corruption", rank = 2, duration = 15 },
[6223] = { name = "Corruption", rank = 3, duration = 18 },
[7648] = { name = "Corruption", rank = 4, duration = 18 },
[11671] = { name = "Corruption", rank = 5, duration = 18 },
[11672] = { name = "Corruption", rank = 6, duration = 18 },
[25311] = { name = "Corruption", rank = 7, duration = 18 },
[980] = { name = "Curse of Agony", rank = 1, duration = 24 },
[1014] = { name = "Curse of Agony", rank = 2, duration = 24 },
[6217] = { name = "Curse of Agony", rank = 3, duration = 24 },
[11711] = { name = "Curse of Agony", rank = 4, duration = 24 },
[11712] = { name = "Curse of Agony", rank = 5, duration = 24 },
[11713] = { name = "Curse of Agony", rank = 6, duration = 24 },
[603] = { name = "Curse of Doom", rank = 1, duration = 60 },
[704] = { name = "Curse of Recklessness", rank = 1, duration = 120 },
[7658] = { name = "Curse of Recklessness", rank = 2, duration = 120 },
[7659] = { name = "Curse of Recklessness", rank = 3, duration = 120 },
[11717] = { name = "Curse of Recklessness", rank = 4, duration = 120 },
[17862] = { name = "Curse of Shadow", rank = 1, duration = 120 },
[17937] = { name = "Curse of Shadow", rank = 2, duration = 120 },
[1490] = { name = "Curse of the Elements", rank = 1, duration = 300 },
[11721] = { name = "Curse of the Elements", rank = 2, duration = 300 },
[11722] = { name = "Curse of the Elements", rank = 3, duration = 300 },
[1714] = { name = "Curse of Tongues", rank = 1, duration = 30 },
[11719] = { name = "Curse of Tongues", rank = 2, duration = 30 },
[702] = { name = "Curse of Weakness", rank = 1, duration = 120 },
[1108] = { name = "Curse of Weakness", rank = 2, duration = 120 },
[6205] = { name = "Curse of Weakness", rank = 3, duration = 120 },
[7646] = { name = "Curse of Weakness", rank = 4, duration = 120 },
[11707] = { name = "Curse of Weakness", rank = 5, duration = 120 },
[11708] = { name = "Curse of Weakness", rank = 6, duration = 120 },
[18223] = { name = "Curse of Exhaustion", rank = 1, duration = 12 },
[348] = { name = "Immolate", rank = 1, duration = 15 },
[707] = { name = "Immolate", rank = 2, duration = 15 },
[1094] = { name = "Immolate", rank = 3, duration = 15 },
[2941] = { name = "Immolate", rank = 4, duration = 15 },
[11665] = { name = "Immolate", rank = 5, duration = 15 },
[11667] = { name = "Immolate", rank = 6, duration = 15 },
[11668] = { name = "Immolate", rank = 7, duration = 15 },
[25309] = { name = "Immolate", rank = 8, duration = 15 },
[6789] = { name = "Death Coil", rank = 1, duration = 3 },
[17925] = { name = "Death Coil", rank = 2, duration = 3 },
[17926] = { name = "Death Coil", rank = 3, duration = 3 },
[710] = { name = "Banish", rank = 1, duration = 30 },
[18647] = { name = "Banish", rank = 2, duration = 30 },
}
end
+335
View File
@@ -0,0 +1,335 @@
if not Cursive.superwow then
return
end
local utils = Cursive.utils
local filter = Cursive.filter
local ui = CreateFrame("Frame", nil, UIParent)
ui.border = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
}
ui.background = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
tile = true, tileSize = 16, edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
}
ui.frames = {}
ui.CreateRoot = function(parent, caption)
local frame = CreateFrame("Frame", "Cursive" .. caption, parent)
frame.id = caption
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetMovable(true)
frame:SetScript("OnDragStart", function()
this.lock = true
this:StartMoving()
end)
frame:SetScript("OnDragStop", function()
-- load current window config
-- convert to best anchor depending on position
local new_anchor = utils.GetBestAnchor(this)
local anchor, x, y = utils.ConvertFrameAnchor(this, new_anchor)
this:ClearAllPoints()
this:SetPoint(anchor, UIParent, anchor, x, y)
-- save new position
anchor, _, _, x, y = this:GetPoint()
Cursive.db.profile.anchor, Cursive.db.profile.x, Cursive.db.profile.y = anchor, x, y
-- stop drag
this:StopMovingOrSizing()
this.lock = false
end)
-- assign/initialize elements
frame.CreateBar = ui.CreateBar
frame.frames = {}
-- create title text
frame.caption = frame:CreateFontString(nil, "HIGH", "GameFontWhite")
frame.caption:SetFont(STANDARD_TEXT_FONT, 9, "THINOUTLINE")
frame.caption:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -2)
frame.caption:SetTextColor(1, 1, 1, 1)
frame.caption:SetText(caption)
return frame
end
ui.BarEnter = function()
this.border:SetBackdropBorderColor(1, 1, 1, 1)
this.hover = true
GameTooltip_SetDefaultAnchor(GameTooltip, this)
GameTooltip:SetUnit(this.guid)
GameTooltip:Show()
end
ui.BarLeave = function()
this.hover = false
GameTooltip:Hide()
end
ui.BarUpdate = function()
-- update statusbar values
this.bar:SetMinMaxValues(0, UnitHealthMax(this.guid))
this.bar:SetValue(UnitHealth(this.guid))
-- update health bar color
local hex, r, g, b, a = utils.GetUnitColor(this.guid)
this.bar:SetStatusBarColor(r, g, b, a)
-- update caption text
local name = UnitName(this.guid)
local hp = UnitHealth(this.guid)
-- convert hp to k if > 1000
if hp and hp > 1000 then
-- round to 1 decimal
hp = math.floor(hp / 100) / 10 .. "k"
end
if name then
if hp then
this.text:SetText(name .. " " .. tostring(hp))
else
this.text:SetText(name)
end
end
-- update health bar border
if this.hover then
this.border:SetBackdropBorderColor(1, 1, 1, 1)
elseif UnitAffectingCombat(this.guid) then
this.border:SetBackdropBorderColor(.8, .2, .2, 1)
else
this.border:SetBackdropBorderColor(.2, .2, .2, 1)
end
-- show raid icon if existing
if GetRaidTargetIndex(this.guid) then
SetRaidTargetIconTexture(this.icon, GetRaidTargetIndex(this.guid))
this.icon:Show()
else
this.icon:Hide()
end
-- update target indicator
if UnitIsUnit("target", this.guid) then
this.target_left:Show()
else
this.target_left:Hide()
end
end
ui.BarClick = function()
TargetUnit(this.guid)
end
ui.CreateBar = function(parent, guid)
local frame = CreateFrame("Button", nil, parent)
frame.guid = guid
frame:SetScript("OnClick", ui.BarClick)
frame:SetScript("OnEnter", ui.BarEnter)
frame:SetScript("OnLeave", ui.BarLeave)
frame:SetScript("OnUpdate", ui.BarUpdate)
-- create health bar
local bar = CreateFrame("StatusBar", nil, frame)
bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
bar:SetStatusBarColor(1, .8, .2, 1)
bar:SetMinMaxValues(0, 100)
bar:SetValue(20)
bar:SetAllPoints()
frame.bar = bar
-- create caption text
local text = frame.bar:CreateFontString(nil, "HIGH", "GameFontWhite")
text:SetPoint("TOPLEFT", bar, "TOPLEFT", 2, -2)
text:SetPoint("BOTTOMRIGHT", bar, "BOTTOMRIGHT", -2, 2)
text:SetFont(STANDARD_TEXT_FONT, 9, "THINOUTLINE")
text:SetJustifyH("LEFT")
frame.text = text
-- create raid icon textures
local icon = bar:CreateTexture(nil, "OVERLAY")
icon:SetWidth(16)
icon:SetHeight(16)
icon:SetPoint("RIGHT", frame, "RIGHT", -2, 0)
icon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
icon:Hide()
frame.icon = icon
-- display up to 3 curses
for i = 1, 3 do
local curse = bar:CreateTexture(nil, "OVERLAY")
curse:SetWidth(20)
curse:SetHeight(20)
curse:SetPoint("LEFT", frame, "RIGHT", 4 + ((i - 1) * 20), 0)
curse.timer = bar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
curse.timer:SetFontObject(GameFontHighlight)
curse.timer:SetFont(STANDARD_TEXT_FONT, 11, "OUTLINE")
curse.timer:SetTextColor(1, 1, 1)
curse.timer:SetAllPoints(curse)
curse.timer:Hide()
curse:Hide()
frame["curse" .. i] = curse
end
-- create target indicator
local target_left = bar:CreateTexture(nil, "OVERLAY")
target_left:SetWidth(8)
target_left:SetHeight(8)
target_left:SetPoint("LEFT", frame, "LEFT", -4, 0)
target_left:SetTexture("Interface\\AddOns\\Cursive\\img\\target-left")
target_left:Hide()
frame.target_left = target_left
-- create frame backdrops
if pfUI and pfUI.uf then
pfUI.api.CreateBackdrop(frame)
frame.border = frame.backdrop
else
frame:SetBackdrop(ui.background)
frame:SetBackdropColor(0, 0, 0, 1)
local border = CreateFrame("Frame", nil, frame.bar)
border:SetBackdrop(ui.border)
border:SetBackdropColor(.2, .2, .2, 1)
border:SetPoint("TOPLEFT", frame.bar, "TOPLEFT", -2, 2)
border:SetPoint("BOTTOMRIGHT", frame.bar, "BOTTOMRIGHT", 2, -2)
frame.border = border
end
return frame
end
ui:SetAllPoints()
ui:SetScript("OnUpdate", function()
if not Cursive.db.profile.enabled then
return
end
if (this.tick or 1) > GetTime() then
return
else
this.tick = GetTime() + .2
end
local caption = Cursive.db.profile.caption
local config = Cursive.db.profile
-- create ui frames based on config values
-- create root frame if not existing
ui.frames[caption] = ui.frames[caption] or ui:CreateRoot(caption)
local root = ui.frames[caption]
-- skip if locked (due to moving)
if root.lock then
return
end
-- update position based on config
if not root.pos or root.pos ~= config.anchor .. config.x .. config.y .. config.scale then
root.pos = config.anchor .. config.x .. config.y .. config.scale
root:ClearAllPoints()
root:SetPoint(config.anchor, config.x, config.y)
root:SetScale(config.scale)
end
-- run through all guids and fill with bars
local title_size = 12 + config.spacing
local width, height = config.width, config.height + title_size
local x, y, count = 0, 0, 0
for guid, time in pairs(Cursive.core.guids) do
-- apply filters
local shouldDisplay = Cursive:ShouldDisplayGuid(guid)
local exists = UnitExists(guid)
-- display element if filters allow it
if exists and shouldDisplay then
count = count + 1
if count > config.maxrow then
count, x = 1, x + config.width + config.spacing
width = math.max(x + config.width, width)
end
y = (count - 1) * (config.height + config.spacing) + title_size
height = math.max(y + config.height + config.spacing, height)
root.frames[guid] = root.frames[guid] or root:CreateBar(guid)
-- update position if required
if not root.frames[guid].pos or root.frames[guid].pos ~= x .. -y then
root.frames[guid]:ClearAllPoints()
root.frames[guid]:SetPoint("TOPLEFT", root, "TOPLEFT", x, -y)
root.frames[guid].pos = x .. -y
end
-- update sizes if required
if not root.frames[guid].sizes or root.frames[guid].sizes ~= config.width .. config.height then
root.frames[guid]:SetWidth(config.width)
root.frames[guid]:SetHeight(config.height)
root.frames[guid].sizes = config.width .. config.height
end
-- update curses
local curseNumber = 1
local guidCurses = Cursive.curses.guids[guid]
if guidCurses then
for curseName, curseData in pairs(guidCurses) do
if curseNumber > 3 then
break
end
local remaining = Cursive.curses:TimeRemaining(curseData)
local curse = root.frames[guid]["curse" .. curseNumber]
if remaining >= 0 then
curse:SetTexture(Cursive.curses.trackedCurseIds[curseData.spellID].texture)
curse.timer:SetText(remaining)
curse.timer:Show()
curse:Show()
else
curse.timer:Hide()
curse:Hide()
end
curseNumber = curseNumber + 1
end
end
root.frames[guid]:Show()
else
if root.frames[guid] then
root.frames[guid]:Hide()
root.frames[guid] = nil
end
if not exists then
-- remove from core
Cursive.core.remove(guid)
-- remove from curses
Cursive.curses:RemoveGuid(guid)
end
end
end
-- update window size
root:SetWidth(width)
root:SetHeight(height)
end)
Cursive.ui = ui
+178
View File
@@ -0,0 +1,178 @@
if not Cursive.superwow then
return
end
local utils = {}
utils.strsplit = function(delimiter, subject)
if not subject then return nil end
local delimiter, fields = delimiter or ":", {}
local pattern = string.format("([^%s]+)", delimiter)
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
return unpack(fields)
end
utils.round = function(input, places)
if not places then places = 0 end
if type(input) == "number" and type(places) == "number" then
local pow = 1
for i = 1, places do pow = pow * 10 end
return floor(input * pow + 0.5) / pow
end
end
utils.IsValidAnchor = function(anchor)
if anchor == "TOP" then return true end
if anchor == "TOPLEFT" then return true end
if anchor == "TOPRIGHT" then return true end
if anchor == "CENTER" then return true end
if anchor == "LEFT" then return true end
if anchor == "RIGHT" then return true end
if anchor == "BOTTOM" then return true end
if anchor == "BOTTOMLEFT" then return true end
if anchor == "BOTTOMRIGHT" then return true end
return false
end
utils.GetBestAnchor = function(self)
local scale = self:GetScale()
local x, y = self:GetCenter()
local a = GetScreenWidth() / scale / 3
local b = GetScreenWidth() / scale / 3 * 2
local c = GetScreenHeight() / scale / 3 * 2
local d = GetScreenHeight() / scale / 3
if not x or not y then return end
if x < a and y > c then
return "TOPLEFT"
elseif x > a and x < b and y > c then
return "TOP"
elseif x > b and y > c then
return "TOPRIGHT"
elseif x < a and y > d and y < c then
return "LEFT"
elseif x > a and x < b and y > d and y < c then
return "CENTER"
elseif x > b and y > d and y < c then
return "RIGHT"
elseif x < a and y < d then
return "BOTTOMLEFT"
elseif x > a and x < b and y < d then
return "BOTTOM"
elseif x > b and y < d then
return "BOTTOMRIGHT"
end
end
utils.ConvertFrameAnchor = function(self, anchor)
local scale, x, y, _ = self:GetScale(), nil, nil, nil
if anchor == "CENTER" then
x, y = self:GetCenter()
x, y = x - GetScreenWidth()/2/scale, y - GetScreenHeight()/2/scale
elseif anchor == "TOPLEFT" then
x, y = self:GetLeft(), self:GetTop() - GetScreenHeight()/scale
elseif anchor == "TOP" then
x, _ = self:GetCenter()
x, y = x - GetScreenWidth()/2/scale, self:GetTop() - GetScreenHeight()/scale
elseif anchor == "TOPRIGHT" then
x, y = self:GetRight() - GetScreenWidth()/scale, self:GetTop() - GetScreenHeight()/scale
elseif anchor == "RIGHT" then
_, y = self:GetCenter()
x, y = self:GetRight() - GetScreenWidth()/scale, y - GetScreenHeight()/2/scale
elseif anchor == "BOTTOMRIGHT" then
x, y = self:GetRight() - GetScreenWidth()/scale, self:GetBottom()
elseif anchor == "BOTTOM" then
x, _ = self:GetCenter()
x, y = x - GetScreenWidth()/2/scale, self:GetBottom()
elseif anchor == "BOTTOMLEFT" then
x, y = self:GetLeft(), self:GetBottom()
elseif anchor == "LEFT" then
_, y = self:GetCenter()
x, y = self:GetLeft(), y - GetScreenHeight()/2/scale
end
return anchor, utils.round(x, 2), utils.round(y, 2)
end
local _r, _g, _b, _a
utils.rgbhex = function(r, g, b, a)
if type(r) == "table" then
if r.r then
_r, _g, _b, _a = r.r, r.g, r.b, (r.a or 1)
elseif table.getn(r) >= 3 then
_r, _g, _b, _a = r[1], r[2], r[3], (r[4] or 1)
end
elseif tonumber(r) then
_r, _g, _b, _a = r, g, b, (a or 1)
end
if _r and _g and _b and _a then
-- limit values to 0-1
_r = _r + 0 > 1 and 1 or _r + 0
_g = _g + 0 > 1 and 1 or _g + 0
_b = _b + 0 > 1 and 1 or _b + 0
_a = _a + 0 > 1 and 1 or _a + 0
return string.format("|c%02x%02x%02x%02x", _a*255, _r*255, _g*255, _b*255)
end
return ""
end
utils.GetReactionColor = function(unitstr)
local color = UnitReactionColor[UnitReaction(unitstr, "player")]
local r, g, b = .8, .8, .8
if color then
r, g, b = color.r, color.g, color.b
end
return utils.rgbhex(r,g,b), r, g, b
end
utils.GetUnitColor = function(unitstr)
local r, g, b = .8, .8, .8
if UnitIsPlayer(unitstr) then
local _, class = UnitClass(unitstr)
if RAID_CLASS_COLORS[class] then
r, g, b = RAID_CLASS_COLORS[class].r, RAID_CLASS_COLORS[class].g, RAID_CLASS_COLORS[class].b
end
else
return utils.GetReactionColor(unitstr)
end
return utils.rgbhex(r,g,b), r, g, b
end
utils.GetLevelColor = function(unitstr)
local color = GetDifficultyColor(UnitLevel(unitstr))
local r, g, b = .8, .8, .8
if color then
r, g, b = color.r, color.g, color.b
end
return utils.rgbhex(r,g,b), r, g, b
end
utils.GetLevelString = function(unitstr)
local level = UnitLevel(unitstr)
if level == -1 then level = "??" end
local elite = UnitClassification(unitstr)
if elite == "worldboss" then
level = level .. "B"
elseif elite == "rareelite" then
level = level .. "R+"
elseif elite == "elite" then
level = level .. "+"
elseif elite == "rare" then
level = level .. "R"
end
return level
end
Cursive.utils = utils