Unify SavedVariables into two clean roots with one-time migration

Collapse all legacy/scattered SavedVariables from absorbed standalone
addons (FeedOMatic, ZHunter/zButtons, SmartAmmo, AutoQuest, AntiDaze,
AutoStrip, MinimapButton) into two persisted globals with clean per-module
nesting under .modules.<id>.

Migration engine (api/savedvariables.lua):
- MTH_SV_EnsureSchema() with schemaVersion gate, idempotent + non-destructive
- Per-module migrators map old locations -> canonical nested stores
- Driven by an ADDON_LOADED("MetaHunt") handler so it runs only AFTER WoW
  loads the real SavedVariables (fixes announce-every-session bug that ran
  the migration on empty pre-load defaults)
- One-time player-facing chat announce, gated on real legacy data present

Framework/config:
- core-framework InitSavedVariables no longer runs migration at file-load;
  unconditionally strips account-root module aliases
- config.lua stops re-creating root[module] aliases (was duplicating data
  onto disk); canonical store stays under .modules.<id>

Modules:
- feedomatic: bind FOM_* globals as runtime aliases into nested store,
  drop persisted duplicates and .legacy blob
- zhunter: ZHunterMod_Saved re-pointed at .modules.zhunter
- smartammo/autoquest/antidaze/autostrip/minimapbutton read nested store

TOC trimmed to MTH_SavedVariables + MTH_CharSavedVariables only.
Profiles unchanged (already snapshot/apply the nested .modules structure).

