forked from michaelnpsp/Grid2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridDefaults.lua
146 lines (135 loc) · 4.56 KB
/
GridDefaults.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
--[[
Created by Michael, based on Grid2Options\GridDefaults.lua from original Grid2 authors
--]]
local Grid2 = Grid2
-- Latest database profile version
local DB_VERSION = 11
-- 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: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
-- 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
self:MakeDefaultsCommon()
self:MakeDefaultsClass()
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
end
-- Set database version
Grid2:DbSetValue("versions","Grid2",DB_VERSION)
end