From c23f85cba92b23daff0910e5cf82013787bd13cc Mon Sep 17 00:00:00 2001 From: sanjinpepic Date: Sun, 16 Aug 2026 20:21:47 +0200 Subject: [PATCH] Bind gen2Constants in the save editor's Gold bootstrap bindGoldData points gen2Palettes, gen2Icons, gen2Pokedex, gen2Landmarks, gen2Roofs and gen2Sprites at the extractor's own Gold tables through loadGen, but never gen2Constants -- despite Schemas.GEN2 routing `constants` to that same namespaced-and-differently-shaped category palettes and icons are in. A save editor boot left data.gen2Constants unset, so mod.content.constants:get(...) read an empty table instead of the cart's ordered name lists, misreading the generation and rejecting every record a mod shaped off it. data.gen2Constants now goes through the same loadGen("constants") path the other five already use, falling back the same way they do when no ROM cache is active. --- tests/save_editor_gen2_tests.lua | 17 +++++++++++++++++ tools/save-editor/Gen.lua | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/tests/save_editor_gen2_tests.lua b/tests/save_editor_gen2_tests.lua index 365ec70e..db9474d8 100644 --- a/tests/save_editor_gen2_tests.lua +++ b/tests/save_editor_gen2_tests.lua @@ -324,6 +324,23 @@ do check(bound.gen2Tilesets == bound.tilesets, "bindGoldData aliases gen2Tilesets") check(Gen.tilesets({ gen2Tilesets = { TILESET_GYM = true } }).TILESET_GYM, "Gen.tilesets prefers gen2Tilesets") + + -- bindGoldData bound gen2Palettes/gen2Icons/gen2Pokedex/gen2Landmarks/ + -- gen2Roofs/gen2Sprites through loadGen but never gen2Constants, so any + -- mod reading mod.content.constants:get(...) under a save-editor Gold + -- bootstrap saw an empty table where it expected the cart's ordered name + -- lists. loadGen falls back to require("data.generated.constants") when + -- the ROM cache has nothing active, which is what a checkout with no + -- ROM imported hits too -- stub that module the same way to prove the + -- wiring without needing a real Gold extraction. + package.loaded["data.generated.constants"] = { badges = { "ZEPHYR" } } + local withConstants = Gen.bindGoldData({}) + package.loaded["data.generated.constants"] = nil + check(withConstants.gen2Constants ~= nil, + "bindGoldData populates gen2Constants") + check(withConstants.gen2Constants and withConstants.gen2Constants.badges + and withConstants.gen2Constants.badges[1] == "ZEPHYR", + "gen2Constants carries the extractor's own name lists") end do diff --git a/tools/save-editor/Gen.lua b/tools/save-editor/Gen.lua index 695aa9b8..56258a85 100644 --- a/tools/save-editor/Gen.lua +++ b/tools/save-editor/Gen.lua @@ -95,6 +95,12 @@ function Gen.bindGoldData(data) end data.gen2Palettes = data.gen2Palettes or loadGen("palettes") + -- Namespaced AND differently shaped in Schemas.GEN2 (the cart's ordered + -- name lists, not Gen 1's rule table), same as palettes/icons below -- + -- omitting it left mod.content.constants:get(...) reading an empty table + -- under a Gold save-editor boot, which is what misreads "generation" and + -- rejects every record a mod shapes off it. + data.gen2Constants = data.gen2Constants or loadGen("constants") data.gen2Icons = data.gen2Icons or loadGen("icons") data.gen2Pokedex = data.gen2Pokedex or loadGen("pokedex") data.gen2Landmarks = data.gen2Landmarks or loadGen("landmarks")