mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-28 18:06:09 +02:00
Add the MODS tab sort options to the Find Mods tab
This commit is contained in:
@@ -1426,6 +1426,80 @@ local function buildFindPanel(imp, parent, m)
|
||||
return
|
||||
end
|
||||
|
||||
-- Sort row: Name / Popularity / Release date / Last updated, the same
|
||||
-- options the MODS tab offers, sharing its persisted choice
|
||||
-- (options.modSort). Data comes from the same _findStats resolution the
|
||||
-- cards use (feed-published, else the repo fetch); rows whose stats have
|
||||
-- not resolved yet sink to the bottom of data sorts and rise as the
|
||||
-- one-per-frame fetches complete.
|
||||
local sortKey = imp.modSort or "name"
|
||||
if imp.modSort == nil then
|
||||
local ok, opts = pcall(require("src.core.SaveData").loadOptions)
|
||||
if ok and type(opts) == "table" and type(opts.modSort) == "string" then
|
||||
sortKey = opts.modSort
|
||||
imp.modSort = sortKey
|
||||
end
|
||||
end
|
||||
local sortRow = mk({ parent = parent, width = "100%",
|
||||
positioning = "flex", flexDirection = "horizontal",
|
||||
flexWrap = "wrap", alignItems = "center", gap = 6 * m.s })
|
||||
label(sortRow, Strings("Sort:"), 11 * m.s + 2, C("detail"), { textWrap = false })
|
||||
local sorts = {
|
||||
{ key = "name", label = Strings("Name") },
|
||||
{ key = "popularity", label = Strings("Popularity") },
|
||||
{ key = "release", label = Strings("Release date") },
|
||||
{ key = "updated", label = Strings("Last updated") },
|
||||
}
|
||||
for _, s in ipairs(sorts) do
|
||||
local active = sortKey == s.key
|
||||
local key = "find-sort-" .. s.key
|
||||
mk({
|
||||
parent = sortRow, text = s.label,
|
||||
textColor = active and C("green")
|
||||
or (imp._hot[key] and C("white") or C("detail")),
|
||||
textSize = 11 * m.s + 2, textAlign = "center-center", autoScaleText = false,
|
||||
backgroundColor = active and C("green", 0.18) or C("border", 0.10),
|
||||
border = 1,
|
||||
borderColor = active and C("green", 0.6) or C("border", 0.35),
|
||||
cornerRadius = 999,
|
||||
padding = { horizontal = 10, vertical = 4 },
|
||||
onEvent = handler(imp, key, function()
|
||||
imp.modSort = s.key
|
||||
pcall(function()
|
||||
local SaveData = require("src.core.SaveData")
|
||||
local opts = SaveData.loadOptions()
|
||||
opts.modSort = s.key
|
||||
SaveData.saveOptions(opts)
|
||||
end)
|
||||
end),
|
||||
})
|
||||
end
|
||||
|
||||
local sorted = {}
|
||||
for i, v in ipairs(rows) do sorted[i] = v end
|
||||
table.sort(sorted, function(a, b)
|
||||
local function value(entry)
|
||||
if sortKey == "name" then
|
||||
return (entry.title or entry.id or ""):lower()
|
||||
end
|
||||
local stats = imp:_findStats(entry)
|
||||
if sortKey == "popularity" then
|
||||
return stats and stats.total or -1
|
||||
end
|
||||
if sortKey == "release" then
|
||||
return stats and stats.first or "0000-00-00"
|
||||
end
|
||||
return stats and stats.latest or "0000-00-00"
|
||||
end
|
||||
local va, vb = value(a), value(b)
|
||||
if va ~= vb then
|
||||
if sortKey == "name" then return va < vb end
|
||||
return va > vb -- data sorts newest / most popular first
|
||||
end
|
||||
return (a.title or a.id or ""):lower() < (b.title or b.id or ""):lower()
|
||||
end)
|
||||
rows = sorted
|
||||
|
||||
local installed = imp:_findInstalledMap()
|
||||
local thumbW = 64 * m.s
|
||||
-- Explicit measured widths AND heights, same reasoning as the mods card:
|
||||
|
||||
@@ -2220,16 +2220,7 @@ end
|
||||
-- renders it. Required lazily so a headless test require of this module
|
||||
-- never loads the UI toolkit.
|
||||
function RomImporter:draw()
|
||||
local ok, err = pcall(require("src.import.LauncherView").draw, self)
|
||||
if not ok then
|
||||
local f = io.open("/tmp/launcher-crash.log", "a")
|
||||
if f then
|
||||
f:write(os.date("%H:%M:%S") .. " " .. tostring(err) .. "\n")
|
||||
f:write(debug.traceback("", 2) .. "\n")
|
||||
f:close()
|
||||
end
|
||||
error(err, 0)
|
||||
end
|
||||
require("src.import.LauncherView").draw(self)
|
||||
end
|
||||
|
||||
-- Nothing in the launcher can undo a delete, so every Delete control asks
|
||||
|
||||
Reference in New Issue
Block a user