mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-10-01 07:40:29 -04:00
Find FireRed summary descriptions by the ROM's move and ability names
SummaryData looks a move or ability description up as MOVE_<name> / ABILITY_<name>, built from the name the summary shows. A translation mod renames moves in place (the moves registry writes Pokemon._moveNames), so with one enabled the key became MOVE_<translated name>, nothing matched, and the summary and TM Case showed "---" instead of the description. Pokemon.install now keeps a copy of the ROM's English move and ability names before any mod patches them, exposed as Pokemon.romMoveName / romAbilityName, and the description lookups use it, falling back to the name passed in when the pack has none.
This commit is contained in:
@@ -22,6 +22,11 @@ Pokemon._abilities = nil
|
||||
Pokemon._abilityNames = nil
|
||||
Pokemon._speciesMeta = nil
|
||||
Pokemon._moveNames = nil
|
||||
-- The ROM's English move and ability names, copied at install before a mod
|
||||
-- renames entries of _moveNames/_abilityNames in place. Anything keyed by
|
||||
-- the English name (the summary's descriptions) reads these.
|
||||
Pokemon._romMoveNames = nil
|
||||
Pokemon._romAbilityNames = nil
|
||||
Pokemon._learnsets = nil
|
||||
Pokemon._eggMoves = nil
|
||||
Pokemon._evolutions = nil
|
||||
@@ -63,6 +68,13 @@ local function resolve_cache(cache)
|
||||
}
|
||||
end
|
||||
|
||||
local function copy_names(names)
|
||||
if type(names) ~= "table" then return nil end
|
||||
local out = {}
|
||||
for k, v in pairs(names) do out[k] = v end
|
||||
return out
|
||||
end
|
||||
|
||||
local function load_lua(cache, rel)
|
||||
cache = resolve_cache(cache)
|
||||
local src = cache:read(rel)
|
||||
@@ -125,6 +137,8 @@ function Pokemon.install(cache)
|
||||
Pokemon._abilityNames = nil
|
||||
Pokemon._speciesMeta = nil
|
||||
Pokemon._moveNames = nil
|
||||
Pokemon._romMoveNames = nil
|
||||
Pokemon._romAbilityNames = nil
|
||||
Pokemon._learnsets = nil
|
||||
Pokemon._eggMoves = nil
|
||||
Pokemon._evolutions = nil
|
||||
@@ -146,6 +160,8 @@ function Pokemon.install(cache)
|
||||
Pokemon._abilityNames = load_lua(c, root .. "/ability_names.lua")
|
||||
Pokemon._speciesMeta = load_lua(c, root .. "/meta.lua")
|
||||
Pokemon._moveNames = load_lua(c, root .. "/move_names.lua")
|
||||
Pokemon._romMoveNames = copy_names(Pokemon._moveNames)
|
||||
Pokemon._romAbilityNames = copy_names(Pokemon._abilityNames)
|
||||
Pokemon._learnsets = load_lua(c, root .. "/learnsets.lua")
|
||||
Pokemon._eggMoves = load_lua(c, root .. "/egg_moves.lua")
|
||||
Pokemon._evolutions = load_lua(c, root .. "/evolutions.lua")
|
||||
@@ -206,6 +222,8 @@ function Pokemon.invalidate()
|
||||
Pokemon._abilityNames = nil
|
||||
Pokemon._speciesMeta = nil
|
||||
Pokemon._moveNames = nil
|
||||
Pokemon._romMoveNames = nil
|
||||
Pokemon._romAbilityNames = nil
|
||||
Pokemon._learnsets = nil
|
||||
Pokemon._eggMoves = nil
|
||||
Pokemon._evolutions = nil
|
||||
@@ -471,6 +489,22 @@ function Pokemon.applyStats(mon)
|
||||
return mon
|
||||
end
|
||||
|
||||
-- The ROM's English name for a move or ability number, whatever a mod renamed
|
||||
-- it to; nil when the pack has none.
|
||||
function Pokemon.romMoveName(num)
|
||||
num = tonumber(num)
|
||||
if not num then return nil end
|
||||
if not Pokemon._moveNames then Pokemon.install(Pokemon._cache) end
|
||||
return Pokemon._romMoveNames and Pokemon._romMoveNames[num]
|
||||
end
|
||||
|
||||
function Pokemon.romAbilityName(abilityId)
|
||||
abilityId = tonumber(abilityId)
|
||||
if not abilityId then return nil end
|
||||
if not Pokemon._abilityNames then Pokemon.install(Pokemon._cache) end
|
||||
return Pokemon._romAbilityNames and Pokemon._romAbilityNames[abilityId]
|
||||
end
|
||||
|
||||
function Pokemon.moveName(moveId)
|
||||
if type(moveId) == "table" then
|
||||
moveId = moveId.id or moveId.move or moveId.moveId or moveId.num or moveId.name or moveId[1]
|
||||
|
||||
@@ -307,8 +307,19 @@ local function get_descriptions()
|
||||
return _descs
|
||||
end
|
||||
|
||||
-- Descriptions are keyed by the English name. A translation mod renames
|
||||
-- moves and abilities, so the name the caller shows is looked past: the ROM's
|
||||
-- own name for that number is what the key was built from.
|
||||
local function rom_name(field, id, shown)
|
||||
local Pokemon = package.loaded["src.core.game3.pokemon"]
|
||||
local english = type(Pokemon) == "table" and Pokemon._cache and Pokemon[field]
|
||||
and Pokemon[field](id)
|
||||
return english or shown
|
||||
end
|
||||
|
||||
function SummaryData.abilityDescription(abilityId, abilityName)
|
||||
local d = get_descriptions()
|
||||
abilityName = rom_name("romAbilityName", abilityId, abilityName)
|
||||
if d and d.ABILITIES and abilityName then
|
||||
local const = "ABILITY_" .. abilityName:upper():gsub("%s+", "_"):gsub("[^%w_]", "")
|
||||
if d.ABILITIES[const] then
|
||||
@@ -320,6 +331,7 @@ end
|
||||
|
||||
function SummaryData.moveDescription(moveId, moveName)
|
||||
local d = get_descriptions()
|
||||
moveName = rom_name("romMoveName", moveId, moveName)
|
||||
if d and d.MOVES and moveName then
|
||||
local const = "MOVE_" .. moveName:upper():gsub("%s+", "_"):gsub("[^%w_]", "")
|
||||
if d.MOVES[const] then
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env luajit
|
||||
-- The summary's move and ability descriptions are keyed by the English name.
|
||||
-- A translation mod renames moves and abilities in place, so the lookup has
|
||||
-- to go through the ROM's own name for the number, not the name on screen.
|
||||
|
||||
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 Pokemon = require("src.core.game3.pokemon")
|
||||
local SummaryData = require("src.core.game3.summary_data")
|
||||
|
||||
-- An installed pack a mod has renamed entries of, as Gen3Compat leaves it.
|
||||
Pokemon._cache = {}
|
||||
Pokemon._moveNames = { [71] = "VOL-VIE" }
|
||||
Pokemon._abilityNames = { [9] = "STATIK" }
|
||||
Pokemon._romMoveNames = { [71] = "ABSORB" }
|
||||
Pokemon._romAbilityNames = { [9] = "STATIC" }
|
||||
|
||||
check(SummaryData.moveDescription(71, "VOL-VIE"):find("absorbs half", 1, true) ~= nil,
|
||||
"a renamed move still finds its description")
|
||||
check(SummaryData.abilityDescription(9, "STATIK") == "Paralyzes on contact.",
|
||||
"a renamed ability still finds its description")
|
||||
|
||||
Strings.load({ strings = { ["Paralyzes on contact."] = "Paralyse au contact." } })
|
||||
check(SummaryData.abilityDescription(9, "STATIK") == "Paralyse au contact.",
|
||||
"the description goes through Strings()")
|
||||
Strings.load({})
|
||||
|
||||
Pokemon._romMoveNames = nil
|
||||
check(SummaryData.moveDescription(71, "ABSORB"):find("absorbs half", 1, true) ~= nil,
|
||||
"without the ROM names, the name passed in is used")
|
||||
|
||||
print(("game3_summary_description_test: %s (%d failed)"):format(failed == 0 and "PASS" or "FAIL", failed))
|
||||
if failed > 0 then os.exit(1) end
|
||||
Reference in New Issue
Block a user