Files
pfQuest-turtle/patchtable.lua
T

70 lines
2.2 KiB
Lua

local loc = GetLocale()
local dbs = { "items", "quests", "quests-itemreq", "objects", "units", "zones", "professions", "areatrigger", "refloot" }
local noloc = { "items", "quests", "objects", "units" }
-- Patch databases to merge TurtleWoW data
local function patchtable(base, diff)
for k, v in pairs(diff) do
if base[k] and type(v) == "table" then
if type(base[k]) == "table" then
patchtable(base[k], v)
else
base[k] = v
end
elseif type(v) == "string" and v == "_" then
base[k] = nil
else
base[k] = v
end
end
end
local loc_core, loc_update
for _, db in pairs(dbs) do
if pfDB[db]["data-turtle"] then
patchtable(pfDB[db]["data"], pfDB[db]["data-turtle"])
end
for loc, _ in pairs(pfDB.locales) do
if pfDB[db][loc] and pfDB[db][loc.."-turtle"] then
loc_update = pfDB[db][loc.."-turtle"] or pfDB[db]["enUS-turtle"]
patchtable(pfDB[db][loc], loc_update)
end
end
end
loc_core = pfDB["professions"][loc] or pfDB["professions"]["enUS"]
loc_update = pfDB["professions"][loc.."-turtle"] or pfDB["professions"]["enUS-turtle"]
if loc_update then patchtable(loc_core, loc_update) end
if pfDB["minimap-turtle"] then patchtable(pfDB["minimap"], pfDB["minimap-turtle"]) end
if pfDB["meta-turtle"] then patchtable(pfDB["meta"], pfDB["meta-turtle"]) end
-- Reload all pfQuest internal database shortcuts
pfDatabase:Reload()
-- Automatically clear quest cache if new turtle quests have been found
local updatecheck = CreateFrame("Frame")
updatecheck:RegisterEvent("PLAYER_ENTERING_WORLD")
updatecheck:SetScript("OnEvent", function()
if pfDB["quests"]["data-turtle"] then
-- count all known turtle-wow quests
local count = 0
for k, v in pairs(pfDB["quests"]["data-turtle"]) do
count = count + 1
end
pfQuest:Debug("TurtleWoW loaded with |cff33ffcc" .. count .. "|r quests.")
-- check if the last count differs to the current amount of quests
if not pfQuest_turtlecount or pfQuest_turtlecount ~= count then
-- remove quest cache to force reinitialisation of all quests.
pfQuest:Debug("New quests found. Reloading |cff33ffccCache|r")
pfQuest_questcache = {}
end
-- write current count to the saved variable
pfQuest_turtlecount = count
end
end)