Also includes pet-scan refinements: canonical pet key derivation and
level-independent pet signature (schema v3).
This commit is contained in:
DuvelCorp
2026-09-09 22:52:48 +02:00
parent de6621f41f
commit 060fc555fe
22 changed files with 855 additions and 503 deletions
+19 -95
View File
@@ -8,8 +8,6 @@ local MTH_FeedOMatic = {
enabled = false,
events = {
"VARIABLES_LOADED",
"MERCHANT_SHOW",
"MERCHANT_UPDATE",
"MTH_PET_LIVE_STATE_CHANGED",
"PET_ATTACK_START",
"PET_ATTACK_STOP",
@@ -31,7 +29,6 @@ local MTH_FeedOMatic = {
}
local MTH_PETL_HOOK_BOUNDARY_KEY = "pet-lifecycle-hooks"
local MTH_FOM_MerchantProbe = nil
function MTH_FeedOMatic_OnUpdate(elapsed)
if not elapsed then
@@ -128,104 +125,34 @@ local function MTH_FeedOMatic_SyncSavedVariables()
end
local moduleStore = MTH:GetModuleSavedVariables("feedomatic")
if not moduleStore.legacy then
moduleStore.legacy = {}
end
local function bindLegacyTable(globalName)
local legacyValue = moduleStore.legacy[globalName]
local globalValue = _G and _G[globalName] or nil
if type(legacyValue) ~= "table" then
-- Bind each legacy FeedOMatic global to its clean nested location under
-- modules.feedomatic. The globals are runtime aliases only (NOT persisted via
-- the TOC any more); the real data lives in these nested tables inside
-- MTH_SavedVariables. Adopt any pre-existing runtime global on first bind.
local function bindGlobal(globalName, key)
local target = moduleStore[key]
if type(target) ~= "table" then
local globalValue = _G and _G[globalName] or nil
if type(globalValue) == "table" then
legacyValue = globalValue
target = globalValue
else
legacyValue = {}
target = {}
end
moduleStore.legacy[globalName] = legacyValue
moduleStore[key] = target
end
if _G then
_G[globalName] = legacyValue
_G[globalName] = target
end
end
bindLegacyTable("FOM_Config")
bindLegacyTable("FOM_FoodQuality")
bindLegacyTable("FOM_AddedFoods")
bindLegacyTable("FOM_RemovedFoods")
bindLegacyTable("FOM_Cooking")
bindLegacyTable("FOM_QuestFood")
bindLegacyTable("FOM_LocaleInfo")
end
local function MTH_FeedOMatic_Log(message, severity)
if type(MTH_Log) == "function" then
MTH_Log("[FeedOMatic] " .. tostring(message or ""), severity)
end
end
local function MTH_FeedOMatic_DebugMerchantScan(sourceEvent)
if type(MTH_GetMerchantFoodsByDiet) ~= "function" then
MTH_FeedOMatic_Log(tostring(sourceEvent) .. ": MTH_GetMerchantFoodsByDiet is not available yet")
return
end
local merchantFoods = MTH_GetMerchantFoodsByDiet()
local knownCount = 0
local unknownCount = 0
if type(merchantFoods) == "table" then
if type(merchantFoods.items) == "table" then
knownCount = table.getn(merchantFoods.items)
end
if type(merchantFoods.unknown) == "table" then
unknownCount = table.getn(merchantFoods.unknown)
end
end
local merchantName = UnitName("npc") or UnitName("target") or "unknown"
MTH_FeedOMatic_Log(tostring(sourceEvent) .. ": wrapper scan for " .. tostring(merchantName) .. " | known=" .. tostring(knownCount) .. " | unknown=" .. tostring(unknownCount))
if type(merchantFoods.byDiet) == "table" then
for dietName, rows in merchantFoods.byDiet do
local dietCount = 0
if type(rows) == "table" then
dietCount = table.getn(rows)
end
if type(rows) == "table" then
for _, row in rows do
end
end
end
end
if unknownCount > 0 and type(merchantFoods.unknown) == "table" then
for _, row in merchantFoods.unknown do
end
end
end
local function MTH_FeedOMatic_SetMerchantProbeEnabled(enabled)
if not enabled then
if MTH_FOM_MerchantProbe then
MTH_FOM_MerchantProbe:UnregisterEvent("MERCHANT_SHOW")
MTH_FOM_MerchantProbe:UnregisterEvent("MERCHANT_UPDATE")
end
return
end
if not MTH_FOM_MerchantProbe then
MTH_FOM_MerchantProbe = CreateFrame("Frame", "MTH_FOM_MerchantProbe")
MTH_FOM_MerchantProbe:SetScript("OnEvent", function()
local evt = event
if evt == "MERCHANT_SHOW" or evt == "MERCHANT_UPDATE" then
MTH_FeedOMatic_DebugMerchantScan(evt)
end
end)
end
MTH_FOM_MerchantProbe:RegisterEvent("MERCHANT_SHOW")
MTH_FOM_MerchantProbe:RegisterEvent("MERCHANT_UPDATE")
bindGlobal("FOM_Config", "settings")
bindGlobal("FOM_FoodQuality", "foodQuality")
bindGlobal("FOM_AddedFoods", "addedFoods")
bindGlobal("FOM_RemovedFoods", "removedFoods")
bindGlobal("FOM_Cooking", "cooking")
bindGlobal("FOM_QuestFood", "questFood")
bindGlobal("FOM_LocaleInfo", "localeInfo")
end
function MTH_FeedOMatic:init()
@@ -265,7 +192,6 @@ function MTH_FeedOMatic:setEnabled(enabled)
MTH_FeedOMatic_CaptureHookBoundary()
MTH_FeedOMatic_SyncSavedVariables()
MTH_FeedOMatic_EnsureVariablesLoaded(self)
MTH_FeedOMatic_SetMerchantProbeEnabled(false)
if MTH_FOM_FeedButton then
MTH_FOM_FeedButton:Show()
end
@@ -275,7 +201,6 @@ function MTH_FeedOMatic:setEnabled(enabled)
if type(FOM_State) == "table" then
FOM_State.ShouldFeed = false
end
MTH_FeedOMatic_SetMerchantProbeEnabled(false)
if MTH_FOM_FeedButton then
MTH_FOM_FeedButton:Hide()
end
@@ -304,7 +229,6 @@ function MTH_FeedOMatic:cleanup()
if type(FOM_State) == "table" then
FOM_State.ShouldFeed = false
end
MTH_FeedOMatic_SetMerchantProbeEnabled(false)
if MTH_FOM_FeedButton then
MTH_FOM_FeedButton:Hide();
end