-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathGridDefaults.lua
More file actions
238 lines (223 loc) · 7.19 KB
/
GridDefaults.lua
File metadata and controls
238 lines (223 loc) · 7.19 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
--[[
Created by Michael, based on Grid2Options\GridDefaults.lua from original Grid2 authors
--]]
local Grid2 = Grid2
-- Latest database profile version
local DB_VERSION = 102
-- Database manipulation functions
function Grid2:DbSetStatusDefaultValue(name, value)
self.defaults.profile.statuses[name] = value
if self.db then -- if acedb was already created, copy by hand the defaults to the current profile
local statuses = self.db.profile.statuses
statuses[name] = Grid2.CopyTable( value, statuses[name] )
end
end
function Grid2:DbUpdateStatusesDefaults()
local defaults = self.defaults.profile.statuses
for k,v in pairs(self.db.profile.statuses) do
local d = defaults[k]
if d then Grid2.CopyTable( d, v ) end
end
end
function Grid2:DbSetValue(section, name, value)
self.db.profile[section][name]= value
end
function Grid2:DbGetValue(section, name)
return self.db.profile[section][name]
end;
function Grid2:DbGetIndicator(name)
return self.db.profile.indicators[name]
end
function Grid2:DbSetIndicator(name, value)
if value==nil then
local map = Grid2.db.profile.statusMap
if map[name] then map[name]= nil end
end
self.db.profile.indicators[name]= value
end
function Grid2:DbSetMap(indicatorName, statusName, priority)
local map = self.db.profile.statusMap
if priority then
if not map[indicatorName] then
map[indicatorName] = {}
end
map[indicatorName][statusName] = priority
else
if map[indicatorName] and map[indicatorName][statusName] then
map[indicatorName][statusName] = nil
end
end
end
-- Register new database profile defaults
-- info.name = profile name
-- info.desc = profile description
-- info.image = example image
-- info.update = function that must store profile settings in a new created profile.
-- params:
-- index = nil|0 0 => registering the default profile for Grid2
function Grid2:DbRegisterProfile(info, index)
if not index or self.defaultProfiles[index] then
index = #self.defaultProfiles+1
end
self.defaultProfiles[index] = info
end
function Grid2:DbGetRegisteredProfileByName(name)
if name then
for index,info in pairs(self.defaultProfiles) do
if name == info.name then
return info, index
end
end
end
end
if Grid2.isMidnight then
function Grid2:MakeDatabaseDefaults()
local defaultProfile = self.defaultProfileIndex
self.defaultProfileIndex = nil
if not defaultProfile and (Grid2Options or C_AddOns.LoadAddOn('Grid2Options')) then
Grid2Options:OpenFirstBootProfilesDialog()
return false
else
local info = self.defaultProfiles[defaultProfile or 0]
info.func(self, info)
return true
end
end
else
function Grid2:MakeDatabaseDefaults()
self:MakeDefaultsCommon()
self:MakeDefaultsClass()
return true
end
end
-- Plugins can hook this function to initialize or update values in database
function Grid2:UpdateDefaults()
local version = Grid2:DbGetValue("versions","Grid2") or 0
if version>=DB_VERSION then return end
if version==0 then
if not self:MakeDatabaseDefaults() then
return -- first boot dialog
end
else
local health = Grid2:DbGetValue("indicators", "health")
local heals = Grid2:DbGetValue("indicators", "heals")
if version<2 then
-- Upgrade health&heals indicator to version 2
if health and heals then heals.parentBar = "health" end
end
if version<4 then
-- Upgrade health&heals indicator to version 4
if heals and heals.parentBar then
heals.anchorTo = heals.parentBar
heals.parentBar = nil
end
if health and health.childBar then
health.childBar = nil
end
end
if version<5 then
-- Upgrade buffs and debuffs groups statuses
for _, status in pairs(self.db.profile.statuses) do
if status.auras and (status.type == "buff" or status.type=="debuff") then
status.type = status.type .. "s" -- Convert type: buff -> buffs , debuff -> debuffs
if status.type == "debuffs" then
status.useWhiteList = true
end
end
end
end
if version<6 then
Grid2:DbSetValue( "indicators", "tooltip", {type = "tooltip", displayUnitOOC = true} )
end
if version<7 then
Grid2:DbSetValue( "indicators", "background", {type = "background"})
end
if version<8 then
-- upgrade multibars
for _,dbx in pairs(self.db.profile.indicators) do
if dbx.type=='multibar' then
local opacity = math.min(dbx.opacity or 1, dbx.invertColor and 0.8 or 1)
dbx.textureColor = dbx.textureColor or {}
dbx.textureColor.a = math.min( dbx.textureColor.a or 1, opacity )
dbx.backColor = dbx.backColor or (dbx.invertColor and {r=0,g=0,b=0,a=1}) -- now invert color needs a background color&texture
dbx.backAnchor = dbx.backColor and (dbx.backMainAnchor and 1 or 2) -- change background anchor codes, now nil means fills the whole background
for i=1,(dbx.barCount or 0) do
local bar = dbx['bar'..i] or {}
bar.color = bar.color or {}
bar.color.a = math.min( opacity, bar.color.a or 1 )
dbx[i], dbx['bar'..i] = bar, nil
end
dbx.barCount, dbx.opacity, dbx.backMainAnchor = nil, nil, nil
end
end
end
if version<9 then
-- upgrade class filter
for _,dbx in pairs(self.db.profile.statuses) do
if dbx.playerClass then
dbx.load = { playerClass = { [dbx.playerClass] = true } }
dbx.playerClass = nil
end
end
end
if version<10 then
-- move some Grid2Layout options from global section to profile section
local dbx = Grid2Layout.dba.global
local val = (dbx.detachHeaders and 'player') or (dbx.detachPetHeaders and 'pet') or nil
if val or dbx.displayAllGroups then
local dba = Grid2Layout.dba.profile
for theme in Grid2.IterateValues(dba, unpack(dba.extraThemes or {}) ) do
theme.detachedHeaders = val
theme.displayAllGroups = dbx.displayAllGroups
end
dbx.detachHeaders = nil
dbx.detachPetHeaders = nil
end
end
if version<11 then
local threat = self.db.profile.statuses.threat
threat.blinkThreshold = not threat.disableBlink
threat.disableBlink = nil
end
if version<12 then
local dbx = self.db.profile.statuses.mana
if dbx.showOnlyHealers then
dbx.load = dbx.load or {}
dbx.load.unitRole = { HEALER = true }
dbx.showOnlyHealers = nil
end
end
if version<13 and self.db.profile.formatting.percentFormat==nil then
self.db.profile.formatting.percentFormat = self.defaults.profile.formatting.percentFormat
end
if version<14 and self.db.profile.hideBlizzardRaidFrames then
local dbx = self.db.profile
local hid = dbx.hideBlizzardRaidFrames
if hid then
dbx.hideBlizzardRaidFrames = nil
dbx.hideBlizzard = dbx.hideBlizzard or {}
dbx.hideBlizzard.raid = (hid==true or hid==2) or nil
dbx.hideBlizzard.party = (hid==true or hid==1) or nil
end
end
if version<101 then -- fix privateauras indicators (GH issue #366)
for _,dbx in pairs(self.db.profile.indicators) do
if dbx.type=='privateauras' then
dbx.load = nil
end
end
end
if version<102 then -- removed posible old anchoring for single bar indicators
for _,dbx in pairs(self.db.profile.indicators) do
if dbx.type=='bar' then
dbx.anchorTo = nil
end
end
end
if DB_VERSION>=100 and version<100 then
Grid2:DbSetValue("versions","Grid2Prev",version)
end
end
-- Set database version
Grid2:DbSetValue("versions","Grid2",DB_VERSION)
end