Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
101 lines (84 loc) · 2.65 KB
/
Copy pathCore.lua
File metadata and controls
101 lines (84 loc) · 2.65 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
---@type string
local addonName = ...
---@class Whetstone
local ns = select(2, ...)
ns.inCombat = false
ns.playerLevel = 1
function ns.Print(...) print("|cff33ccff" .. addonName .. ":|r", ...) end
local function InitDB()
WhetstoneDB = WhetstoneDB or {}
local db = WhetstoneDB
for key, value in pairs(ns.DEFAULTS) do
if db[key] == nil then db[key] = value end
end
---@type table<string, true>
db.hidden = db.hidden or {}
ns.db = db
end
local frame = CreateFrame("Frame")
---@type table<string, fun(...)>
local events = {}
local function RegisterRuntimeEvents()
for event in pairs(events) do
frame:RegisterEvent(event)
end
end
function events.PLAYER_LOGIN()
InitDB()
ns.playerLevel = UnitLevel("player")
ns.Bar:Init()
ns.Options:Init()
RegisterRuntimeEvents()
ns.StartScanning()
end
events.SKILL_LINES_CHANGED = ns.OnSkillLinesChanged
-- Rank gains. SKILL_LINES_CHANGED is only documented for learning, unlearning and new caps.
events.CHAT_MSG_SKILL = ns.RequestScan
-- UnitLevel still returns the old level while this event fires.
function events.PLAYER_LEVEL_UP(level)
ns.playerLevel = level
ns.RequestScan()
end
---@param slot number
function events.PLAYER_EQUIPMENT_CHANGED(slot)
if slot == INVSLOT_MAINHAND or slot == INVSLOT_OFFHAND or slot == INVSLOT_RANGED then ns.InvalidateEquipped() end
ns.RequestScan()
end
function events.UPDATE_SHAPESHIFT_FORM() ns.Bar:Refresh() end
function events.PLAYER_REGEN_DISABLED()
ns.inCombat = true
ns.Bar:UpdateVisibility()
end
function events.PLAYER_REGEN_ENABLED()
ns.inCombat = false
ns.Bar:UpdateVisibility()
end
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", function(_, event, ...) events[event](...) end)
---@param key string
---@param value boolean
local function Set(key, value)
ns.db[key] = value
ns.Bar:Apply()
end
local COMMANDS = {
{ "lock", "stop the bar from being dragged", function() Set("locked", true) end },
{ "unlock", "let the bar be dragged", function() Set("locked", false) end },
{ "show", "show the bar", function() Set("shown", true) end },
{ "hide", "hide the bar", function() Set("shown", false) end },
{ "reset", "move the bar back to its default position", function() ns.Bar:ResetPosition() end },
{ "scan", "rescan skills", ns.RequestScan },
}
SLASH_WHETSTONE1 = "/whet"
SLASH_WHETSTONE2 = "/whetstone"
SlashCmdList.WHETSTONE = function(input)
local cmd = strlower(strtrim(input))
if cmd == "" then return ns.Options:Open() end
for _, command in ipairs(COMMANDS) do
if command[1] == cmd then return command[3]() end
end
ns.Print("/whet opens the options.")
for _, command in ipairs(COMMANDS) do
ns.Print(("/whet %s: %s"):format(command[1], command[2]))
end
end