fix(game3): make Engine.canSwitch and State.prefixedName resilient to unpopulated RomText cache

This commit is contained in:
1jamie
2026-09-23 13:59:20 -05:00
parent 703e103e3c
commit d74c43a71b
2 changed files with 9 additions and 4 deletions
+7 -2
View File
@@ -2079,14 +2079,19 @@ function Engine.canSwitch(st, adapter, battler)
if not battler then return true end
if battler.expTrapped or battler.escapePrevention or (battler.expTrapTurns or 0) > 0 or battler.expIngrain then
-- src/party_menu.c:5964
return false, RomText.ascii("gText_PkmnCantSwitchOut", { stringVars = { adapter:displayName(battler) } })
local name = (adapter and adapter.displayName and adapter:displayName(battler)) or "POKéMON"
local ok, txt = pcall(RomText.ascii, "gText_PkmnCantSwitchOut", { stringVars = { name } })
if ok and txt then return false, txt end
return false, name .. " can't be switched out!"
end
local holder, ab = Abilities.escapeBlocker(adapter, battler)
if holder then
-- src/pokemon.c:6029
return false, State.text(st, "gText_PkmnsXPreventsSwitching", {
local ok, txt = pcall(State.text, st, "gText_PkmnsXPreventsSwitching", {
buff1 = State.prefixedName(st, holder), lastAbility = Abilities.id(ab),
})
if ok and txt then return false, txt end
return false, "Can't escape!"
end
return true
end
+2 -2
View File
@@ -389,13 +389,13 @@ function State.text(st, id, fill)
return require("src.core.game3.battle.battle_text").get(id, fill)
end
-- src/battle_message.c:2248
function State.prefixedName(st, battler, name)
name = name or State.displayName(battler)
if battler and battler.side == "player" then return name end
local RomText = require("src.core.game3.rom_text")
local prefix = (st ~= nil and not st.wild) and "sText_FoePkmnPrefix" or "sText_WildPkmnPrefix"
return RomText.plain(prefix) .. name
local ok, pre = pcall(RomText.plain, prefix)
return (ok and pre or (st ~= nil and not st.wild and "Foe " or "Wild ")) .. name
end
function State.isFainted(battler)