feat: add Database options tab with import/export/cleanup
New files:
- Modules/QuestieLearnerExport.lua: serialize/compress/encode pipeline using
AceSerializer + LibDeflate:CompressDeflate(level=9) + EncodeForPrint.
QxLD:<version>!<encoded> string format. Export(), ExportAll(), ValidateImport(),
MergeImport(), DryRunPrune(), Prune().
- Modules/Options/DatabaseTab/QuestieOptionsDatabase.lua: new Database tab with:
- Live learned data stats (per server)
- Per-type learner toggles (NPCs/Quests/Objects/Items/Broadcast)
- Export current server / Export all servers buttons (opens scrollable dialog)
- Import window (paste -> Validate -> Import with diff summary)
- Dry-run preview and Prune Now cleanup buttons
- Full reset button (confirm-gated)
- Contribute section with step-by-step GitHub submission instructions
Wiring:
- QuestieOptions.lua: database_tab initialized and registered in args
- All TOC files: QuestieLearnerExport.lua added before options, DatabaseTab lua added
This commit is contained in:
@@ -0,0 +1,441 @@
|
||||
---@type QuestieOptions
|
||||
local QuestieOptions = QuestieLoader:ImportModule("QuestieOptions")
|
||||
---@type l10n
|
||||
local l10n = QuestieLoader:ImportModule("l10n")
|
||||
|
||||
QuestieOptions.tabs.database = {}
|
||||
|
||||
local AceGUI = LibStub("AceGUI-3.0")
|
||||
|
||||
-- Forward declarations for dialog functions
|
||||
local _OpenExportDialog, _OpenImportDialog
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Dialog helpers
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
local function GetExportModule()
|
||||
return QuestieLoader:ImportModule("QuestieLearnerExport")
|
||||
end
|
||||
|
||||
local function GetServer()
|
||||
if Questie.IsAscension then return "Ascension" end
|
||||
if Questie.IsTurtle then return "Turtle" end
|
||||
if Questie.IsEbonhold then return "Ebonhold" end
|
||||
if Questie.IsEra then return "Era" end
|
||||
if Questie.Is335 then return "WotLK" end
|
||||
return GetRealmName and GetRealmName() or "unknown"
|
||||
end
|
||||
|
||||
local function GetLearnedCounts()
|
||||
local ld = Questie.db and Questie.db.global and Questie.db.global.learnedData
|
||||
local none = { npcs = 0, quests = 0, items = 0, objects = 0, total = 0 }
|
||||
if not ld then return none end
|
||||
local bucket = ld[GetServer()] or (ld.npcs and ld) or nil
|
||||
if not bucket then return none end
|
||||
local function Count(t)
|
||||
if not t then return 0 end
|
||||
local n = 0; for _ in pairs(t) do n = n + 1 end; return n
|
||||
end
|
||||
local s = {
|
||||
npcs = Count(bucket.npcs),
|
||||
quests = Count(bucket.quests),
|
||||
items = Count(bucket.items),
|
||||
objects = Count(bucket.objects),
|
||||
}
|
||||
s.total = s.npcs + s.quests + s.items + s.objects
|
||||
return s
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Export Dialog
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
_OpenExportDialog = function(exportStr, stats)
|
||||
local f = AceGUI:Create("Frame")
|
||||
f:SetTitle("Questie-X — Export Learned Data")
|
||||
f:SetWidth(620)
|
||||
f:SetHeight(420)
|
||||
f:SetLayout("Flow")
|
||||
f:SetCallback("OnClose", function(w) AceGUI:Release(w) end)
|
||||
|
||||
local info = AceGUI:Create("Label")
|
||||
info:SetFullWidth(true)
|
||||
info:SetText(string.format(
|
||||
"|cFFFFD700Server:|r %s |cFFFFD700NPCs:|r %d |cFFFFD700Quests:|r %d |cFFFFD700Items:|r %d |cFFFFD700Objects:|r %d |cFFFFD700Total:|r %d entries",
|
||||
GetServer(), stats.npcs or 0, stats.quests or 0, stats.items or 0, stats.objects or 0, stats.total or 0
|
||||
))
|
||||
f:AddChild(info)
|
||||
|
||||
local spacer = AceGUI:Create("Label")
|
||||
spacer:SetFullWidth(true)
|
||||
spacer:SetText(" ")
|
||||
f:AddChild(spacer)
|
||||
|
||||
local box = AceGUI:Create("MultiLineEditBox")
|
||||
box:SetFullWidth(true)
|
||||
box:SetNumLines(14)
|
||||
box:SetLabel("Select all and copy (Ctrl+A, Ctrl+C):")
|
||||
box:SetText(exportStr)
|
||||
box:DisableButton(true)
|
||||
f:AddChild(box)
|
||||
|
||||
local hint = AceGUI:Create("Label")
|
||||
hint:SetFullWidth(true)
|
||||
hint:SetText("|cFF888888To share your data: copy this string and submit it on the Questie-X GitHub or Discord. Contributors help grow the quest database for everyone.|r")
|
||||
f:AddChild(hint)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Import Dialog
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
_OpenImportDialog = function()
|
||||
local f = AceGUI:Create("Frame")
|
||||
f:SetTitle("Questie-X — Import Learned Data")
|
||||
f:SetWidth(620)
|
||||
f:SetHeight(420)
|
||||
f:SetLayout("Flow")
|
||||
f:SetCallback("OnClose", function(w) AceGUI:Release(w) end)
|
||||
|
||||
local statusLabel = AceGUI:Create("Label")
|
||||
statusLabel:SetFullWidth(true)
|
||||
statusLabel:SetText("|cFF888888Paste a QxLD export string below, then click Validate.|r")
|
||||
f:AddChild(statusLabel)
|
||||
|
||||
local spacer = AceGUI:Create("Label")
|
||||
spacer:SetFullWidth(true)
|
||||
spacer:SetText(" ")
|
||||
f:AddChild(spacer)
|
||||
|
||||
local box = AceGUI:Create("MultiLineEditBox")
|
||||
box:SetFullWidth(true)
|
||||
box:SetNumLines(12)
|
||||
box:SetLabel("Paste export string here:")
|
||||
box:SetText("")
|
||||
box:DisableButton(true)
|
||||
f:AddChild(box)
|
||||
|
||||
local validateBtn = AceGUI:Create("Button")
|
||||
validateBtn:SetText("Validate")
|
||||
validateBtn:SetWidth(120)
|
||||
f:AddChild(validateBtn)
|
||||
|
||||
local importBtn = AceGUI:Create("Button")
|
||||
importBtn:SetText("Import")
|
||||
importBtn:SetWidth(120)
|
||||
importBtn:SetDisabled(true)
|
||||
f:AddChild(importBtn)
|
||||
|
||||
validateBtn:SetCallback("OnClick", function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then
|
||||
statusLabel:SetText("|cFFFF0000Export module not loaded.|r")
|
||||
return
|
||||
end
|
||||
local input = box:GetText()
|
||||
local payload, statsOrErr = Exp:ValidateImport(input)
|
||||
if not payload then
|
||||
statusLabel:SetText("|cFFFF0000Validation failed: " .. tostring(statsOrErr) .. "|r")
|
||||
importBtn:SetDisabled(true)
|
||||
else
|
||||
statusLabel:SetText(string.format(
|
||||
"|cFF00FF00Valid! Server: %s NPCs: %d Quests: %d Items: %d Objects: %d Total: %d|r",
|
||||
statsOrErr.server or "?",
|
||||
statsOrErr.npcs or 0, statsOrErr.quests or 0,
|
||||
statsOrErr.items or 0, statsOrErr.objects or 0,
|
||||
statsOrErr.total or 0
|
||||
))
|
||||
importBtn:SetDisabled(false)
|
||||
end
|
||||
end)
|
||||
|
||||
importBtn:SetCallback("OnClick", function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then return end
|
||||
local ok, msg = Exp:MergeImport()
|
||||
if ok then
|
||||
statusLabel:SetText("|cFF00FF00" .. msg .. "|r")
|
||||
importBtn:SetDisabled(true)
|
||||
else
|
||||
statusLabel:SetText("|cFFFF0000" .. msg .. "|r")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Tab Definition
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
function QuestieOptions.tabs.database:Initialize()
|
||||
return {
|
||||
name = function() return l10n("Database") end,
|
||||
type = "group",
|
||||
order = 9,
|
||||
args = {
|
||||
|
||||
---- Header -----------------------------------------------
|
||||
db_header = {
|
||||
type = "header",
|
||||
order = 1,
|
||||
name = function() return l10n("Learned Data") end,
|
||||
},
|
||||
|
||||
---- Live stats description --------------------------------
|
||||
db_stats_desc = {
|
||||
type = "description",
|
||||
order = 1.1,
|
||||
fontSize = "medium",
|
||||
name = function()
|
||||
local s = GetLearnedCounts()
|
||||
if s.total == 0 then
|
||||
return "|cFF888888No learned data recorded yet. Play the game and Questie will learn as you go.|r"
|
||||
end
|
||||
return string.format(
|
||||
"|cFFFFD700Server:|r %s\n|cFF5EBAF3NPCs:|r %d |cFF5EBAF3Quests:|r %d |cFF5EBAF3Items:|r %d |cFF5EBAF3Objects:|r %d\n|cFFFFFFFFTotal entries:|r %d",
|
||||
GetServer(), s.npcs, s.quests, s.items, s.objects, s.total
|
||||
)
|
||||
end,
|
||||
},
|
||||
|
||||
---- Learner Toggles header --------------------------------
|
||||
learner_toggle_header = {
|
||||
type = "header",
|
||||
order = 2,
|
||||
name = function() return l10n("What To Learn") end,
|
||||
},
|
||||
|
||||
learn_npcs = {
|
||||
type = "toggle",
|
||||
order = 2.1,
|
||||
name = function() return l10n("Learn NPCs") end,
|
||||
desc = function() return l10n("Record quest-relevant NPC positions and data.") end,
|
||||
get = function() return Questie.db.global.learnedData and Questie.db.global.learnedData.settings and Questie.db.global.learnedData.settings.learnNpcs end,
|
||||
set = function(_, v)
|
||||
if Questie.db.global.learnedData and Questie.db.global.learnedData.settings then
|
||||
Questie.db.global.learnedData.settings.learnNpcs = v
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
learn_quests = {
|
||||
type = "toggle",
|
||||
order = 2.2,
|
||||
name = function() return l10n("Learn Quests") end,
|
||||
desc = function() return l10n("Record quest metadata, objectives, and rewards.") end,
|
||||
get = function() return Questie.db.global.learnedData and Questie.db.global.learnedData.settings and Questie.db.global.learnedData.settings.learnQuests end,
|
||||
set = function(_, v)
|
||||
if Questie.db.global.learnedData and Questie.db.global.learnedData.settings then
|
||||
Questie.db.global.learnedData.settings.learnQuests = v
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
learn_objects = {
|
||||
type = "toggle",
|
||||
order = 2.3,
|
||||
name = function() return l10n("Learn Objects") end,
|
||||
desc = function() return l10n("Record interactable quest object positions.") end,
|
||||
get = function() return Questie.db.global.learnedData and Questie.db.global.learnedData.settings and Questie.db.global.learnedData.settings.learnObjects end,
|
||||
set = function(_, v)
|
||||
if Questie.db.global.learnedData and Questie.db.global.learnedData.settings then
|
||||
Questie.db.global.learnedData.settings.learnObjects = v
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
learn_items = {
|
||||
type = "toggle",
|
||||
order = 2.4,
|
||||
name = function() return l10n("Learn Items") end,
|
||||
desc = function() return l10n("Record quest item drop sources.") end,
|
||||
get = function() return Questie.db.global.learnedData and Questie.db.global.learnedData.settings and Questie.db.global.learnedData.settings.learnItems end,
|
||||
set = function(_, v)
|
||||
if Questie.db.global.learnedData and Questie.db.global.learnedData.settings then
|
||||
Questie.db.global.learnedData.settings.learnItems = v
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
learn_broadcast = {
|
||||
type = "toggle",
|
||||
order = 2.5,
|
||||
name = function() return l10n("Broadcast to Party") end,
|
||||
desc = function() return l10n("Share newly learned data with nearby party/raid members who also have Questie-X.") end,
|
||||
get = function() return Questie.db.profile.learnerBroadcast end,
|
||||
set = function(_, v) Questie.db.profile.learnerBroadcast = v end,
|
||||
},
|
||||
|
||||
---- Export -----------------------------------------------
|
||||
export_header = {
|
||||
type = "header",
|
||||
order = 3,
|
||||
name = function() return l10n("Export") end,
|
||||
},
|
||||
|
||||
export_desc = {
|
||||
type = "description",
|
||||
order = 3.1,
|
||||
fontSize = "medium",
|
||||
name = function()
|
||||
return "|cFF888888Export your learned data as a compressed string. You can paste this in a GitHub issue or Discord message to help improve the official Questie databases.|r"
|
||||
end,
|
||||
},
|
||||
|
||||
export_current_btn = {
|
||||
type = "execute",
|
||||
order = 3.2,
|
||||
name = function() return l10n("Export Current Server") end,
|
||||
desc = function()
|
||||
local s = GetLearnedCounts()
|
||||
return string.format("Export %d entries for %s", s.total, GetServer())
|
||||
end,
|
||||
func = function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then
|
||||
Questie:Print("|cFFFF0000QuestieLearnerExport module not loaded.|r")
|
||||
return
|
||||
end
|
||||
local str, statsOrErr = Exp:Export()
|
||||
if not str then
|
||||
Questie:Print("|cFFFF0000Export failed: " .. tostring(statsOrErr) .. "|r")
|
||||
else
|
||||
_OpenExportDialog(str, statsOrErr)
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
export_all_btn = {
|
||||
type = "execute",
|
||||
order = 3.3,
|
||||
name = function() return l10n("Export All Servers") end,
|
||||
desc = function() return "Export merged data from all server profiles." end,
|
||||
func = function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then
|
||||
Questie:Print("|cFFFF0000QuestieLearnerExport module not loaded.|r")
|
||||
return
|
||||
end
|
||||
local str, statsOrErr = Exp:ExportAll()
|
||||
if not str then
|
||||
Questie:Print("|cFFFF0000Export failed: " .. tostring(statsOrErr) .. "|r")
|
||||
else
|
||||
_OpenExportDialog(str, statsOrErr)
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
---- Import -----------------------------------------------
|
||||
import_header = {
|
||||
type = "header",
|
||||
order = 4,
|
||||
name = function() return l10n("Import") end,
|
||||
},
|
||||
|
||||
import_desc = {
|
||||
type = "description",
|
||||
order = 4.1,
|
||||
fontSize = "medium",
|
||||
name = function()
|
||||
return "|cFF888888Import a QxLD string from another player or the Questie-X GitHub. Questie-X will validate the string before merging — existing data with higher confidence is never overwritten.|r"
|
||||
end,
|
||||
},
|
||||
|
||||
import_btn = {
|
||||
type = "execute",
|
||||
order = 4.2,
|
||||
name = function() return l10n("Open Import Window") end,
|
||||
func = function()
|
||||
_OpenImportDialog()
|
||||
end,
|
||||
},
|
||||
|
||||
---- Cleanup ----------------------------------------------
|
||||
cleanup_header = {
|
||||
type = "header",
|
||||
order = 5,
|
||||
name = function() return l10n("Cleanup") end,
|
||||
},
|
||||
|
||||
cleanup_desc = {
|
||||
type = "description",
|
||||
order = 5.1,
|
||||
fontSize = "medium",
|
||||
name = function()
|
||||
return "|cFF888888Remove stale, empty, or low-confidence entries from your learned data. Run a dry-run first to see what would be removed.|r"
|
||||
end,
|
||||
},
|
||||
|
||||
prune_dry_btn = {
|
||||
type = "execute",
|
||||
order = 5.2,
|
||||
name = function() return l10n("Dry Run (Preview)") end,
|
||||
desc = function() return "Print a summary of entries that would be removed, without deleting anything." end,
|
||||
func = function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then return end
|
||||
local r = Exp:DryRunPrune()
|
||||
Questie:Print(string.format(
|
||||
"|cFF00FF00[Learner Prune Preview]|r Would remove: NPCs %d, Quests %d, Items %d, Objects %d — Total %d",
|
||||
r.npcs, r.quests, r.items, r.objects, r.total
|
||||
))
|
||||
if r.total > 0 then
|
||||
Questie:Print("|cFF888888Use /questie db prune to apply, or click Prune Now in the Database tab.|r")
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
prune_btn = {
|
||||
type = "execute",
|
||||
order = 5.3,
|
||||
name = function() return l10n("Prune Now") end,
|
||||
desc = function() return "|cFFFF8800Removes stale entries. Cannot be undone. Export first if you want a backup.|r" end,
|
||||
func = function()
|
||||
local Exp = GetExportModule()
|
||||
if not Exp then return end
|
||||
local r = Exp:Prune()
|
||||
Questie:Print(string.format(
|
||||
"|cFF00FF00[Learner Prune]|r Removed: NPCs %d, Quests %d, Items %d, Objects %d — Total %d",
|
||||
r.npcs, r.quests, r.items, r.objects, r.total
|
||||
))
|
||||
end,
|
||||
},
|
||||
|
||||
prune_all_btn = {
|
||||
type = "execute",
|
||||
order = 5.4,
|
||||
name = function() return "|cFFFF4444" .. l10n("Reset All Learned Data") .. "|r" end,
|
||||
desc = function() return "|cFFFF0000DANGER: Wipes ALL learned data for ALL servers. Export first.|r" end,
|
||||
confirm = true,
|
||||
confirmText = "Are you sure? This cannot be undone.",
|
||||
func = function()
|
||||
if Questie.db and Questie.db.global then
|
||||
Questie.db.global.learnedData = nil
|
||||
Questie:Print("|cFFFF4444[Questie-X]|r All learned data has been reset.")
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
---- Submit/Contribute ------------------------------------
|
||||
submit_header = {
|
||||
type = "header",
|
||||
order = 6,
|
||||
name = function() return l10n("Contribute") end,
|
||||
},
|
||||
|
||||
submit_desc = {
|
||||
type = "description",
|
||||
order = 6.1,
|
||||
fontSize = "medium",
|
||||
name = function()
|
||||
return "|cFF888888Want to help grow the Questie-X database?\n\n" ..
|
||||
"1. Click |r|cFFFFFFFFExport Current Server|r|cFF888888 above.\n" ..
|
||||
"2. Copy the full export string (Ctrl+A then Ctrl+C in the dialog).\n" ..
|
||||
"3. Open a new GitHub issue at |r|cFF5EBAF3github.com/Xurkon/Questie-X/issues|r|cFF888888 titled: |r|cFFFFFFFF[Data Submission] <Server Name>|r|cFF888888\n" ..
|
||||
"4. Paste the string into the issue body and submit.\n\n" ..
|
||||
"Submissions are reviewed and merged into the official database. Thank you for contributing!|r"
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
@@ -137,6 +137,8 @@ _CreateOptionsTable = function()
|
||||
coroutine.yield()
|
||||
local advanced_tab = QuestieOptions.tabs.advanced:Initialize()
|
||||
coroutine.yield()
|
||||
local database_tab = QuestieOptions.tabs.database:Initialize()
|
||||
coroutine.yield()
|
||||
local credits_tab = QuestieOptions.tabs.credits:Initialize()
|
||||
coroutine.yield()
|
||||
return {
|
||||
@@ -157,6 +159,7 @@ _CreateOptionsTable = function()
|
||||
nameplate_tab = nameplate_tab,
|
||||
dbm_hud_tab = dbm_hud_tab,
|
||||
advanced_tab = advanced_tab,
|
||||
database_tab = database_tab,
|
||||
credits_tab = credits_tab,
|
||||
profiles_tab = LibStub("AceDBOptions-3.0"):GetOptionsTable(Questie.db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user