-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathChoreTracker.lua
217 lines (187 loc) · 6.47 KB
/
ChoreTracker.lua
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
local addonName, addonTable = ...
local Addon = LibStub('AceAddon-3.0'):NewAddon(addonTable, addonName, 'AceConsole-3.0', 'AceEvent-3.0')
Addon:SetDefaultModuleLibraries('AceBucket-3.0', 'AceEvent-3.0')
Addon.data = {
chores = {},
delves = {},
timers = {},
}
Addon.L = LibStub('AceLocale-3.0'):GetLocale(addonName)
local ADB = LibStub('AceDB-3.0')
local LSM = LibStub('LibSharedMedia-3.0')
local DEFAULT_SECTION_ORDER = {
'timers',
'anniversary',
'events',
'hallowfallFishingDerby',
'delves',
'warWithin',
'professions',
'pvp',
'dragonflight',
}
local defaultDb = {
char = {
skillLines = {},
},
global = {
questWeeks = {},
},
profile = {
modules = {
['**'] = {
enabled = true,
}
},
general = {
appearance = {
backgroundColor = { r = 0, g = 0, b = 0, a = 0.7 },
borderColor = { r = 63 / 255, g = 63 / 255, b = 63 / 255, a = 0.7 },
strata = 'LOW',
},
automation = {
acceptQuests = false,
},
display = {
awakenedTimers = false,
showAnniversaryAccount = false,
showCompleted = false,
showCompletedSections = true,
showObjectives = 'ALL',
statusIcons = true,
},
order = {
sections = DEFAULT_SECTION_ORDER,
},
text = {
font = LSM:GetDefault('font'),
fontSize = 12,
fontStyle = '',
},
},
delves = {
bountiful = {
onlyWithKeys = false,
showDelves = true,
showKeys = true,
},
},
window = {
height = nil,
width = nil,
left = nil,
top = nil,
locked = false,
minimized = false,
},
desiredShown = true,
seenAutoAcceptMessage = false,
chores = {},
timers = {},
}
}
function Addon:OnInitialize()
for sectionKey, sectionData in pairs(self.data.chores) do
defaultDb.profile.chores[sectionKey] = {}
for _, catData in ipairs(sectionData.categories or {}) do
defaultDb.profile.chores[sectionKey][catData.key] = {}
local defaultEnabled = sectionData.defaultEnabled ~= false and
catData.defaultEnabled ~= false
if catData.drops ~= nil then
local drops = {}
for _, dropData in ipairs(catData.drops) do
drops[dropData.key] = dropData.defaultEnabled ~= false and defaultEnabled
end
defaultDb.profile.chores[sectionKey][catData.key].drops = drops
end
if catData.dungeons ~= nil then
local dungeons = {}
for _, dungeonData in ipairs(catData.dungeons) do
dungeons[dungeonData.key] = dungeonData.defaultEnabled ~= false and defaultEnabled
end
defaultDb.profile.chores[sectionKey][catData.key].dungeons = dungeons
end
if catData.quests ~= nil then
local quests = {}
for _, questData in ipairs(catData.quests) do
if quests[questData.key] == nil then
quests[questData.key] = questData.defaultEnabled ~= false and defaultEnabled
end
end
defaultDb.profile.chores[sectionKey][catData.key].quests = quests
end
end
end
for _, category in pairs(self.data.timers) do
defaultDb.profile.timers[category.key] = {}
for _, timer in ipairs(category.timers) do
defaultDb.profile.timers[category.key][timer.key] = category.key == 'warWithin'
end
end
-- DevTools_Dump(defaultDb)
self:RegisterChatCommand('chores', 'SlashCommand')
self:RegisterChatCommand('choretracker', 'SlashCommand')
self.db = ADB:New('ChoreTrackerDB', defaultDb, true) -- default global profile
-- Fix section order
local ughSections = {}
local seenSections = {}
for _, section in ipairs(self.db.profile.general.order.sections) do
if section ~= nil and not seenSections[section] then
seenSections[section] = true
tinsert(ughSections, section)
end
end
for _, section in ipairs(DEFAULT_SECTION_ORDER) do
if not seenSections[section] then
tinsert(ughSections, 1, section)
end
end
self.db.profile.general.order.sections = ughSections
-- Clean up old weekly data
local cutoff = time() - (14 * 24 * 60 * 60)
for weekEnd, _ in pairs(self.db.global.questWeeks) do
if weekEnd < cutoff then
self.db.global.questWeeks[weekEnd] = nil
end
end
-- register events, etc
self:RegisterEvent('PLAYER_ENTERING_WORLD')
end
function Addon:PLAYER_ENTERING_WORLD()
for _, module in Addon:IterateModules() do
if module.OnEnteringWorld ~= nil then
module:OnEnteringWorld()
end
end
if not Addon.db.global.seenAutoAcceptMessage then
C_Timer.After(5, function() print(Addon.L['auto_accept_message']) end)
Addon.db.global.seenAutoAcceptMessage = true
end
end
function Addon:TableKeys(tbl)
local keys = {}
for key in pairs(tbl) do
keys[#keys + 1] = key
end
return keys
end
function Addon:SlashCommand(command, editbox)
if command == 'show' then
local displayModule = self:GetModule('Display')
displayModule:SetDesiredShown(true)
elseif command == 'hide' then
local displayModule = self:GetModule('Display')
displayModule:SetDesiredShown(false)
elseif command == 'toggle' then
local displayModule = self:GetModule('Display')
displayModule:ToggleShown(true)
elseif command == '' or command == nil then
Settings.OpenToCategory(addonName)
else
print('ChoreTracker: unknown command')
print()
print(' hide: hide the window')
print(' show: show the window')
print(' toggle: toggle the window')
end
end