Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
104 lines (94 loc) · 2.91 KB
/
Copy pathCore.lua
File metadata and controls
104 lines (94 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local ADDON_NAME, MM = ...
MM = MM or {}
_G.MacroMaker = MM
MM.name = ADDON_NAME or "MacroMaker"
MM.version = "0.4.0"
MM.ASCENSION_BODY_LIMIT = 511
MM.WRATH_BODY_LIMIT = 255
MM.NAME_LIMIT = 16
local defaults = {
bodyLimit = 511,
showPassive = false,
showRanks = false,
lastScope = "character",
drafts = {},
}
local function CopyDefaults(source, target)
for key, value in pairs(source) do
if target[key] == nil then
if type(value) == "table" then
target[key] = {}
CopyDefaults(value, target[key])
else
target[key] = value
end
end
end
end
function MM:Print(message)
DEFAULT_CHAT_FRAME:AddMessage("|cff65d6ffMacro Maker:|r " .. tostring(message))
end
function MM:UTF8Length(text)
local count = 0
text = tostring(text or "")
for position = 1, string.len(text) do
local value = string.byte(text, position)
if value < 128 or value >= 192 then count = count + 1 end
end
return count
end
function MM:UTF8Prefix(text, maxCharacters)
local count = 0
text = tostring(text or "")
for position = 1, string.len(text) do
local value = string.byte(text, position)
if value < 128 or value >= 192 then
count = count + 1
if count > maxCharacters then return string.sub(text, 1, position - 1) end
end
end
return text
end
function MM:InitializeDatabase()
MacroMakerDB = MacroMakerDB or {}
CopyDefaults(defaults, MacroMakerDB)
self.db = MacroMakerDB
end
function MM:Toggle()
if not self.UI then return end
if self.UI:IsShown() then
self.UI:Hide()
else
self.UI:Show()
self:RefreshAll()
end
end
function MM:RefreshAll()
if self.ScanSpellbook then self:ScanSpellbook() end
if self.RefreshMacroList then self:RefreshMacroList() end
if self.RefreshSpellList then self:RefreshSpellList() end
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:RegisterEvent("SPELLS_CHANGED")
eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == MM.name then
MM:InitializeDatabase()
if MM.CreateUI then MM:CreateUI() end
elseif event == "PLAYER_LOGIN" then
SLASH_MACROMAKER1 = "/macromaker"
SLASH_MACROMAKER2 = "/mmaker"
SlashCmdList.MACROMAKER = function() MM:Toggle() end
if MM.RegisterEscapeMenuButton then MM:RegisterEscapeMenuButton() end
MM:RefreshAll()
elseif event == "SPELLS_CHANGED" then
MM:ScanSpellbook()
if MM.UI and MM.UI:IsShown() then MM:RefreshSpellList() end
elseif event == "PLAYER_REGEN_ENABLED" and MM.pendingSave then
local pending = MM.pendingSave
MM.pendingSave = nil
MM:CommitMacro(pending)
end
end)