From b7b96cd9ef070ba4908bb336c69a869eee843c84 Mon Sep 17 00:00:00 2001 From: Shane McGovern Date: Wed, 26 Aug 2026 13:23:59 +0100 Subject: [PATCH] fix(ui): hoist getNavLayer definition before Kit.endFrame to fix nil function crash --- src/ui/kit/Kit.lua | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ui/kit/Kit.lua b/src/ui/kit/Kit.lua index 13f40c68..e00ea4b6 100644 --- a/src/ui/kit/Kit.lua +++ b/src/ui/kit/Kit.lua @@ -342,6 +342,32 @@ function Kit.beginFrame(mx, my, clicked, wheel) Kit._navN = 0 end +local function getNavLayer(slot) + if not slot then return 3 end + local id = tostring(slot.id or "") + local y = slot.y or 0 + + -- Layer 1: Top Bar (Settings / Gear, Close / Quit) + if id == "gear" or id == "settings" or id == "close" or id == "quit" or (y < 45 * Kit.scale and not id:match("^tab%-")) then + return 1 + end + + -- Layer 2: ROM Select & Feature Tabs (Red, Blue, Yellow, Gold, Silver, Crystal, Mods, Find, Skins, Bug) + if id:match("^tab%-") or (y >= 45 * Kit.scale and y < 105 * Kit.scale and (slot.h and slot.h < 50 * Kit.scale)) then + return 2 + end + + -- Layer 4: Footer (Patch notes, Updater, BCG, Export, etc.) + local screenH = (love and love.graphics and love.graphics.getHeight and love.graphics.getHeight()) or 480 + if id == "patch-notes" or id == "updater" or id == "bcg" + or id:match("^footer") or (y > screenH - 55 * Kit.scale) then + return 4 + end + + -- Layer 3: Main content panel (Import ROM / Play, Manage, Save slots, Mods list, Find mods, etc.) + return 3 +end + -- Retire this frame's keystrokes, wheel notches and one-shot activations. -- Anything typed while no field had focus is dropped here rather than -- replayed into the next field that gets clicked. @@ -417,32 +443,6 @@ function Kit.setFocus(id) Kit._ringShown = id ~= nil end --- Pick the nearest focusable in `dir` from the current one. Candidates must -local function getNavLayer(slot) - local id = tostring(slot.id or "") - local y = slot.y or 0 - - -- Layer 1: Top Bar (Settings / Gear, Close / Quit) - if id == "gear" or id == "settings" or id == "close" or id == "quit" or (y < 45 * Kit.scale and not id:match("^tab%-")) then - return 1 - end - - -- Layer 2: ROM Select & Feature Tabs (Red, Blue, Yellow, Gold, Silver, Crystal, Mods, Find, Skins, Bug) - if id:match("^tab%-") or (y >= 45 * Kit.scale and y < 105 * Kit.scale and (slot.h < 50 * Kit.scale)) then - return 2 - end - - -- Layer 4: Footer (Patch notes, Updater, BCG, Export, etc.) - local screenH = (love and love.graphics and love.graphics.getHeight and love.graphics.getHeight()) or 480 - if id == "patch-notes" or id == "updater" or id == "bcg" - or id:match("^footer") or (y > screenH - 55 * Kit.scale) then - return 4 - end - - -- Layer 3: Main content panel (Import ROM / Play, Manage, Save slots, Mods list, Find mods, etc.) - return 3 -end - function Kit._resolveNav() local dir = Kit._navQueue Kit._navQueue = nil