Repository navigation
Expand file tree
/
Copy pathDatabase.lua
More file actions
174 lines (147 loc) · 4.48 KB
/
Copy pathDatabase.lua
File metadata and controls
174 lines (147 loc) · 4.48 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
local _, ns = ...
local CURRENT_SCHEMA_VERSION = 3
local POSITION_LIMIT = 10000
local MINIMUM_DISPLAY_TIME_MIN = 2
local MINIMUM_DISPLAY_TIME_MAX = 20
local MAXIMUM_VISIBLE_TOOLTIPS_MIN = 1
local MAXIMUM_VISIBLE_TOOLTIPS_MAX = 8
local PARTY_DEBUFF_MAX_PER_MEMBER_MIN = 1
local PARTY_DEBUFF_MAX_PER_MEMBER_MAX = 3
local PARTY_DEBUFF_SCALE_MIN = 75
local PARTY_DEBUFF_SCALE_MAX = 125
local defaults = {
schemaVersion = CURRENT_SCHEMA_VERSION,
enabled = true,
trackTarget = true,
trackFocus = true,
trackBosses = true,
trackNameplates = true,
minimumDisplayTime = 20,
maximumVisibleTooltips = 5,
showTargetAbilities = true,
showPartyDebuffs = true,
partyDebuffMaxPerMember = 2,
partyDebuffScale = 90,
position = {
x = 300,
y = 120,
},
partyDebuffPosition = {
x = -330,
y = 90,
},
}
ns.Defaults = defaults
local function IsFiniteNumber(value)
return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
end
local function ClampInteger(value, fallback, minimum, maximum)
if not IsFiniteNumber(value) then
return fallback
end
return Clamp(math.floor(value + 0.5), minimum, maximum)
end
local function ClampPosition(value, fallback)
if not IsFiniteNumber(value) then
return fallback
end
return Clamp(value, -POSITION_LIMIT, POSITION_LIMIT)
end
local function ValidateBoolean(db, key)
if type(db[key]) ~= "boolean" then
db[key] = defaults[key]
end
end
function ns.InitializeDatabase()
local db = SpellTipsDB
if type(db) ~= "table" and type(AbilityTooltipDB) == "table" then
db = AbilityTooltipDB
end
if type(db) ~= "table" then
db = {}
end
SpellTipsDB = db
AbilityTooltipDB = nil
if not IsFiniteNumber(db.schemaVersion) then
db.schemaVersion = 0
end
ValidateBoolean(db, "enabled")
ValidateBoolean(db, "trackTarget")
ValidateBoolean(db, "trackFocus")
ValidateBoolean(db, "trackBosses")
ValidateBoolean(db, "trackNameplates")
ValidateBoolean(db, "showTargetAbilities")
ValidateBoolean(db, "showPartyDebuffs")
db.minimumDisplayTime = ClampInteger(
db.minimumDisplayTime,
defaults.minimumDisplayTime,
MINIMUM_DISPLAY_TIME_MIN,
MINIMUM_DISPLAY_TIME_MAX
)
db.maximumVisibleTooltips = ClampInteger(
db.maximumVisibleTooltips,
defaults.maximumVisibleTooltips,
MAXIMUM_VISIBLE_TOOLTIPS_MIN,
MAXIMUM_VISIBLE_TOOLTIPS_MAX
)
db.partyDebuffMaxPerMember = ClampInteger(
db.partyDebuffMaxPerMember,
defaults.partyDebuffMaxPerMember,
PARTY_DEBUFF_MAX_PER_MEMBER_MIN,
PARTY_DEBUFF_MAX_PER_MEMBER_MAX
)
db.partyDebuffScale = ClampInteger(
db.partyDebuffScale,
defaults.partyDebuffScale,
PARTY_DEBUFF_SCALE_MIN,
PARTY_DEBUFF_SCALE_MAX
)
if type(db.position) ~= "table" then
db.position = {}
end
db.position.x = ClampPosition(db.position.x, defaults.position.x)
db.position.y = ClampPosition(db.position.y, defaults.position.y)
if type(db.partyDebuffPosition) ~= "table" then
db.partyDebuffPosition = {}
end
db.partyDebuffPosition.x = ClampPosition(
db.partyDebuffPosition.x,
defaults.partyDebuffPosition.x
)
db.partyDebuffPosition.y = ClampPosition(
db.partyDebuffPosition.y,
defaults.partyDebuffPosition.y
)
if db.schemaVersion < CURRENT_SCHEMA_VERSION then
db.schemaVersion = CURRENT_SCHEMA_VERSION
end
ns.db = db
end
function ns.GetDatabase()
return ns.db
end
function ns.SetSavedPosition(x, y)
local db = ns.GetDatabase()
db.position.x = ClampPosition(x, defaults.position.x)
db.position.y = ClampPosition(y, defaults.position.y)
end
function ns.ResetSavedPosition()
ns.SetSavedPosition(defaults.position.x, defaults.position.y)
if ns.ApplyAnchorPosition then
ns.ApplyAnchorPosition()
end
end
function ns.SetPartyDebuffSavedPosition(x, y)
local db = ns.GetDatabase()
db.partyDebuffPosition.x = ClampPosition(x, defaults.partyDebuffPosition.x)
db.partyDebuffPosition.y = ClampPosition(y, defaults.partyDebuffPosition.y)
end
function ns.ResetPartyDebuffSavedPosition()
ns.SetPartyDebuffSavedPosition(
defaults.partyDebuffPosition.x,
defaults.partyDebuffPosition.y
)
if ns.ApplyPartyDebuffAnchorPosition then
ns.ApplyPartyDebuffAnchorPosition()
end
end