-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.lua
More file actions
165 lines (126 loc) · 5.86 KB
/
Copy pathDB.lua
File metadata and controls
165 lines (126 loc) · 5.86 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
local ADDON_NAME, Addon = ...
local DB = {}
Addon.DB = DB
local function NormalizeText(value, fallback)
value = Addon.util.Trim(value)
if value == "" then
return fallback
end
return value
end
local function NormalizeFontSize(value, fallback)
local numberValue = tonumber(value)
if not numberValue then
numberValue = tonumber(fallback) or Addon.CHAT_FONT_SIZE_MIN
end
numberValue = math.floor(numberValue + 0.5)
if numberValue < Addon.CHAT_FONT_SIZE_MIN then
return Addon.CHAT_FONT_SIZE_MIN
end
if numberValue > Addon.CHAT_FONT_SIZE_MAX then
return Addon.CHAT_FONT_SIZE_MAX
end
return numberValue
end
local function MigrateLegacyFields(db)
Addon.util.DeepMergeDefaults(db, Addon.DEFAULTS)
local settings = db.settings
local tabs = db.tabs
if db.enableServicesTab ~= nil then
settings.enableRetailServicesTab = Addon.util.ToBoolean(db.enableServicesTab, settings.enableRetailServicesTab)
end
if db.enableVoiceFrame ~= nil then
settings.keepRetailVoiceFrame = Addon.util.ToBoolean(db.enableVoiceFrame, settings.keepRetailVoiceFrame)
end
if db.autoJoinClassicLFG ~= nil then
local enabled = Addon.util.ToBoolean(db.autoJoinClassicLFG, settings.enableClassicLFGTab)
settings.enableClassicLFGTab = enabled
tabs.lfg.autoJoin = enabled
end
if db.setupOnLogin ~= nil then
settings.setupOnLogin = Addon.util.ToBoolean(db.setupOnLogin, settings.setupOnLogin)
end
db.enableServicesTab = nil
db.enableVoiceFrame = nil
db.autoJoinClassicLFG = nil
db.setupOnLogin = nil
end
local function NormalizeSchema(db)
Addon.util.DeepMergeDefaults(db, Addon.DEFAULTS)
db.version = Addon.SCHEMA_VERSION
db.initializedPresetVersion = tonumber(db.initializedPresetVersion) or 0
local settings = db.settings
local tabs = db.tabs
settings.setupOnLogin = Addon.util.ToBoolean(settings.setupOnLogin, Addon.DEFAULTS.settings.setupOnLogin)
settings.resetBeforeApply = Addon.util.ToBoolean(settings.resetBeforeApply, Addon.DEFAULTS.settings.resetBeforeApply)
settings.chatFontSize = NormalizeFontSize(settings.chatFontSize, Addon.DEFAULTS.settings.chatFontSize)
settings.keepRetailVoiceFrame = Addon.util.ToBoolean(settings.keepRetailVoiceFrame, Addon.DEFAULTS.settings.keepRetailVoiceFrame)
settings.enableRetailServicesTab = Addon.util.ToBoolean(settings.enableRetailServicesTab, Addon.DEFAULTS.settings.enableRetailServicesTab)
settings.enableClassicLFGTab = Addon.util.ToBoolean(settings.enableClassicLFGTab, Addon.DEFAULTS.settings.enableClassicLFGTab)
settings.classicChannelNames.lfg = NormalizeText(settings.classicChannelNames.lfg, Addon.DEFAULTS.settings.classicChannelNames.lfg)
settings.classicChannelNames.layer = NormalizeText(settings.classicChannelNames.layer, Addon.DEFAULTS.settings.classicChannelNames.layer)
tabs.general.name = NormalizeText(tabs.general.name, Addon.DEFAULTS.tabs.general.name)
tabs.log.name = NormalizeText(tabs.log.name, Addon.DEFAULTS.tabs.log.name)
tabs.lootTrade.name = NormalizeText(tabs.lootTrade.name, Addon.DEFAULTS.tabs.lootTrade.name)
tabs.services.name = NormalizeText(tabs.services.name, Addon.DEFAULTS.tabs.services.name)
tabs.lfg.name = NormalizeText(tabs.lfg.name, Addon.DEFAULTS.tabs.lfg.name)
tabs.general.enabled = Addon.util.ToBoolean(tabs.general.enabled, Addon.DEFAULTS.tabs.general.enabled)
tabs.log.enabled = Addon.util.ToBoolean(tabs.log.enabled, Addon.DEFAULTS.tabs.log.enabled)
tabs.lootTrade.enabled = Addon.util.ToBoolean(tabs.lootTrade.enabled, Addon.DEFAULTS.tabs.lootTrade.enabled)
tabs.services.enabled = Addon.util.ToBoolean(tabs.services.enabled, Addon.DEFAULTS.tabs.services.enabled)
tabs.lfg.enabled = Addon.util.ToBoolean(tabs.lfg.enabled, Addon.DEFAULTS.tabs.lfg.enabled)
tabs.lfg.autoJoin = Addon.util.ToBoolean(tabs.lfg.autoJoin, Addon.DEFAULTS.tabs.lfg.autoJoin)
tabs.lootTrade.channels = type(tabs.lootTrade.channels) == "table" and tabs.lootTrade.channels or Addon.util.DeepCopy(Addon.DEFAULTS.tabs.lootTrade.channels)
tabs.lootTrade.messageGroups = type(tabs.lootTrade.messageGroups) == "table" and tabs.lootTrade.messageGroups or Addon.util.DeepCopy(Addon.DEFAULTS.tabs.lootTrade.messageGroups)
tabs.services.channels = type(tabs.services.channels) == "table" and tabs.services.channels or Addon.util.DeepCopy(Addon.DEFAULTS.tabs.services.channels)
tabs.lfg.channels = type(tabs.lfg.channels) == "table" and tabs.lfg.channels or Addon.util.DeepCopy(Addon.DEFAULTS.tabs.lfg.channels)
end
function DB.Migrate(fromVersion)
local db = CalmChatDB
if type(db) ~= "table" then
return
end
if type(fromVersion) ~= "number" then
fromVersion = 0
end
if fromVersion < 3 then
MigrateLegacyFields(db)
end
NormalizeSchema(db)
end
function DB.Initialize()
CalmChatDB = type(CalmChatDB) == "table" and CalmChatDB or {}
local fromVersion = tonumber(CalmChatDB.version) or 0
DB.Migrate(fromVersion)
return CalmChatDB
end
function DB.Get()
return CalmChatDB
end
function DB.GetSettings()
return CalmChatDB and CalmChatDB.settings
end
function DB.GetTabs()
return CalmChatDB and CalmChatDB.tabs
end
function DB.ResetToDefaults()
CalmChatDB = Addon.util.DeepCopy(Addon.DEFAULTS)
CalmChatDB.version = Addon.SCHEMA_VERSION
CalmChatDB.initializedPresetVersion = 0
return CalmChatDB
end
function DB.GetDefaults()
return Addon.DEFAULTS
end
function DB.NormalizeText(value, fallback)
return NormalizeText(value, fallback)
end
function DB.GetInitializedPresetVersion()
return (CalmChatDB and tonumber(CalmChatDB.initializedPresetVersion)) or 0
end
function DB.SetInitializedPresetVersion(version)
if type(CalmChatDB) ~= "table" then
return
end
CalmChatDB.initializedPresetVersion = tonumber(version) or 0
end