-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathChoreTracker.lua
More file actions
288 lines (250 loc) · 8.15 KB
/
ChoreTracker.lua
File metadata and controls
288 lines (250 loc) · 8.15 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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
local addonName, addonTable = ...
local Addon = LibStub('AceAddon-3.0'):NewAddon(
addonTable,
addonName,
'AceBucket-3.0',
'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 LDB = LibStub('LibDataBroker-1.1')
local DBIcon = LibStub('LibDBIcon-1.0')
local DEFAULT_SECTION_ORDER = {
'timers',
'anniversary',
'events',
'hallowfallFishingDerby',
'delves',
'midnight',
'warWithin',
'professions',
'pvp',
'dragonflight',
}
local defaultDb = {
char = {
skillLines = {},
},
global = {
questWeeks = {},
},
profile = {
modules = {
['**'] = {
enabled = true,
}
},
minimap = {
hide = false,
},
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:ToggleMinimapIcon(show)
if show then
DBIcon:Show(addonName)
else
DBIcon:Hide(addonName)
end
end
-- LibDataBroker plugin
local CT_LDB = LDB:NewDataObject(addonName, {
type = "data source",
text = "?/?",
icon = "Interface\\AddOns\\ChoreTracker\\Assets\\icon.tga",
OnTooltipShow = function(tooltip)
tooltip:SetText("ChoreTracker")
tooltip:AddLine(Addon.L['tooltip:toggleWindow'], 1, 1, 1)
tooltip:AddLine(Addon.L['tooltip:showOptions'], 1, 1, 1)
tooltip:Show()
end,
OnClick = function(_, button)
if(button=="LeftButton")then
Addon:GetModule('Display'):ToggleShown(true)
else
Addon:OpenSettings()
end
end,
})
function Addon:UpdateLdb()
local completed = 0
local total = 0
local displayModule = Addon:GetModule('Display')
local sections = displayModule:GetSections()
for _, section in ipairs(sections) do
completed = completed + section.completed
total = total + section.total
end
local prefix = displayModule:GetPercentColor(completed, total)
CT_LDB.text = prefix .. completed ..'|r|cFF888888/|r' .. prefix .. total .. '|r'
end
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')
-- register minimap icon
DBIcon:Register(addonName, CT_LDB, self.db.profile.minimap)
-- update LDB data
self:RegisterBucketMessage({ 'ChoreTracker_Data_Updated' }, 2, 'UpdateLdb')
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:OpenSettings()
Settings.OpenToCategory(Addon:GetModule('Options').optionsCategory)
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 == 'accept' then
local autoAcceptModule = self:GetModule('AutoAccept')
autoAcceptModule:ScanJournal()
elseif command == '' or command == nil then
Addon:OpenSettings()
else
print('ChoreTracker: unknown command')
print()
print(' hide: hide the window')
print(' show: show the window')
print(' toggle: toggle the window')
end
end
function ChoreTracker_OnAddonCompartmentClick()
Addon:SlashCommand('toggle', _)
end