forked from ThingEngineering/choretracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChoreTracker.lua
146 lines (123 loc) · 4.38 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
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 = {},
}
Addon.L = LibStub('AceLocale-3.0'):GetLocale(addonName)
local ADB = LibStub('AceDB-3.0')
local LSM = LibStub('LibSharedMedia-3.0')
local defaultDb = {
global = {
questWeeks = {},
},
profile = {
modules = {
['**'] = {
enabled = true,
}
},
general = {
display = {
showCompleted = false,
statusIcons = true,
},
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',
},
text = {
font = LSM:GetDefault('font'),
fontSize = 12,
fontStyle = '',
}
},
window = {
height = nil,
width = nil,
left = nil,
top = nil,
locked = false,
minimized = false,
},
desiredShown = true,
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] = {}
if catData.drops ~= nil then
local drops = {}
for _, dropData in ipairs(catData.drops) do
drops[dropData.key] = dropData.defaultEnabled ~= false
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
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
end
end
defaultDb.profile.chores[sectionKey][catData.key].quests = quests
end
end
end
for _, timer in ipairs(self.data.timers) do
defaultDb.profile.timers[timer.key] = true
end
-- DevTools_Dump(defaultDb)
self:RegisterChatCommand('chores', 'SlashCommand')
self:RegisterChatCommand('choretracker', 'SlashCommand')
self.db = ADB:New("ChoreTrackerDB", defaultDb, true) -- default global profile
-- 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
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
local optionsModule = self:GetModule('Options')
InterfaceOptionsFrame_OpenToCategory(optionsModule.optionsFrame)
else
print('ChoreTracker: unknown command')
print()
print(' hide: hide the window')
print(' show: show the window')
print(' toggle: toggle the window')
end
end