From a389416b7b83d23992632d1cb0a9017e6d0e4d6a Mon Sep 17 00:00:00 2001 From: johnjohto Date: Thu, 30 Jul 2026 17:53:53 -0400 Subject: [PATCH] Fix battle menu cursor edges Battle commands toggled directly between rows and columns. An outward press therefore moved the cursor to the opposite command instead of leaving it at the edge. --- src/battle/BattleState.lua | 24 +++++++++----- tests/parity_battle_menu_cursor.lua | 49 +++++++++++++++++++++++++++++ tests/run_tests.lua | 1 + 3 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 tests/parity_battle_menu_cursor.lua diff --git a/src/battle/BattleState.lua b/src/battle/BattleState.lua index a2ae60d5..eaab7b6d 100644 --- a/src/battle/BattleState.lua +++ b/src/battle/BattleState.lua @@ -1507,10 +1507,14 @@ function BattleState:update(dt) end local col = (self.menuIndex - 1) % 2 local row = math.floor((self.menuIndex - 1) / 2) - if input:wasPressed("left") or input:wasPressed("right") then - col = 1 - col - elseif input:wasPressed("up") or input:wasPressed("down") then - row = 1 - row + if input:wasPressed("left") then + col = math.max(0, col - 1) + elseif input:wasPressed("right") then + col = math.min(1, col + 1) + elseif input:wasPressed("up") then + row = math.max(0, row - 1) + elseif input:wasPressed("down") then + row = math.min(1, row + 1) end self.menuIndex = row * 2 + col + 1 if input:wasPressed("a") then @@ -1539,10 +1543,14 @@ function BattleState:update(dt) end local col = (self.menuIndex - 1) % 2 local row = math.floor((self.menuIndex - 1) / 2) - if input:wasPressed("left") or input:wasPressed("right") then - col = 1 - col - elseif input:wasPressed("up") or input:wasPressed("down") then - row = 1 - row + if input:wasPressed("left") then + col = math.max(0, col - 1) + elseif input:wasPressed("right") then + col = math.min(1, col + 1) + elseif input:wasPressed("up") then + row = math.max(0, row - 1) + elseif input:wasPressed("down") then + row = math.min(1, row + 1) end self.menuIndex = row * 2 + col + 1 if input:wasPressed("a") then diff --git a/tests/parity_battle_menu_cursor.lua b/tests/parity_battle_menu_cursor.lua new file mode 100644 index 00000000..398756fa --- /dev/null +++ b/tests/parity_battle_menu_cursor.lua @@ -0,0 +1,49 @@ +-- Parity: the main battle-menu cursor stops at an edge instead of wrapping +-- to the opposite command (#485). +package.path = "./?.lua;./?/init.lua;" .. package.path +if not _G.love then _G.love = require("tests.love_stub") end + +local Data = require("src.core.Data") +if not Data.maps then Data:load() end +local Pokemon = require("src.pokemon.Pokemon") +local SaveData = require("src.core.SaveData") +local BattleState = require("src.battle.BattleState") +local S = require("tests.harness").suite("parity battle menu cursor") +local eq = S.eq + +local pressed = {} +local save = SaveData.newGame() +save.party = { Pokemon.new(Data, "BULBASAUR", 5) } +local game = { + data = Data, + save = save, + input = { wasPressed = function(_, key) return pressed[key] == true end }, + stack = { push = function() end, pop = function() end, top = function() end }, +} +local battle = BattleState.newWild(game, "RATTATA", 2) +battle.phase = "menu" + +local function pressAt(state, index, key) + state.menuIndex = index + pressed[key] = true + state:update(1 / 60) + pressed[key] = nil + return state.menuIndex +end + +eq(pressAt(battle, 1, "left"), 1, "FIGHT stays selected when pressing left") +eq(pressAt(battle, 2, "right"), 2, "PKMN stays selected when pressing right") +eq(pressAt(battle, 1, "up"), 1, "FIGHT stays selected when pressing up") +eq(pressAt(battle, 4, "down"), 4, "RUN stays selected when pressing down") +eq(pressAt(battle, 1, "right"), 2, "FIGHT moves right to PKMN") +eq(pressAt(battle, 1, "down"), 3, "FIGHT moves down to ITEM") + +local safari = BattleState.newWild(game, "RATTATA", 2) +safari:makeSafari({ balls = 30 }) +safari.phase = "menu" +eq(pressAt(safari, 1, "left"), 1, "SAFARI BALL stays selected when pressing left") +eq(pressAt(safari, 2, "right"), 2, "BAIT stays selected when pressing right") +eq(pressAt(safari, 1, "up"), 1, "SAFARI BALL stays selected when pressing up") +eq(pressAt(safari, 4, "down"), 4, "RUN stays selected when pressing down") + +S.finish() diff --git a/tests/run_tests.lua b/tests/run_tests.lua index 1590c258..16233eb8 100644 --- a/tests/run_tests.lua +++ b/tests/run_tests.lua @@ -3274,6 +3274,7 @@ runSuites(orderedGlob("tests/parity_*.lua", { "tests/parity_C.lua", "tests/parity_K.lua", "tests/parity_L.lua", "tests/parity_H.lua", "tests/parity_G.lua", "tests/parity_I_M.lua", "tests/parity_B.lua", "tests/parity_J.lua", "tests/parity_A.lua", + "tests/parity_battle_menu_cursor.lua", "tests/parity_flavor.lua", "tests/parity_trainer_sight.lua", "tests/parity_static.lua", "tests/parity_trashcans.lua", "tests/parity_hof.lua", "tests/parity_trade_gift.lua",