Files
gen1recomp/tests/game3_battle_translated_text_test.lua
T
thibautbus b97c683743 Route FireRed battle messages through Strings()
Every message the game3 battle engine prints was built by concatenating English fragments around names ("X" .. " is hurt\nby poison!"), so a translation mod could not reach them, nor phrase a sentence other than as English splits it. They are now whole-sentence Strings() templates with the names as arguments (Strings("%s is hurt\nby poison!", name)), which renders the same English and lets a catalog word the whole sentence around each value. The one visible change is that effect messages now name abilities through Abilities.name, as the cart prints them (COMPOUNDEYES, LIGHTNINGROD) rather than from the identifier (COMPOUND EYES). Values still fill the template in call order (Strings() formats with string.format).

Fragment tables become full templates: status infliction, charge-turn and semi-invulnerable moves, Truant, berry flavours, held-item and enemy-item cures, and the stat-change lines (one template per rose/sharply rose/fell/harshly fell instead of a translated verb glued after the stat). Tables built at load time mark their keys with Strings.source() and are translated where they are said, since no catalog exists yet when the module loads. Stat names, the Ally/Foe prefixes, weather lines and screen names are translated at the time they are shown; the "a boosted" EXP line and the trainer send-out line become one template per variant rather than a fragment passed as an argument.

Code that read the English text back is fixed too: the double-battle send-out (animated and headless intros) no longer parses the trainer out of the translated "sent out" line, the battle UI paces the move-used line by its catalog wording, and AnimSeq recognises the miss, confusion, substitute, move-used and fainted lines it paces animations on through their catalog wording.
2026-09-19 23:04:31 +02:00

47 lines
1.5 KiB
Lua

#!/usr/bin/env luajit
-- AnimSeq reads a few battle messages to pace the animation (a missed move
-- pauses, a fainted POKéMON drops). The messages are translated by then, so
-- it has to recognise them through the catalog's wording, not the English.
package.path = "./?.lua;./?/init.lua;" .. package.path
love = require("tests.love_stub")
local failed = 0
local function check(cond, msg)
if not cond then
failed = failed + 1
print("[FAIL] " .. msg)
end
end
local Strings = require("src.core.Strings")
local AnimSeq = require("src.core.game3.battle.anim_seq")
local function kinds(steps)
local out = {}
for _, step in ipairs(steps) do out[#out + 1] = step.kind end
return table.concat(out, ",")
end
local function missPauses(text)
local steps = AnimSeq.buildSteps({
{ kind = "msg", text = "PIKACHU utilise\nECLAIR!" },
{ kind = "msg", text = text },
})
return kinds(steps):find("pause", 1, true) ~= nil
end
check(missPauses("PIKACHU's\nattack missed!"), "an English miss pauses")
Strings.load({ strings = {
["%s's\nattack missed!"] = "%s\nrate son attaque!",
["It doesn't affect\n%s…"] = "Ça n'affecte pas\n%s…",
} })
check(missPauses("PIKACHU\nrate son attaque!"), "a translated miss pauses")
check(missPauses("Ça n'affecte pas\nRONFLEX…"), "a translated no-effect line pauses")
check(not missPauses("PIKACHU\nest KO!"), "another line does not pause")
Strings.load({})
print(("game3_battle_translated_text_test: %s (%d failed)"):format(failed == 0 and "PASS" or "FAIL", failed))
if failed > 0 then os.exit(1) end