-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.lua
More file actions
105 lines (92 loc) · 2.67 KB
/
Copy pathdb.lua
File metadata and controls
105 lines (92 loc) · 2.67 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
local A, L = ...
---------------------------------------------------------------------
-- deepMerge
---------------------------------------------------------------------
local function deepMerge(target, source)
if not source then return target end
if not target then target = {} end
for key, value in pairs(source) do
if type(value) == "table" then
if type(target[key]) ~= "table" then
target[key] = {}
end
deepMerge(target[key], value)
else
target[key] = value
end
end
return target
end
---------------------------------------------------------------------
-- LoadDBDefaults
---------------------------------------------------------------------
local function LoadDBDefaults()
return {
settings = {
modules = {
chat = {
enabled = true,
},
darkmode = {
enabled = true,
},
spellalert = {
enabled = true,
},
statedriver = {
enabled = true,
},
tooltip = {
enabled = true,
},
vignette = {
enabled = true,
},
},
},
["DB_VERSION"] = 2,
}
end
---------------------------------------------------------------------
-- DB_UPDATE
---------------------------------------------------------------------
local DB_UPDATE = {}
---------------------------------------------------------------------
-- LoadDBUpdates
---------------------------------------------------------------------
--check if a db-update is required in the local db
--if there is no new version do nothing
local function LoadDBUpdates()
--test for new version + 1
local newVersion = L.DB["DB_VERSION"] + 1
for i = newVersion, L.dbversion do
L.DB = deepMerge(L.DB, DB_UPDATE[i])
print(L.name, L.version, "updating local db to version", i)
end
L.DB["DB_VERSION"] = L.dbversion
end
---------------------------------------------------------------------
-- InitDB
---------------------------------------------------------------------
local function InitDB()
rLayout_DB = rLayout_DB or LoadDBDefaults()
local resetDB = false
if not rLayout_DB["DB_VERSION"] or rLayout_DB["DB_VERSION"] < 2 then
resetDB = true
end
if resetDB == true then
rLayout_DB = LoadDBDefaults()
print(L.name, "error in db structure found, reloading db defaults")
end
L.DB = rLayout_DB
end
---------------------------------------------------------------------
-- LoadDB
---------------------------------------------------------------------
local function LoadDB()
InitDB()
LoadDBUpdates()
print(L.name, L.version, "loading db version", L.DB["DB_VERSION"])
end
L.F.LoadDB = LoadDB
L.DB_DEFAULTS = LoadDBDefaults()