Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
123 lines (112 loc) · 3.85 KB
/
Copy pathCore.lua
File metadata and controls
123 lines (112 loc) · 3.85 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
-- Wick's Wardrobe
-- Core.lua: namespace, saved variables, event dispatch, slash command.
local ADDON, ns = ...
-- TBC Anniversary 2.5.5 namespaced API shims
ns.IsAddOnLoaded = (C_AddOns and C_AddOns.IsAddOnLoaded) or IsAddOnLoaded
ns.GetAddOnMetadata = (C_AddOns and C_AddOns.GetAddOnMetadata) or GetAddOnMetadata
-- ============================================================
-- Saved variables
-- ============================================================
WicksWardrobeDB = WicksWardrobeDB or {}
local DB_DEFAULTS = {
ui = {
hidden = true,
width = 620,
height = 480,
},
pos = { posPoint = false, posRel = false, posX = 0, posY = 0 },
minimap = {
hide = false,
position = 225,
},
lastClass = nil,
lastSetIdx = nil,
outfits = {}, -- saved named outfits: { name=string, items={slot=itemLink} }
}
local function applyDefaults(target, defaults)
for k, v in pairs(defaults) do
if type(v) == "table" then
if type(target[k]) ~= "table" then target[k] = {} end
applyDefaults(target[k], v)
elseif target[k] == nil then
target[k] = v
end
end
end
-- ============================================================
-- Namespace / global
-- ============================================================
WicksWardrobe = WicksWardrobe or {}
local WW = WicksWardrobe
ns.WW = WW
WW.ADDON = ADDON
WW.db = WicksWardrobeDB -- placeholder; rebound on ADDON_LOADED
-- Internal pub/sub
WW._listeners = {}
function WW:On(event, fn)
self._listeners[event] = self._listeners[event] or {}
table.insert(self._listeners[event], fn)
end
function WW:Emit(event, ...)
local list = self._listeners[event]
if not list then return end
for _, fn in ipairs(list) do
local ok, err = pcall(fn, ...)
if not ok then
print(("|cff4FC778Wick's Wardrobe|r error in %s: %s"):format(event, tostring(err)))
end
end
end
-- ============================================================
-- WoW event frame
-- ============================================================
local f = CreateFrame("Frame")
WW.eventFrame = f
local EVENTS = {
"ADDON_LOADED",
"PLAYER_LOGIN",
"PLAYER_LOGOUT",
}
for _, e in ipairs(EVENTS) do
pcall(f.RegisterEvent, f, e)
end
f:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
local arg1 = ...
if arg1 == ADDON then
WicksWardrobeDB = WicksWardrobeDB or {}
applyDefaults(WicksWardrobeDB, DB_DEFAULTS)
WW.db = WicksWardrobeDB
end
elseif event == "PLAYER_LOGIN" then
WW:Emit("LOGIN")
print("|cff4FC778Wick's Wardrobe|r loaded. /wwd to toggle.")
elseif event == "PLAYER_LOGOUT" then
if WW.UI and WW.UI.SnapPosition then WW.UI:SnapPosition() end
end
WW:Emit(event, ...)
end)
-- ============================================================
-- Slash command
-- ============================================================
SLASH_WICKSWARDROBE1 = "/wwd"
SLASH_WICKSWARDROBE2 = "/wardrobe"
SlashCmdList.WICKSWARDROBE = function(input)
input = (input or ""):gsub("^%s*(.-)%s*$", "%1"):lower()
if input == "" or input == "toggle" then
if WW.UI and WW.UI.Toggle then WW.UI:Toggle() end
return
end
if input == "show" and WW.UI then WW.UI:Show() return end
if input == "hide" and WW.UI then WW.UI:Hide() return end
if input == "reset" and WW.UI then WW.UI:Reset() return end
if input == "help" or input == "?" then
print("|cff4FC778Wick's Wardrobe|r")
print(" /wwd toggle the panel")
print(" /wwd show open")
print(" /wwd hide close")
print(" /wwd reset reset position and size")
return
end
print("|cff4FC778Wick's Wardrobe|r: unknown command. Try /wwd help")
end