-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinit.lua
More file actions
102 lines (82 loc) · 2.39 KB
/
init.lua
File metadata and controls
102 lines (82 loc) · 2.39 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
-- SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
-- Copyright (c) 2022-2026 Thomas Floeren
local _, ns = ...
--[[===========================================================================
Defaults
===========================================================================]]--
local function merge_defaults(src, dst)
for k, v in pairs(src) do
local src_type = type(v)
if src_type == 'table' then
if type(dst[k]) ~= 'table' then dst[k] = {} end
merge_defaults(v, dst[k])
elseif type(dst[k]) ~= src_type then
dst[k] = v
end
end
end
-- 1/2: v2.6, Nov 2025: currentPet/previousPet --> recentPets ==> reset specific
local DB_VERSION_CURRENT = 2.0
local defaults_global = {
dbVersion = DB_VERSION_CURRENT,
autoEnabled = true,
newPetTimer = 720,
remainingTimer = 360,
favsOnly = false,
verbosityLevel = 3,
drSummoning = true,
numRecents = 4,
recentPets = {},
eventAlt = nil,
debugMode = false,
}
local defaults_perchar = {
charFavsEnabled = false,
charFavs = {},
recentPets = {},
}
if type(_G.PetWalkerDB) ~= 'table' then
_G.PetWalkerDB = {}
end
if type(_G.PetWalkerPerCharDB) ~= 'table' then
_G.PetWalkerPerCharDB = {}
end
merge_defaults(defaults_global, _G.PetWalkerDB)
merge_defaults(defaults_perchar, _G.PetWalkerPerCharDB)
local db, dbc = _G.PetWalkerDB, _G.PetWalkerPerCharDB
ns.db, ns.dbc = db, dbc
--[[----------------------------------------------------------------------------
DB Update
----------------------------------------------------------------------------]]--
local protected_tables = {
recentPets = true,
charFavs = true,
}
-- Reverse nil cleanup
local function clean_removed(trg, ref)
for k, v in pairs(trg) do
if ref[k] == nil then
trg[k] = nil
elseif not protected_tables[k] and type(v) == 'table' then
clean_removed(v, ref[k])
end
end
end
local function update_db()
local ver = db.dbVersion or 0
if ver == DB_VERSION_CURRENT then return end
-- Do the migration in ascending order, in case we have historically overlapping changes!
-- if ver < 2 then
-- end
-- if ver < 3 then
-- end
clean_removed(db, defaults_global)
clean_removed(dbc, defaults_perchar)
db.dbVersion = DB_VERSION_CURRENT
ns.db_updated = true
end
update_db()
--[[===========================================================================
Some variables and early stuff
===========================================================================]]--
-- nothing here