-
Notifications
You must be signed in to change notification settings - Fork 0
Format
Format.lua: diagnostic-panel formatters: library version status, version history coloring, a settings on/off snapshot, and stripping color markup for a plain-text destination.
Picks which branch fires (missing, disabled, exact match, older-than, newer-than); you supply the wording for each one via formatters.
local text = LibAPH.FormatLibraryVersion(lam_version, lam_enabled, MyAddon.REQUIRED_LAM_VERSION, {
missing = function() return "|cFF0000LAM2 not found|r" end,
disabled = function(v) return string.format("|cFF0000LAM2 (v%d) disabled|r", v) end,
exact = function(v) return string.format("|c00FF00LAM2 (v%d)|r", v) end,
old = function(v, r) return string.format("|c888888LAM2|r |cFF0000v%d|r, expected |c00FFFFv%d|r", v, r) end,
newer = function(v, r) return string.format("|c00FFFFLAM2 v%d (expected v%d)|r", v, r) end,
})Colors a list of version strings (oldest entry red, newest green, everything between left plain), joined with sep (default ", "). history defaults to {currentVersion} if omitted.
LibAPH.FormatVersionHistory({"0.8.6", "0.8.7", "0.8.8"}, "0.8.8")
--> "|cFF00000.8.6|r, 0.8.7, |c00FF000.8.8|r"Turns a flat settings table plus a curated field list into readable On/Off lines, for a bug report.
local text = LibAPH.FormatSettingsSnapshot(
MyAddon.settings,
{ { key = "is_csa_enabled", label = "CSA Announcements" }, { key = "is_log_enabled", label = "Chat Log" } },
"ON", "OFF"
)
--> "CSA Announcements: ON\nChat Log: OFF"fields is an ordered list of {key=, label=}. Anything missing from settings or not a plain boolean is silently skipped: this only knows how to render a toggle, it won't guess at formatting anything else. Pull label from the same text your settings-menu checkbox already uses, so a bug report reads with the same wording the player sees in-game.
Strips |cRRGGBB...|r color markup via a Lua pattern. For text headed to a plain-text destination (an editable copy box a player selects and pastes into a bug report), not an in-game label, where those color codes are correct and wanted.
LibAPH.StripColors("|c00FF00Success|r: cleared 12.4 MB")
--> "Success: cleared 12.4 MB"" (v12)" / " v12". Both return "" for a nil or zero version - GetAddOnVersion() returns 0 for any addon whose manifest carries no real AddOnVersion field.
Compares an installed library's version against a recorded/known version. Returns color, plus, label: green with no suffix if equal, cyan with "+" and " (Newer Version)" if installed is higher, red with " (Old Version)" if lower, white if tableVer is nil.
local color, plus, label = LibAPH.GetLibraryDriftColor(ver, libData.requiredVersion)
d(string.format(" %s: %sv%d%s%s|r", libData.fullName, color, ver, plus, label))Returns version, enabled for any installed addon or library by exact manifest name.
local lam_v, lam_e = LibAPH.CheckLibraryVersion("LibAddonMenu-2.0")
LibAPH.BuildLibraryWarning(templates, fullName, shortName, ver, enabled, requiredVer, consequence) / LibAPH.BuildLibraryWarningFromData(templates, libData, ver, enabled, consequence)
Ready-made missing/disabled/outdated warning text for an optional library dependency: your own %s-format templates, with colored version numbers (red for old, green for the required/target version) filled in. Returns nil when nothing's wrong (exact match or newer).
BuildLibraryWarningFromData reads fullName/shortName/requiredVersion off a libData table instead of taking them as separate arguments.
local lam_alert = LibAPH.BuildLibraryWarning(libwarn_templates, "LibAddonMenu", "LAM", lam_ver, lam_en, MyAddon.REQUIRED_LAM_VERSION, "the settings menu won't open")Copies every key from defaults into settings (deep-copying tables via ZO_ShallowTableCopy) except keys listed in excludeKeys, runs postFn if given, then reloads the UI.
function MyAddon.reset_to_defaults()
LibAPH.ResetToDefaults(MyAddon.settings, MyAddon.defaults, {
wizard_completed = true,
})
endColored "install date > today" line for a diagnostic panel.
LibAPH.FormatModuleFileLine(filename, state, labels) / LibAPH.BuildModuleFileList(moduleOrder, moduleFiles, getState, labels, sep)
One colored loaded/missing/unloaded line per module file, or the whole ordered list joined with sep (default "\n ").
local file_lines_str = LibAPH.BuildModuleFileList(
{ "migration", "wizard", "menu", "ui" },
{ migration = "MODULE/ALC_Migration.lua", wizard = "MODULE/ALC_Wizard.lua", menu = "MODULE/ALC_Menu.lua", ui = "MODULE/ALC_UI.lua" },
function(mod_key) return (MyAddon._modules[mod_key] == false) and "unloaded" or "loaded" end,
{ loaded = "Loaded", unloaded = "Unloaded by user" }
)Joins a stats section, a settings section, and an error section into one report body. opts: statsText, fieldSettingsLabel, settingsLines, errorSection.
local text = LibAPH.BuildBugReportText({
statsText = MyAddon.build_client_info_text(),
settingsLines = settings_lines,
fieldSettingsLabel = MyAddon.L("FIELD_SETTINGS"),
errorSection = error_section,
})