fix(switch): centralize the NX asset fallback in a boot-time loader overlay

The scattered per-call-site prefix rewrites were a parallel track that any
future newImage("assets/generated/...") would silently bypass.  Replace
them with NxAssetOverlay: installed once from love.load on NX only, it
wraps newImage / newImageData / newSource / filesystem.read / getInfo so a
missing assets/generated path falls back to the active version's
blue|yellow copy.  Call sites return to plain love loader calls, and
Assets.resolve goes back to being the platform-free mod-override point.

Two deliberate exceptions remain: the chip-audio worker (separate Lua
state) keeps receiving the prefix explicitly via audio.programPrefix, and
data/generated module loads keep using CacheFs.readActive.

A new guard test (tests/engine/nx_generated_guard_test.lua) fails CI on
any direct love loader call with a literal assets/generated path, so the
class of bug cannot regress by accident.  scripts/test.sh --quick is
green across all tiers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Andrew Quenehen
2026-08-03 15:42:55 -03:00
parent 17243a7d8b
commit 67e6b1fb04
15 changed files with 262 additions and 175 deletions
+4 -7
View File
@@ -124,14 +124,11 @@ local function loadBanks(data)
return cachedBanks
end
local raw, readError
-- NX-only: Blue/Yellow live under a versioned save-dir prefix. The main
-- thread resolves it before sending audio to the worker; the sync path
-- resolves it here so desktop keeps the mountVersion overlay behavior.
-- The chip worker runs in a separate Lua state without the NX overlay;
-- ChipAudio hands it the versioned cache prefix explicitly. On the main
-- thread the NX overlay (or desktop mountVersion) makes the plain read
-- resolve, so no platform branching belongs here.
local prefix = audio.programPrefix
if not prefix and require("src.core.Platform").isNX() then
local gv = require("src.core.GameVersion").cachePrefix()
if gv ~= "" then prefix = gv end
end
if prefix and prefix ~= "" then
raw, readError = love.filesystem.read(prefix .. audio.programFile)
end