-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathState.lua
More file actions
155 lines (133 loc) · 3.67 KB
/
Copy pathState.lua
File metadata and controls
155 lines (133 loc) · 3.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
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
local _, VoxGM = ...
local State = VoxGM.State
local C = nil -- set during Init (Constants loads before us)
local DEFAULTS = {
schemaVersion = 1,
ui = {
x = nil,
y = nil,
selectedTab = "GM",
minimapAngle = 225,
minimapHidden = false,
},
lastUsed = {
speed = 6,
scale = 1,
wmorph = "",
wscale = "",
morph = "",
settime = "12",
npcEntry = "",
npcFaction = "",
npcAura = "",
npcScale = "",
},
favorites = {},
history = {},
}
function State:Init()
C = VoxGM.C
if not VoxGMDB then
VoxGMDB = VoxGM.Util:DeepCopy(DEFAULTS)
return
end
self:Migrate()
end
function State:Migrate()
local db = VoxGMDB
-- Type coercion: if top-level keys are wrong type, reset them
if type(db) ~= "table" then
VoxGMDB = VoxGM.Util:DeepCopy(DEFAULTS)
return
end
if type(db.ui) ~= "table" then db.ui = VoxGM.Util:DeepCopy(DEFAULTS.ui) end
if type(db.lastUsed) ~= "table" then db.lastUsed = VoxGM.Util:DeepCopy(DEFAULTS.lastUsed) end
if type(db.history) ~= "table" then db.history = {} end
if type(db.favorites) ~= "table" then db.favorites = {} end
-- Always backfill missing keys from DEFAULTS (future-proof for new keys)
for k, v in pairs(DEFAULTS) do
if db[k] == nil then
db[k] = VoxGM.Util:DeepCopy(v)
end
end
for k, v in pairs(DEFAULTS.ui) do
if db.ui[k] == nil then db.ui[k] = v end
end
for k, v in pairs(DEFAULTS.lastUsed) do
if db.lastUsed[k] == nil then db.lastUsed[k] = v end
end
local ver = db.schemaVersion or 0
if ver < 1 then
db.schemaVersion = 1
end
-- Future version-specific migrations go here:
-- if ver < 2 then ... db.schemaVersion = 2 end
-- Prune invalid history entries (structural validation + cap)
local cap = C and C.HISTORY_CAP or 100
local cleanHistory = {}
for _, entry in ipairs(db.history) do
if type(entry) == "table" and type(entry.cmd) == "string" then
table.insert(cleanHistory, entry)
if #cleanHistory >= cap then break end
end
end
db.history = cleanHistory
-- Prune invalid favorites (structural validation)
local cleanFavs = {}
for _, fav in ipairs(db.favorites) do
if type(fav) == "table" and fav.label and fav.payload then
table.insert(cleanFavs, fav)
end
end
db.favorites = cleanFavs
end
function State:Get(key)
return VoxGMDB and VoxGMDB[key]
end
function State:Set(key, value)
if VoxGMDB then
VoxGMDB[key] = value
end
end
function State:GetUI(key)
return VoxGMDB and VoxGMDB.ui and VoxGMDB.ui[key]
end
function State:SetUI(key, value)
if VoxGMDB and VoxGMDB.ui then
VoxGMDB.ui[key] = value
end
end
function State:GetLastUsed(key)
return VoxGMDB and VoxGMDB.lastUsed and VoxGMDB.lastUsed[key]
end
function State:SetLastUsed(key, value)
if VoxGMDB and VoxGMDB.lastUsed then
VoxGMDB.lastUsed[key] = value
end
end
function State:ResetPosition()
if VoxGMDB and VoxGMDB.ui then
VoxGMDB.ui.x = nil
VoxGMDB.ui.y = nil
end
if VoxGM.UI.mainFrame then
VoxGM.UI.mainFrame:ClearAllPoints()
VoxGM.UI.mainFrame:SetPoint("CENTER")
end
end
-- Session-only state (not persisted)
State.session = {
flyOn = false,
gmOn = false,
gmVisible = false,
godMode = false,
stealthOn = false,
typingOn = false,
combatLogOn = false,
ranMaxrep = false,
ranMaxtitles = false,
ranMaxachieve = false,
ranProfs = false,
ranGoldPackage = false,
phaseId = nil,
}