mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-10-08 09:42:55 -04:00
Merge pull request #2747 from thibautbus/feat/metric-pokedex-units
Print Pokédex heights and weights in metric units when a mod gives them
This commit is contained in:
@@ -941,6 +941,7 @@ do not.
|
||||
| `catchRate` | integer 0..255 | yes |
|
||||
| `cry` | cries id | no |
|
||||
| `dex` | integer >= 1 | yes |
|
||||
| `dexEntry` | {heightM?, kind?, text?, text2?, weightKg?} | no |
|
||||
| `eggGroups` | list of string | no |
|
||||
| `eggGroupsRaw` | integer 0..255 | no |
|
||||
| `eggMoves` | list of moves id | no |
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
local Strings = require("src.core.Strings")
|
||||
|
||||
local Units = {}
|
||||
|
||||
function Units.metric(species)
|
||||
local Pokemon = require("src.core.game3.pokemon")
|
||||
if Pokemon._dex == nil then return nil end
|
||||
local ok, entry = pcall(Pokemon.dexEntry, species)
|
||||
if ok and type(entry) == "table" and entry.heightM and entry.weightKg then return entry end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function decimal(value, pad)
|
||||
local text = (("%.1f"):format(value or 0):gsub("%.", ","))
|
||||
return string.rep(pad or " ", math.max(0, 5 - #text)) .. text
|
||||
end
|
||||
|
||||
function Units.height(entry, pad)
|
||||
return decimal(entry.heightM, pad) .. " " .. Strings("m")
|
||||
end
|
||||
|
||||
function Units.weight(entry, pad)
|
||||
return decimal(entry.weightKg, pad) .. " " .. Strings("kg")
|
||||
end
|
||||
|
||||
function Units.unknownHeight()
|
||||
return "???,? " .. Strings("m")
|
||||
end
|
||||
|
||||
function Units.unknownWeight()
|
||||
return "???,? " .. Strings("kg")
|
||||
end
|
||||
|
||||
return Units
|
||||
@@ -26,10 +26,13 @@ function PokedexText.apply(data)
|
||||
for species, entry in pairs(dex.entries) do
|
||||
local def = pokemon[species]
|
||||
local override = def and def.dexEntry
|
||||
if override and (override.kind or override.text or override.text2) then
|
||||
if override and (override.kind or override.text or override.text2 or override.heightM) then
|
||||
if override.kind then entry.kind = override.kind end
|
||||
if override.text then entry.text = override.text end
|
||||
if override.text2 then entry.text2 = override.text2 end
|
||||
if override.heightM and override.weightKg then
|
||||
entry.heightM, entry.weightKg = override.heightM, override.weightKg
|
||||
end
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1222,7 +1222,8 @@ local function monRecord(base, id)
|
||||
local entry = national and t.dex and t.dex[national]
|
||||
if entry then
|
||||
record.dexEntry = { kind = entry.category or "", height = entry.height or 0,
|
||||
weight = entry.weight or 0 }
|
||||
weight = entry.weight or 0, heightM = entry.heightM,
|
||||
weightKg = entry.weightKg }
|
||||
end
|
||||
return record
|
||||
end
|
||||
@@ -1346,6 +1347,8 @@ local function writeMon(target, t, num, value)
|
||||
category = value.dexEntry.kind or old.category,
|
||||
height = value.dexEntry.height or old.height,
|
||||
weight = value.dexEntry.weight or old.weight,
|
||||
heightM = value.dexEntry.heightM or old.heightM,
|
||||
weightKg = value.dexEntry.weightKg or old.weightKg,
|
||||
}
|
||||
end
|
||||
local sprites = sideTable(target, "spriteOverrides")
|
||||
@@ -1809,6 +1812,9 @@ R.pokemon = {
|
||||
genderRatio = f.opt(f.int(0, 255)),
|
||||
-- the two wild held items, in the ROM's own order (rare then common)
|
||||
items = f.opt(f.list(f.id("items"))),
|
||||
dexEntry = f.opt(f.rec{ kind = f.opt(f.str), text = f.opt(f.str),
|
||||
text2 = f.opt(f.str), heightM = f.opt(f.num),
|
||||
weightKg = f.opt(f.num) }),
|
||||
spriteFront = f.path, spriteBack = f.path, picSize = f.int(1, 7),
|
||||
source = f.opt(f.str),
|
||||
cry = f.opt(f.id("cries")), trueColor = f.opt(f.bool),
|
||||
@@ -1844,7 +1850,8 @@ R.pokemon = {
|
||||
item = f.opt(f.id("items")),
|
||||
param = f.opt(f.int(0)) }),
|
||||
dexEntry = f.opt(f.rec{ kind = f.str, height = f.int(0),
|
||||
weight = f.int(0) }),
|
||||
weight = f.int(0), heightM = f.opt(f.num),
|
||||
weightKg = f.opt(f.num) }),
|
||||
spriteFront = f.path, spriteBack = f.path,
|
||||
trueColor = f.opt(f.bool),
|
||||
},
|
||||
|
||||
@@ -145,6 +145,7 @@ function DexEntryMenu.new(game, speciesOrOpts, onDone)
|
||||
self.pageCount = pages and #pages or 1
|
||||
self.species = species
|
||||
self.picDelay = PIC_DELAY
|
||||
self.metricMasks = { Strings("GR. ???m"), Strings("GEW. ???kg") }
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -187,7 +188,7 @@ function DexEntryMenu:draw()
|
||||
DexEntryMenu.render(self.game, self.def, not waiting and self.sprite or nil,
|
||||
self.forceOwned, self.spriteTrueColor, self.page,
|
||||
{ crying = self:crying(), waiting = waiting,
|
||||
arrow = (self.blink or 0) < 30 })
|
||||
arrow = (self.blink or 0) < 30, metricMasks = self.metricMasks })
|
||||
end
|
||||
|
||||
-- Static entry-page renderer, shared with the printer stand-in
|
||||
@@ -261,6 +262,10 @@ function DexEntryMenu.render(game, def, sprite, forceOwned, trueColor, page, sta
|
||||
Font.draw("??", 120, 48)
|
||||
Font.draw("???", 112, 64)
|
||||
end
|
||||
elseif not numbers or state.crying or state.waiting then
|
||||
local masks = state.metricMasks or { Strings("GR. ???m"), Strings("GEW. ???kg") }
|
||||
Font.draw(masks[1], 72, 48)
|
||||
Font.draw(masks[2], 72, 64)
|
||||
end
|
||||
-- engine/menus/pokedex.asm:516: everything below the divider waits on the
|
||||
-- cry the line above it started
|
||||
|
||||
@@ -239,6 +239,7 @@ function Pokedex.showRegistration(speciesId, opts)
|
||||
opts = opts or {}
|
||||
Pokedex.open = true
|
||||
Pokedex._regSpecies = tonumber(speciesId) or 1
|
||||
Pokedex._unitTexts = nil
|
||||
Pokedex.selectedSpecies = Pokedex._regSpecies
|
||||
Pokedex._session = opts.session
|
||||
Pokedex._dex = (opts.session and opts.session.dex) or Dex.new()
|
||||
@@ -269,6 +270,7 @@ end
|
||||
|
||||
-- pokedex_screen.c
|
||||
function Pokedex.resetScreenState()
|
||||
Pokedex._unitTexts = nil
|
||||
Pokedex.screen = "mode_select"
|
||||
Pokedex.subScreenPrev = "mode_select"
|
||||
Pokedex.modeCursor = 2
|
||||
@@ -856,6 +858,20 @@ function Pokedex.controlInfoForDataPage(screen)
|
||||
return RomText.plain("gText_Cry"), RomText.plain("gText_NextDataCancel")
|
||||
end
|
||||
|
||||
local function unitTexts(sp, caught)
|
||||
local memo = Pokedex._unitTexts
|
||||
if memo and memo.sp == sp and memo.caught == caught then return memo end
|
||||
local Units = require("src.core.game3.pokedex_units")
|
||||
local metric = Units.metric(sp)
|
||||
memo = { sp = sp, caught = caught }
|
||||
if metric then
|
||||
memo.height = caught and Units.height(metric) or Units.unknownHeight()
|
||||
memo.weight = caught and Units.weight(metric) or Units.unknownWeight()
|
||||
end
|
||||
Pokedex._unitTexts = memo
|
||||
return memo
|
||||
end
|
||||
|
||||
--- 3. Detailed Data Entry Screen (Page 1: Specs & Flavor Text, Page 2: Size Chart & Area Map)
|
||||
local function draw_data_screen()
|
||||
local dex = Pokedex._dex
|
||||
@@ -903,13 +919,14 @@ local function draw_data_screen()
|
||||
|
||||
-- Line 3 (y = 60): HT in FONT_SMALL at x=16; Height value at x=46
|
||||
FrlgFont.draw(RomText.plain("gText_HT"), 16, 60, { small = true, colors = upperColors })
|
||||
local htStr = isCaught and (entry.heightFormatted or " ??'??\"") or " ??'??\""
|
||||
local units = unitTexts(sp, isCaught)
|
||||
local htStr = units.height or (isCaught and (entry.heightFormatted or " ??'??\"") or " ??'??\"")
|
||||
FrlgFont.draw(htStr, 46, 60, { small = true, colors = upperColors })
|
||||
|
||||
-- Line 4 (y = 72): WT in FONT_SMALL at x=16; Weight value at x=46
|
||||
FrlgFont.draw(RomText.plain("gText_WT"), 16, 72, { small = true, colors = upperColors })
|
||||
-- src/pokedex_screen.c:2834
|
||||
local wtStr = isCaught and entry.weightFormatted or ("????.? " .. RomText.plain("gText_Lbs"))
|
||||
local wtStr = units.weight or (isCaught and entry.weightFormatted or ("????.? " .. RomText.plain("gText_Lbs")))
|
||||
FrlgFont.draw(wtStr, 46, 72, { small = true, colors = upperColors })
|
||||
|
||||
-- Footprint (16x16) at screen x=104, y=64 (window x=88, y=40)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local Kit = require("src.ui.game3.rse.scene_kit")
|
||||
local Strings = require("src.core.Strings")
|
||||
local Units = require("src.core.game3.pokedex_units")
|
||||
local FrlgFont = require("src.ui.game3.frlg_font")
|
||||
local RomText = require("src.core.game3.rom_text")
|
||||
local Pal = require("src.core.game3.pal_fade")
|
||||
@@ -946,8 +947,9 @@ local function monInfo(s, nat, nationalNumber, owned, newEntry)
|
||||
local category = owned and (Strings(e.category or "") .. categorySuffix(unknown)) or unknown
|
||||
local cx = 88 + (owned and (FrlgFont.measure(unknown) - FrlgFont.measure(category)) or 0)
|
||||
out[#out + 1] = {text = category, x = cx, y = 40}
|
||||
out[#out + 1] = {text = owned and Pokedex.heightText(e.height or 0) or rsString("UnknownHeight"), x = 128, y = 56}
|
||||
out[#out + 1] = {text = owned and RsPolicy.weightText(e.weight or 0) or rsString("UnknownWeight"), x = 128, y = 72}
|
||||
local metric = owned and Units.metric(Pokedex.speciesOf(nat))
|
||||
out[#out + 1] = {text = metric and Units.height(metric, " ") or owned and Pokedex.heightText(e.height or 0) or rsString("UnknownHeight"), x = 128, y = 56}
|
||||
out[#out + 1] = {text = metric and Units.weight(metric, " ") or owned and RsPolicy.weightText(e.weight or 0) or rsString("UnknownWeight"), x = 128, y = 72}
|
||||
local desc
|
||||
if s.descriptionPage == 1 then
|
||||
desc = cached(e.descriptionLabel2, e.description2)
|
||||
@@ -975,7 +977,11 @@ local function monInfo(s, nat, nationalNumber, owned, newEntry)
|
||||
out[#out + 1] = { text = category, x = 0x64, y = 0x29 }
|
||||
out[#out + 1] = { text = RomText.plain("gText_HTHeight"), x = 0x60, y = 0x39 }
|
||||
out[#out + 1] = { text = RomText.plain("gText_WTWeight"), x = 0x60, y = 0x49 }
|
||||
if owned then
|
||||
local metric = owned and Units.metric(sp)
|
||||
if metric then
|
||||
out[#out + 1] = { text = Units.height(metric, "{UNK_SPACER}"), x = 0x81, y = 0x39 }
|
||||
out[#out + 1] = { text = Units.weight(metric, "{UNK_SPACER}"), x = 0x81, y = 0x49 }
|
||||
elseif owned then
|
||||
out[#out + 1] = { text = Pokedex.heightText(e.height or 0), x = 0x81, y = 0x39 }
|
||||
out[#out + 1] = { text = Pokedex.weightText(e.weight or 0), x = 0x81, y = 0x49 }
|
||||
else
|
||||
|
||||
+42
-20
@@ -64,6 +64,8 @@ local CANCEL_LABEL = Strings.source("CANCEL")
|
||||
local NO_SEARCH_RESULTS = Strings.source("No <PK><MN> found!")
|
||||
local ENTRY_ACTION_LABEL = Strings.source(" PAGE AREA CRY PRNT")
|
||||
local POUND_LABEL = Strings.source("lb")
|
||||
local METRE_LABEL = Strings.source("m")
|
||||
local KILOGRAM_LABEL = Strings.source("kg")
|
||||
local NEST_TITLE = Strings.source("%s'S NEST")
|
||||
|
||||
local LIST_DIRS = { "up", "down" }
|
||||
@@ -173,6 +175,7 @@ function PokedexMenu.new(game, opts)
|
||||
local self = setmetatable({}, PokedexMenu)
|
||||
self.game = game
|
||||
self.save = opts.save or (game and game.save)
|
||||
self.metricLabels = { Strings(METRE_LABEL), Strings(KILOGRAM_LABEL) }
|
||||
local data = game and game.data or {}
|
||||
-- engine/pokedex/pokedex.asm:447
|
||||
self.data = data
|
||||
@@ -641,6 +644,10 @@ function PokedexMenu:border(tx, ty, interiorRows, interiorCols)
|
||||
self:tile(B.bottomRight, tx + interiorCols + 1, bottom)
|
||||
end
|
||||
|
||||
local function metricString(value)
|
||||
return (("%.1f"):format(value or 0):gsub("%.", ","))
|
||||
end
|
||||
|
||||
-- PrintNum: a right-aligned field of `digits` characters, space-padded unless
|
||||
-- PRINTNUM_LEADINGZEROS was set. `before` splits the field into an integer
|
||||
-- part and a fraction with a '.' between them.
|
||||
@@ -1041,26 +1048,36 @@ function PokedexMenu:drawEntryBody(row, entry)
|
||||
-- "HT ?'??"" at (9,7) and "WT ???lb" at (9,9).
|
||||
self:text(Strings(HEIGHT_LABEL), 9, 7)
|
||||
self:text(Strings(WEIGHT_LABEL), 9, 9)
|
||||
self:tile(TILE_FOOT, 14, 7)
|
||||
self:text(Strings(POUND_LABEL), 17, 9)
|
||||
if entry.heightM then
|
||||
self:text(self.metricLabels[1], 17, 7)
|
||||
self:text(self.metricLabels[2], 17, 9)
|
||||
local height = row.caught and metricString(entry.heightM) or "???"
|
||||
local weight = row.caught and metricString(entry.weightKg) or "???"
|
||||
self:text(height, 17 - #height, 7)
|
||||
self:text(weight, 17 - #weight, 9)
|
||||
if not row.caught then return end
|
||||
else
|
||||
self:tile(TILE_FOOT, 14, 7)
|
||||
self:text(Strings(POUND_LABEL), 17, 9)
|
||||
|
||||
if not row.caught then
|
||||
self:text(" ?", 11, 7)
|
||||
self:text("??", 15, 7)
|
||||
if not row.caught then
|
||||
self:text(" ?", 11, 7)
|
||||
self:text("??", 15, 7)
|
||||
self:tile(TILE_INCH, 17, 7)
|
||||
self:text(" ???", 11, 9)
|
||||
return
|
||||
end
|
||||
|
||||
-- The height word is four digits with two in front of the point and the
|
||||
-- point replaced by the foot mark; the weight word is five with four in
|
||||
-- front. Both are already the digits the cart prints.
|
||||
local height = printNumString(entry.height or 0, 4, false, 2)
|
||||
self:text(height:sub(1, 2), 12, 7)
|
||||
self:text(height:sub(4), 15, 7)
|
||||
self:tile(TILE_INCH, 17, 7)
|
||||
self:text(" ???", 11, 9)
|
||||
return
|
||||
self:text(printNumString(entry.weight or 0, 5, false, 4), 11, 9)
|
||||
end
|
||||
|
||||
-- The height word is four digits with two in front of the point and the
|
||||
-- point replaced by the foot mark; the weight word is five with four in
|
||||
-- front. Both are already the digits the cart prints.
|
||||
local height = printNumString(entry.height or 0, 4, false, 2)
|
||||
self:text(height:sub(1, 2), 12, 7)
|
||||
self:text(height:sub(4), 15, 7)
|
||||
self:tile(TILE_INCH, 17, 7)
|
||||
self:text(printNumString(entry.weight or 0, 5, false, 4), 11, 9)
|
||||
|
||||
-- Page marker, then the description. ClearBox(2,11) is 5 rows by 18
|
||||
-- columns and <NEXT> steps two rows, so the three lines land on 11/13/15.
|
||||
self:tile(TILE_PAGE_TOP, 1, 9)
|
||||
@@ -1114,10 +1131,15 @@ function PokedexMenu:drawPlain()
|
||||
Chrome.print(("%s %s"):format(
|
||||
Chrome.number(entry.dex or 0, 3, true), self:monName(row.species)), 1, 1)
|
||||
Chrome.print(entry.kind or "", 1, 3)
|
||||
Chrome.print(Strings(HEIGHT_LABEL) .. " "
|
||||
.. printNumString(entry.height or 0, 4, false, 2), 1, 5)
|
||||
Chrome.print(Strings(WEIGHT_LABEL) .. " "
|
||||
.. printNumString(entry.weight or 0, 5, false, 4), 1, 7)
|
||||
if entry.heightM then
|
||||
Chrome.print(Strings(HEIGHT_LABEL) .. " " .. metricString(entry.heightM) .. self.metricLabels[1], 1, 5)
|
||||
Chrome.print(Strings(WEIGHT_LABEL) .. " " .. metricString(entry.weightKg) .. self.metricLabels[2], 1, 7)
|
||||
else
|
||||
Chrome.print(Strings(HEIGHT_LABEL) .. " "
|
||||
.. printNumString(entry.height or 0, 4, false, 2), 1, 5)
|
||||
Chrome.print(Strings(WEIGHT_LABEL) .. " "
|
||||
.. printNumString(entry.weight or 0, 5, false, 4), 1, 7)
|
||||
end
|
||||
self:drawPic(row, 12, 1, true)
|
||||
Chrome.box(0, 10, 20, 8)
|
||||
local ty = 11
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env luajit
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
_G.love = _G.love or require("tests.love_stub")
|
||||
|
||||
local T = require("tests.harness")
|
||||
local check = T.check
|
||||
|
||||
T.suite("game3 pokedex metric units")
|
||||
|
||||
local Schemas = require("src.mods.Schemas")
|
||||
local target = { _names = { [1] = "BULBASAUR" }, _dex = { [1] = { category = "SEED", height = 7, weight = 69 } } }
|
||||
local patched = { dexEntry = { kind = "SEED", height = 7, weight = 69, heightM = 0.7, weightKg = 6.9 } }
|
||||
Schemas.gen3View.monWrite(target, { ops = { BULBASAUR = true }, get = function() return patched end })
|
||||
local row = target._dex[1]
|
||||
check(row.heightM == 0.7 and row.weightKg == 6.9 and row.height == 7 and row.category == "SEED",
|
||||
"a patch's metric values reach the dex table beside the cart's")
|
||||
|
||||
local DEX = { [252] = { category = "WOOD GECKO", height = 5, weight = 50, heightM = 0.5, weightKg = 5 },
|
||||
[253] = { category = "WOOD GECKO", height = 9, weight = 216 } }
|
||||
package.loaded["src.core.game3.pokemon"] = { _dex = DEX,
|
||||
dexEntry = function(species) return DEX[species] end,
|
||||
name = function() return "TREECKO" end,
|
||||
speciesFromNational = function(nat) return nat end,
|
||||
}
|
||||
|
||||
local Units = require("src.core.game3.pokedex_units")
|
||||
check(Units.metric(252) == DEX[252] and Units.metric(253) == nil, "only a species with metric values is metric")
|
||||
check(Units.height(DEX[252]) == " 0,5 m" and Units.weight(DEX[252]) == " 5,0 kg",
|
||||
"a metric height and weight print with one decimal and a comma")
|
||||
check(Units.weight({ weightKg = 950 }) == "950,0 kg", "a three-digit weight fills the field")
|
||||
check(Units.unknownHeight() == "???,? m" and Units.unknownWeight() == "???,? kg", "the unknown masks")
|
||||
|
||||
local MANIFEST = { assetLayout = "emerald", tenDashes = "----------",
|
||||
strings = { UnknownPoke = "?????POKéMON", UnknownHeight = "??'??\"", UnknownWeight = "????.? lbs." } }
|
||||
package.loaded["src.ui.game3.rse.pokedex_gfx"] = setmetatable({ manifest = function() return MANIFEST end },
|
||||
{ __index = function() return function() end end })
|
||||
package.loaded["src.ui.game3.rse.mapsec"] = setmetatable({ readLua = function(path)
|
||||
if path:find("entries", 1, true) then return DEX end
|
||||
return { nationalToRegional = {} }
|
||||
end }, { __index = function() return function() end end })
|
||||
local BUNDLE = { text = {} }
|
||||
package.loaded["src.core.game3.scripting.space"] = { ensureBundle = function() return BUNDLE end }
|
||||
local Pokedex = require("src.ui.game3.rse.pokedex")
|
||||
local function rows(nat, owned)
|
||||
local out = {}
|
||||
for _, r in ipairs(Pokedex.monInfo({ descriptionPage = 0 }, nat, true, owned, false)) do out[#out + 1] = r.text end
|
||||
return table.concat(out, "|")
|
||||
end
|
||||
MANIFEST.assetLayout = "rs"
|
||||
check(rows(252, true):find("| 0,5 m| 5,0 kg|", 1, true) ~= nil,
|
||||
"a caught Ruby/Sapphire entry prints its metric values, two spaces per missing digit")
|
||||
check(rows(253, true):find("lbs.", 1, true) ~= nil, "a Ruby/Sapphire entry without metric values keeps the US ones")
|
||||
check(rows(252, false):find("????.? lbs.", 1, true) ~= nil, "a seen Ruby/Sapphire entry keeps the cart's unknown rows")
|
||||
|
||||
local function ir(text) return { { t = "text", s = text }, { t = "eos" } } end
|
||||
BUNDLE.text = { gText_Pokemon = ir("POKéMON"), gText_5MarksPokemon = ir("?????POKéMON"), gText_NumberClear01 = ir("No. "),
|
||||
gText_HTHeight = ir("HT"), gText_WTWeight = ir("WT"),
|
||||
gText_UnkHeight = ir("???,? m"), gText_UnkWeight = ir("???,? kg") }
|
||||
MANIFEST.assetLayout = "emerald"
|
||||
check(rows(252, true):find("{UNK_SPACER}{UNK_SPACER}0,5 m|{UNK_SPACER}{UNK_SPACER}5,0 kg", 1, true) ~= nil,
|
||||
"a caught Emerald entry prints its metric values aligned with the digit spacer")
|
||||
check(rows(253, true):find("lbs.", 1, true) ~= nil, "an Emerald entry without metric values keeps the US ones")
|
||||
check(rows(252, false):find("???,? m|???,? kg", 1, true) ~= nil, "a seen Emerald entry prints the cart's unknown rows")
|
||||
|
||||
T.finish("game3 pokedex metric units")
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env luajit
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
_G.love = _G.love or require("tests.love_stub")
|
||||
|
||||
local T = require("tests.harness")
|
||||
local check = T.check
|
||||
|
||||
T.suite("pokedex metric units")
|
||||
|
||||
local Font = require("src.render.Font")
|
||||
local drawn
|
||||
local fontDraw = Font.draw
|
||||
Font.draw = function(text) drawn[#drawn + 1] = tostring(text) end
|
||||
local function has(text)
|
||||
for _, value in ipairs(drawn) do if value == text then return true end end
|
||||
return false
|
||||
end
|
||||
|
||||
local DexEntryMenu = require("src.ui.DexEntryMenu")
|
||||
local game = { save = { pokedex = { owned = {} } }, data = { text = {}, constants = {} } }
|
||||
local metric = { id = "BULBASAUR", name = "BULBASAUR", dex = 1,
|
||||
dexEntry = { kind = "SEED", heightFt = 2, heightIn = 4, weight = 152, heightM = 0.7, weightKg = 6.9 } }
|
||||
local imperial = { id = "BULBASAUR", name = "BULBASAUR", dex = 1,
|
||||
dexEntry = { kind = "SEED", heightFt = 2, heightIn = 4, weight = 152 } }
|
||||
|
||||
drawn = {}
|
||||
DexEntryMenu.render(game, metric, nil, true)
|
||||
check(has("GR. 0,7m") and has("GEW. 6,9kg"), "a caught Gen 1 entry prints its metric height and weight")
|
||||
drawn = {}
|
||||
DexEntryMenu.render(game, metric, nil, false)
|
||||
check(has("GR. ???m") and has("GEW. ???kg"), "a seen Gen 1 entry prints the metric unknown masks")
|
||||
check(not has("lb") and not has("???"), "a metric Gen 1 entry prints no imperial field")
|
||||
drawn = {}
|
||||
DexEntryMenu.render(game, metric, nil, false, nil, 1, { metricMasks = { "TAI ???m", "PDS ???kg" } })
|
||||
check(has("TAI ???m") and has("PDS ???kg"), "the entry page prints the masks it resolved when it opened")
|
||||
drawn = {}
|
||||
DexEntryMenu.render(game, imperial, nil, false)
|
||||
check(has("???") and has("lb") and not has("GR. ???m"), "an entry without metric values keeps the US fields")
|
||||
|
||||
Font.draw = fontDraw
|
||||
|
||||
local PokedexText = require("src.core.gen2.PokedexText")
|
||||
local data = {
|
||||
gen2Pokedex = { entries = { CHIKORITA = { dex = 152, kind = "LEAF", height = 211, weight = 141 } } },
|
||||
pokemon = { CHIKORITA = { dexEntry = { heightM = 0.9, weightKg = 6.4 } } },
|
||||
}
|
||||
PokedexText.apply(data)
|
||||
local entry = data.gen2Pokedex.entries.CHIKORITA
|
||||
check(entry.heightM == 0.9 and entry.weightKg == 6.4 and entry.height == 211,
|
||||
"a mod's metric values reach the #DEX entry beside the US cart's")
|
||||
|
||||
local PokedexMenu = require("src.ui.gen2.PokedexMenu")
|
||||
local texts, tiles
|
||||
local menu = setmetatable({ page = 1, metricLabels = { "m", "kg" } }, { __index = PokedexMenu })
|
||||
function menu:text(str, tx, ty) texts[#texts + 1] = { tostring(str), tx, ty } end
|
||||
function menu:tile(id, tx, ty) tiles[#tiles + 1] = { id, tx, ty } end
|
||||
for _, name in ipairs({ "fill", "border", "blank", "drawPic", "drawFootprint" }) do menu[name] = function() end end
|
||||
function menu:cursorVisible() return false end
|
||||
function menu:monName() return "CHIKORITA" end
|
||||
local function at(str, tx, ty)
|
||||
for _, t in ipairs(texts) do if t[1] == str and t[2] == tx and t[3] == ty then return true end end
|
||||
return false
|
||||
end
|
||||
texts, tiles = {}, {}
|
||||
menu:drawEntryBody({ species = "CHIKORITA", caught = true }, entry)
|
||||
check(at("0,9", 14, 7) and at("m", 17, 7) and at("6,4", 14, 9) and at("kg", 17, 9),
|
||||
"a caught Gen 2 entry prints its metric height and weight right-aligned before the unit")
|
||||
local footTile = false
|
||||
for _, t in ipairs(tiles) do if t[2] == 14 and t[3] == 7 then footTile = true end end
|
||||
check(not footTile and not at("lb", 17, 9), "a metric Gen 2 entry prints neither the foot mark nor the pound label")
|
||||
texts, tiles = {}, {}
|
||||
menu:drawEntryBody({ species = "CHIKORITA", caught = false }, entry)
|
||||
check(at("???", 14, 7) and at("???", 14, 9), "a seen Gen 2 entry prints the metric unknown masks")
|
||||
texts, tiles = {}, {}
|
||||
menu:drawEntryBody({ species = "CHIKORITA", caught = true },
|
||||
{ dex = 152, kind = "LEAF", height = 211, weight = 141 })
|
||||
check(at("lb", 17, 9) and not at("m", 17, 7), "an entry without metric values keeps the US fields")
|
||||
|
||||
T.finish("pokedex metric units")
|
||||
Reference in New Issue
Block a user