mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-12 16:31:05 +02:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12a04f4188 | |||
| 0fe7a96781 | |||
| a06a49bfed | |||
| 86b90fd4b8 | |||
| 78ac154998 | |||
| bbcaac7b71 | |||
| 54ae20c69b | |||
| 1963a5453e | |||
| 59a383736c | |||
| d377518632 | |||
| f74e21782b | |||
| 7b060c19f4 | |||
| 604b9338f9 | |||
| 92f73d8bed | |||
| e3fcdd0776 |
+37
-14
@@ -18,6 +18,26 @@ local M = {
|
||||
VIRIDIAN_GYM = { city = "VIRIDIAN CITY", leader = "GIOVANNI", badge = "EARTHBADGE" },
|
||||
}
|
||||
|
||||
-- The originals' middle branch shared by every leader's text_asm: beaten
|
||||
-- but EVENT_GOT_TM* unset means the bag was full when the victory script
|
||||
-- ran GiveItem, so talking to the leader re-runs the ReceiveTM script.
|
||||
-- Returns true when the retry took over the talk. A save from before
|
||||
-- #797 already holds the TM without the flag; treat the owned TM as
|
||||
-- received so those saves fall through to the advice text instead of
|
||||
-- collecting a second copy.
|
||||
local function retryTmGive(game, ow, victoryKey, done)
|
||||
local reward = require("data.scripts.victories")[victoryKey]
|
||||
if not (reward and reward.gotFlag) then return false end
|
||||
if game.save.flags[reward.gotFlag] then return false end
|
||||
local owned = game.save.inventory and game.save.inventory[reward.item] or 0
|
||||
if owned > 0 then
|
||||
game.save.flags[reward.gotFlag] = true
|
||||
return false
|
||||
end
|
||||
ow:offerGymTm(reward, done)
|
||||
return true
|
||||
end
|
||||
|
||||
-- scripts/PewterGym.asm PewterGymBrockText (text_asm): CheckEvent
|
||||
-- EVENT_BEAT_BROCK branches his dialogue. Before the badge he prints
|
||||
-- _PewterGymBrockPreBattleText and engages the leader battle
|
||||
@@ -25,12 +45,14 @@ local M = {
|
||||
-- badge/TM34 rewards and EVENT_BEAT_BROCK come from
|
||||
-- data/scripts/victories.lua OPP_BROCK#1). After the badge his
|
||||
-- .afterBeat branch prints _PewterGymBrockPostBattleAdviceText ("Go to
|
||||
-- the GYM in CERULEAN..."). The original's middle branch (beat but
|
||||
-- TM34 not yet handed over, CheckEventReuseA EVENT_GOT_TM34) is
|
||||
-- unreachable in the port: the TM is granted with the victory.
|
||||
-- the GYM in CERULEAN..."). The middle branch (beat but TM34 not yet
|
||||
-- handed over, CheckEventReuseA EVENT_GOT_TM34 -> call
|
||||
-- PewterGymScriptReceiveTM34) retries the TM give when the bag was full
|
||||
-- at the victory (#797).
|
||||
M.PEWTER_GYM.talk = {
|
||||
TEXT_PEWTERGYM_BROCK = function(game, ow, npc, done)
|
||||
if game.save.flags.EVENT_BEAT_BROCK then
|
||||
if retryTmGive(game, ow, "OPP_BROCK#1", done) then return end
|
||||
local TextBox = require("src.render.TextBox")
|
||||
game.stack:push(TextBox.new(game,
|
||||
game.data.text._PewterGymBrockPostBattleAdviceText
|
||||
@@ -48,16 +70,17 @@ M.PEWTER_GYM.talk = {
|
||||
-- (engageTrainer shows that same pre-battle text via resolveText; the
|
||||
-- badge/TM rewards and the beat flag come from data/scripts/victories.lua)
|
||||
-- -- and once beaten print the post-battle advice text. As with Brock,
|
||||
-- the originals' middle branch (beaten but the TM not yet handed over,
|
||||
-- CheckEventReuseA EVENT_GOT_TM*) is unreachable in the port: the TM is
|
||||
-- granted with the victory.
|
||||
-- the middle branch (beaten but the TM not yet handed over,
|
||||
-- CheckEventReuseA EVENT_GOT_TM*) retries the TM give when the bag was
|
||||
-- full at the victory.
|
||||
-- afterAdvice, when given, takes over `done`: it is handed (game, ow, npc,
|
||||
-- done) and must call done() itself once whatever it's doing (e.g. a fade
|
||||
-- around a HideObject) finishes, rather than having it invoked
|
||||
-- automatically. Only Giovanni's farewell uses this.
|
||||
local function leaderTalk(beatFlag, adviceLabel, fallback, afterAdvice)
|
||||
local function leaderTalk(beatFlag, adviceLabel, fallback, afterAdvice, victoryKey)
|
||||
return function(game, ow, npc, done)
|
||||
if game.save.flags[beatFlag] then
|
||||
if victoryKey and retryTmGive(game, ow, victoryKey, done) then return end
|
||||
local TextBox = require("src.render.TextBox")
|
||||
local finish = done
|
||||
if afterAdvice then
|
||||
@@ -79,42 +102,42 @@ end
|
||||
M.CERULEAN_GYM.talk = {
|
||||
TEXT_CERULEANGYM_MISTY = leaderTalk("EVENT_BEAT_MISTY",
|
||||
"_CeruleanGymMistyTM11ExplanationText",
|
||||
"TM11 teaches\nBUBBLEBEAM!"),
|
||||
"TM11 teaches\nBUBBLEBEAM!", nil, "OPP_MISTY#1"),
|
||||
}
|
||||
|
||||
-- scripts/VermilionGym.asm VermilionGymLTSurgeText .got_tm24_already
|
||||
M.VERMILION_GYM.talk = {
|
||||
TEXT_VERMILIONGYM_LT_SURGE = leaderTalk("EVENT_BEAT_LT_SURGE",
|
||||
"_VermilionGymLTSurgePostBattleAdviceText",
|
||||
"A little word of\nadvice, kid!"),
|
||||
"A little word of\nadvice, kid!", nil, "OPP_LT_SURGE#1"),
|
||||
}
|
||||
|
||||
-- scripts/CeladonGym.asm CeladonGymErikaText .afterBeat
|
||||
M.CELADON_GYM.talk = {
|
||||
TEXT_CELADONGYM_ERIKA = leaderTalk("EVENT_BEAT_ERIKA",
|
||||
"_CeladonGymErikaPostBattleAdviceText",
|
||||
"You are cataloging\nPOKéMON? I must\nsay I'm impressed."),
|
||||
"You are cataloging\nPOKéMON? I must\nsay I'm impressed.", nil, "OPP_ERIKA#1"),
|
||||
}
|
||||
|
||||
-- scripts/FuchsiaGym.asm FuchsiaGymKogaText .afterBeat
|
||||
M.FUCHSIA_GYM.talk = {
|
||||
TEXT_FUCHSIAGYM_KOGA = leaderTalk("EVENT_BEAT_KOGA",
|
||||
"_FuchsiaGymKogaPostBattleAdviceText",
|
||||
"When afflicted by\nTOXIC, POKéMON\nsuffer more and\nmore as battle\nprogresses!"),
|
||||
"When afflicted by\nTOXIC, POKéMON\nsuffer more and\nmore as battle\nprogresses!", nil, "OPP_KOGA#1"),
|
||||
}
|
||||
|
||||
-- scripts/SaffronGym.asm SaffronGymSabrinaText .afterBeat
|
||||
M.SAFFRON_GYM.talk = {
|
||||
TEXT_SAFFRONGYM_SABRINA = leaderTalk("EVENT_BEAT_SABRINA",
|
||||
"_SaffronGymSabrinaPostBattleAdviceText",
|
||||
"Everyone has\npsychic power!\nPeople just don't\nrealize it!"),
|
||||
"Everyone has\npsychic power!\nPeople just don't\nrealize it!", nil, "OPP_SABRINA#1"),
|
||||
}
|
||||
|
||||
-- scripts/CinnabarGym.asm CinnabarGymBlaineText .afterBeat
|
||||
M.CINNABAR_GYM.talk = {
|
||||
TEXT_CINNABARGYM_BLAINE = leaderTalk("EVENT_BEAT_BLAINE",
|
||||
"_CinnabarGymBlainePostBattleAdviceText",
|
||||
"FIRE BLAST is the\nultimate fire\ntechnique!"),
|
||||
"FIRE BLAST is the\nultimate fire\ntechnique!", nil, "OPP_BLAINE#1"),
|
||||
}
|
||||
|
||||
-- scripts/ViridianGym.asm ViridianGymGiovanniText .afterBeat: after the
|
||||
@@ -142,7 +165,7 @@ M.VIRIDIAN_GYM.talk = {
|
||||
"VIRIDIAN_GYM", "VIRIDIANGYM_GIOVANNI")
|
||||
end
|
||||
end, done))
|
||||
end),
|
||||
end, "OPP_GIOVANNI#3"),
|
||||
}
|
||||
|
||||
return M
|
||||
|
||||
@@ -18,6 +18,16 @@
|
||||
-- script). Leaders are not def_trainers entries, so engageTrainer has
|
||||
-- no header.won -- checkVictoryRewards shows this chain instead of a
|
||||
-- synthetic "received badge/TM" stub.
|
||||
--
|
||||
-- Gym entries split the TM hand-over out of `dialogue`, mirroring the
|
||||
-- originals' GiveItem check (`call GiveItem` / `jr nc, .BagFull`):
|
||||
-- `tmPre` is the ReceiveTM script's lead-in (badge info / "Wait! Take
|
||||
-- this!"), shown at the victory and again when a beaten leader retries
|
||||
-- the hand-over; `tmDialogue` shows only when the TM actually goes in
|
||||
-- the bag; `noRoom` is the "make room" line shown instead when the bag
|
||||
-- is full; `gotFlag` (pokered's EVENT_GOT_TM*) is set only on a
|
||||
-- successful give, which is what makes the leader's talk script retry
|
||||
-- later (gyms.lua).
|
||||
|
||||
local function range(prefix, first, last)
|
||||
local t = {}
|
||||
@@ -33,6 +43,8 @@ return {
|
||||
-- escort NPC and the first Route 22 rival stay gone after the badge.
|
||||
["OPP_BROCK#1"] = { badge = "BOULDERBADGE", flag = "EVENT_BEAT_BROCK",
|
||||
item = "TM_BIDE",
|
||||
gotFlag = "EVENT_GOT_TM34",
|
||||
noRoom = "_PewterGymTM34NoRoomText",
|
||||
deactivate = { "EVENT_BEAT_PEWTER_GYM_TRAINER_0" },
|
||||
hide = {
|
||||
{ "PEWTER_CITY", "PEWTERCITY_YOUNGSTER" },
|
||||
@@ -41,69 +53,99 @@ return {
|
||||
dialogue = {
|
||||
"_PewterGymBrockReceivedBoulderBadgeText",
|
||||
"_PewterGymBrockBoulderBadgeInfoText",
|
||||
"_PewterGymBrockWaitTakeThisText",
|
||||
},
|
||||
tmPre = { "_PewterGymBrockWaitTakeThisText" },
|
||||
tmDialogue = {
|
||||
"_PewterGymReceivedTM34Text",
|
||||
"_TM34ExplanationText",
|
||||
} },
|
||||
["OPP_MISTY#1"] = { badge = "CASCADEBADGE", flag = "EVENT_BEAT_MISTY",
|
||||
item = "TM_BUBBLEBEAM",
|
||||
gotFlag = "EVENT_GOT_TM11",
|
||||
noRoom = "_CeruleanGymMistyTM11NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_CERULEAN_GYM_TRAINER_", 0, 1),
|
||||
dialogue = {
|
||||
"_CeruleanGymMistyReceivedCascadeBadgeText",
|
||||
"_CeruleanGymMistyCascadeBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_CeruleanGymMistyCascadeBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_CeruleanGymMistyReceivedTM11Text",
|
||||
} },
|
||||
["OPP_LT_SURGE#1"] = { badge = "THUNDERBADGE", flag = "EVENT_BEAT_LT_SURGE",
|
||||
item = "TM_THUNDERBOLT",
|
||||
gotFlag = "EVENT_GOT_TM24",
|
||||
noRoom = "_VermilionGymLTSurgeTM24NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_VERMILION_GYM_TRAINER_", 0, 2),
|
||||
dialogue = {
|
||||
"_VermilionGymLTSurgeReceivedThunderBadgeText",
|
||||
"_VermilionGymLTSurgeThunderBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_VermilionGymLTSurgeThunderBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_VermilionGymLTSurgeReceivedTM24Text",
|
||||
"_TM24ExplanationText",
|
||||
} },
|
||||
["OPP_ERIKA#1"] = { badge = "RAINBOWBADGE", flag = "EVENT_BEAT_ERIKA",
|
||||
item = "TM_MEGA_DRAIN",
|
||||
gotFlag = "EVENT_GOT_TM21",
|
||||
noRoom = "_CeladonGymTM21NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_CELADON_GYM_TRAINER_", 0, 6),
|
||||
dialogue = {
|
||||
"_CeladonGymErikaReceivedRainbowBadgeText",
|
||||
"_CeladonGymRainbowBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_CeladonGymRainbowBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_CeladonGymReceivedTM21Text",
|
||||
"_TM21ExplanationText",
|
||||
} },
|
||||
["OPP_KOGA#1"] = { badge = "SOULBADGE", flag = "EVENT_BEAT_KOGA",
|
||||
item = "TM_TOXIC",
|
||||
gotFlag = "EVENT_GOT_TM06",
|
||||
noRoom = "_FuchsiaGymKogaTM06NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_FUCHSIA_GYM_TRAINER_", 0, 5),
|
||||
dialogue = {
|
||||
"_FuchsiaGymKogaReceivedSoulBadgeText",
|
||||
"_FuchsiaGymKogaSoulBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_FuchsiaGymKogaSoulBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_FuchsiaGymKogaReceivedTM06Text",
|
||||
"_FuchsiaGymKogaTM06ExplanationText",
|
||||
} },
|
||||
["OPP_SABRINA#1"] = { badge = "MARSHBADGE", flag = "EVENT_BEAT_SABRINA",
|
||||
item = "TM_PSYWAVE",
|
||||
gotFlag = "EVENT_GOT_TM46",
|
||||
noRoom = "_SaffronGymSabrinaTM46NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_SAFFRON_GYM_TRAINER_", 0, 6),
|
||||
dialogue = {
|
||||
"_SaffronGymSabrinaReceivedMarshBadgeText",
|
||||
"_SaffronGymSabrinaMarshBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_SaffronGymSabrinaMarshBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_SaffronGymSabrinaReceivedTM46Text",
|
||||
"_TM46ExplanationText",
|
||||
} },
|
||||
["OPP_BLAINE#1"] = { badge = "VOLCANOBADGE", flag = "EVENT_BEAT_BLAINE",
|
||||
item = "TM_FIRE_BLAST",
|
||||
gotFlag = "EVENT_GOT_TM38",
|
||||
noRoom = "_CinnabarGymBlaineTM38NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_CINNABAR_GYM_TRAINER_", 0, 6),
|
||||
dialogue = {
|
||||
"_CinnabarGymBlaineReceivedVolcanoBadgeText",
|
||||
"_CinnabarGymBlaineVolcanoBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_CinnabarGymBlaineVolcanoBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_CinnabarGymBlaineReceivedTM38Text",
|
||||
"_CinnabarGymBlaineTM38ExplanationText",
|
||||
} },
|
||||
["OPP_GIOVANNI#3"] = { badge = "EARTHBADGE", flag = "EVENT_BEAT_GIOVANNI",
|
||||
item = "TM_FISSURE",
|
||||
gotFlag = "EVENT_GOT_TM27",
|
||||
noRoom = "_ViridianGymGiovanniTM27NoRoomText",
|
||||
deactivate = range("EVENT_BEAT_VIRIDIAN_GYM_TRAINER_", 0, 7),
|
||||
dialogue = {
|
||||
"_ViridianGymGiovanniReceivedEarthBadgeText",
|
||||
"_ViridianGymGiovanniEarthBadgeInfoText",
|
||||
},
|
||||
tmPre = { "_ViridianGymGiovanniEarthBadgeInfoText" },
|
||||
tmDialogue = {
|
||||
"_ViridianGymGiovanniReceivedTM27Text",
|
||||
"_ViridianGymGiovanniTM27ExplanationText",
|
||||
} },
|
||||
|
||||
@@ -234,8 +234,12 @@ What was ported from pokered's engine code and where it came from.
|
||||
pre-battle text and engages the leader battle (badge/TM via
|
||||
data/scripts/victories.lua); post-badge talk prints the leader's
|
||||
post-battle advice text (Misty's is her TM11 explanation). The
|
||||
originals' middle branch (beaten but TM not handed over) is
|
||||
unreachable since the TM is granted with the victory. Giovanni's
|
||||
originals' middle branch (beaten but TM not handed over,
|
||||
CheckEventReuseA EVENT_GOT_TM*) is ported too: the victory's GiveItem
|
||||
goes through the bag's capacity check, a full bag shows the leader's
|
||||
"make room" text instead of the received lines and leaves
|
||||
EVENT_GOT_TM* unset, and talking to the leader re-runs the ReceiveTM
|
||||
script until the TM goes in (#797). Giovanni's
|
||||
farewell (`ViridianGymGiovanniText` .afterBeat) hides him inside a
|
||||
fade-to-black/fade-in Transition matching ViridianGym.asm's
|
||||
GBFadeOutToBlack → HideObject → GBFadeInFromBlack, persisted
|
||||
|
||||
@@ -12,6 +12,34 @@
|
||||
"tintColor": "3b5ca8",
|
||||
"category": "games",
|
||||
"versions": [
|
||||
{
|
||||
"version": "0.1.68",
|
||||
"date": "2026-08-04",
|
||||
"size": 9768011,
|
||||
"downloadURL": "https://github.com/bryanthaboi/gen1recomp/releases/download/v0.1.68/gen1recomp-0.1.68-ios.ipa",
|
||||
"localizedDescription": "Download the correct version for your computer below.\n\n## Contributors\n\n- @bryanthaboi\n- @caorthann-celt"
|
||||
},
|
||||
{
|
||||
"version": "0.1.67",
|
||||
"date": "2026-08-04",
|
||||
"size": 9767619,
|
||||
"downloadURL": "https://github.com/bryanthaboi/gen1recomp/releases/download/v0.1.67/gen1recomp-0.1.67-ios.ipa",
|
||||
"localizedDescription": "Download the correct version for your computer below.\n\n## Issues closed\n\n- #373 Lines at Title Screen\n- #644 Substitute failing causes visual issues\n- #673 iOS: thin vertical seam below the START menu panel (v0.1.56, iPhone 15 Pro Max)\n- #703 Credits playing too fast (song ends after it should)\n- #726 Surfing Pikachu Minigame Broken\n- #737 Battle menu move cursor fails to reset to the first slot after switching Pokémon\n- #750 NPC (possibly player) trades still graphically broken\n- #752 Launcher exports save to AppData while in portable mode\n- #764 Trainer Fanfare doesn't play\n- #765 Text Advance broken in certain aspects\n- #768 Menu behaviour for Pokemon and HM moves\n- #773 Battle screen colours messed up when BG = World, battle in un-flashed Rock Tunnel\n- #774 bug(build): Desktop build can reject a valid game archive under pipefail\n- #775 TM42 Dream Eater dialog.\n- #777 Battle Screen is Very dark\n- #780 Do not delete save\n- #782 Giovanni battle at Silph Co plays wrong song\n\n## Contributors\n\n- @bryanthaboi\n- @luisgonzaleznf\n- @ShaneMcGovernIE"
|
||||
},
|
||||
{
|
||||
"version": "0.1.66",
|
||||
"date": "2026-08-04",
|
||||
"size": 9749980,
|
||||
"downloadURL": "https://github.com/bryanthaboi/gen1recomp/releases/download/v0.1.66/gen1recomp-0.1.66-ios.ipa",
|
||||
"localizedDescription": "Download the correct version for your computer below.\n\n## Issues closed\n\n- #691 Save file transfer\n- #743 Cannot Scroll Main Menu/Mod Menu\n- #779 \"Enemy \" untranslateable\n\n## Contributors\n\n- @bryanthaboi\n- @jherediagu\n- @ShaneMcGovernIE\n- @vegerot"
|
||||
},
|
||||
{
|
||||
"version": "0.1.65",
|
||||
"date": "2026-08-03",
|
||||
"size": 9376618,
|
||||
"downloadURL": "https://github.com/bryanthaboi/gen1recomp/releases/download/v0.1.65/gen1recomp-0.1.65-ios.ipa",
|
||||
"localizedDescription": "Download the correct version for your computer below.\n\n## Issues closed\n\n- #592 Screen Orientation\n- #702 FLY overworld animation incorrect/incomplete\n- #748 Launcher Menu has overlap\n- #754 Can push boulders with STRENGTH through walls\n- #758 PC to Mac Online Multiplayer Disconnects Shortly After Starting Match\n\n## Contributors\n\n- @andrewqsantos\n- @Bortlesboat\n- @bryanthaboi\n- @castdrian\n- @johnjohto\n- @ShaneMcGovernIE"
|
||||
},
|
||||
{
|
||||
"version": "0.1.64",
|
||||
"date": "2026-08-03",
|
||||
|
||||
+10
-3
@@ -793,11 +793,13 @@ function Game:joystickhat(joystick, hat, direction)
|
||||
end
|
||||
|
||||
-- Window focus/visibility flips: a release due while unfocused/hidden can
|
||||
-- be swallowed by the OS. Reset on both edges -- gaining focus with a
|
||||
-- physically held key won't re-fire keypressed, so trusting leftover
|
||||
-- state is worse than asking the player to re-press.
|
||||
-- be swallowed by the OS. Reset on both edges; on the regain, reconcile
|
||||
-- re-arms only what is still physically held -- a held key won't re-fire
|
||||
-- keypressed by itself, and without the rebuild a spurious lifecycle event
|
||||
-- parked the player until every direction was re-pressed (#799).
|
||||
function Game:focus(f)
|
||||
Input:reset()
|
||||
if f then Input:reconcile() end
|
||||
TouchControls:reset()
|
||||
self:cancelPointers()
|
||||
end
|
||||
@@ -814,6 +816,7 @@ end
|
||||
|
||||
function Game:onResume()
|
||||
Input:reset()
|
||||
Input:reconcile()
|
||||
TouchControls:reset()
|
||||
self:cancelPointers()
|
||||
-- Chip music may survive NX suspend as a duplicate stream; stop it and let
|
||||
@@ -830,6 +833,10 @@ end
|
||||
|
||||
function Game:recoverInput(event, joystick)
|
||||
Input:reset()
|
||||
-- A hotplug can arrive with no hotplug (macOS Bluetooth re-enumeration),
|
||||
-- and the blanket reset above also drops unrelated keyboard holds; put
|
||||
-- back whatever is still physically down (#799).
|
||||
Input:reconcile()
|
||||
TouchControls:reset()
|
||||
-- reset just dropped every source, mod holds included: retire the mods'
|
||||
-- outstanding press tokens so nothing stale can be released later, and
|
||||
|
||||
@@ -301,6 +301,71 @@ function Input:joystickhat(joystick, hat, direction)
|
||||
self.hatDirs[hat] = dirs
|
||||
end
|
||||
|
||||
-- Lifecycle resets (focus/visibility flips, joystick add/remove, resume)
|
||||
-- wipe held state because a release can be swallowed while the OS owns the
|
||||
-- event stream. A direction the player is STILL holding never re-fires
|
||||
-- keypressed/gamepadpressed after the wipe either, so a spurious reset --
|
||||
-- macOS re-enumerating a Bluetooth pad fires joystickadded with no hotplug,
|
||||
-- and the blanket reset took unrelated keyboard holds down with it --
|
||||
-- parked the player in place until every direction was released and
|
||||
-- pressed again (#799). Rebuild holds from the devices' ground truth
|
||||
-- instead: only what is physically down right now comes back, so the
|
||||
-- swallowed-release hazards the resets guard against stay cleared.
|
||||
-- Deliberately separate from reset(): the soft-reset chord path in
|
||||
-- Game:step needs the clean slate (re-arming A there would read it as a
|
||||
-- title-menu choice).
|
||||
function Input:reconcile()
|
||||
local kb = love and love.keyboard
|
||||
if kb and kb.isDown then
|
||||
for key, btn in pairs(self.keyBindings) do
|
||||
local ok, down = pcall(kb.isDown, key)
|
||||
if ok and down then press(self, btn, "key:" .. key) end
|
||||
end
|
||||
end
|
||||
local js = love and love.joystick
|
||||
if not (js and js.getJoysticks) then return end
|
||||
local ok, joysticks = pcall(js.getJoysticks)
|
||||
if not ok or type(joysticks) ~= "table" then return end
|
||||
for _, j in ipairs(joysticks) do
|
||||
if GamepadMap.ignoreRawForJoystick(j) then
|
||||
-- SDL-recognized pad: buttons + left stick, the gamepad surfaces
|
||||
if j.isGamepadDown then
|
||||
for button, btn in pairs(self.padBindings) do
|
||||
local ok2, down = pcall(j.isGamepadDown, j, button)
|
||||
if ok2 and down then press(self, btn, "pad:" .. button) end
|
||||
end
|
||||
end
|
||||
if j.getGamepadAxis then
|
||||
for _, axis in ipairs({ "leftx", "lefty" }) do
|
||||
local ok2, v = pcall(j.getGamepadAxis, j, axis)
|
||||
if ok2 and type(v) == "number" then self:gamepadaxis(j, axis, v) end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- raw stick (#620/#632): the surfaces the joystick* events feed
|
||||
if j.isDown then
|
||||
for index, btn in pairs(self.joyBindings) do
|
||||
local ok2, down = pcall(j.isDown, j, index)
|
||||
if ok2 and down then press(self, btn, "joy:" .. index) end
|
||||
end
|
||||
end
|
||||
if j.getAxis then
|
||||
for _, axis in ipairs({ 1, 2 }) do
|
||||
local ok2, v = pcall(j.getAxis, j, axis)
|
||||
if ok2 and type(v) == "number" then self:joystickaxis(j, axis, v) end
|
||||
end
|
||||
end
|
||||
if j.getHatCount and j.getHat then
|
||||
local ok2, count = pcall(j.getHatCount, j)
|
||||
for hat = 1, (ok2 and count) or 0 do
|
||||
local ok3, dir = pcall(j.getHat, j, hat)
|
||||
if ok3 and dir then self:joystickhat(j, hat, dir) end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Input:isDown(btn)
|
||||
return self.state[btn] or false
|
||||
end
|
||||
|
||||
+14
-10
@@ -255,6 +255,15 @@ local function useOn(game, battle, id, target, list, moveIndex, picker)
|
||||
|
||||
if result == "consumed" then
|
||||
consume(game, id)
|
||||
-- refresh counts in the list
|
||||
for i, it in ipairs(list.items) do
|
||||
if it.value == id then
|
||||
local left = game.save.inventory[id]
|
||||
if left then it.right = "x" .. left else table.remove(list.items, i) end
|
||||
break
|
||||
end
|
||||
end
|
||||
list.index = math.min(list.index, math.max(1, #list.items))
|
||||
if extra and extra.evolveTo then
|
||||
list:close()
|
||||
local Evolution = require("src.pokemon.Evolution")
|
||||
@@ -265,7 +274,11 @@ local function useOn(game, battle, id, target, list, moveIndex, picker)
|
||||
-- moves and a level evolution follow (item_effects.asm .useRareCandy
|
||||
-- runs PrintStatsBox, LearnMoveFromLevelUp and TryEvolvingMon)
|
||||
if extra and extra.leveledTo and target then
|
||||
list:close()
|
||||
-- ...but the bag stays open underneath it all: RARE_CANDY is in
|
||||
-- pokered's UsableItems_PartyMenu (data/items/use_party.asm), and
|
||||
-- .useItem_partyMenu jumps back to StartMenu_Item once UseItem
|
||||
-- returns, cursor still on the candy (start_sub_menus.asm) -- so
|
||||
-- mashing A burns through a stack of them (#796)
|
||||
showMessages(game, payload, function()
|
||||
local StatBox = require("src.battle.BattleState").StatBox
|
||||
game.stack:push(StatBox.new(game, target, function()
|
||||
@@ -304,15 +317,6 @@ local function useOn(game, battle, id, target, list, moveIndex, picker)
|
||||
end)
|
||||
return
|
||||
end
|
||||
-- refresh counts in the list
|
||||
for i, it in ipairs(list.items) do
|
||||
if it.value == id then
|
||||
local left = game.save.inventory[id]
|
||||
if left then it.right = "x" .. left else table.remove(list.items, i) end
|
||||
break
|
||||
end
|
||||
end
|
||||
list.index = math.min(list.index, math.max(1, #list.items))
|
||||
-- HP medicine: fill the bar in the still-open picker first, then print
|
||||
-- and close, the order item_effects.asm .doneHealing runs in
|
||||
-- (SFX_HEAL_HP -> UpdateHPBar2 -> RedrawPartyMenu prints the message).
|
||||
|
||||
@@ -3008,6 +3008,22 @@ function OverworldState:engageTrainer(npc, onDone)
|
||||
end))
|
||||
end
|
||||
|
||||
-- Shared GiveItem step for the victory rewards (pokered home/give.asm):
|
||||
-- the item goes through the bag's capacity check, and only a successful
|
||||
-- add sets the reward's gotFlag (EVENT_GOT_TM*) and copies the item name
|
||||
-- into wStringBuffer for the "{RAM:wStringBuffer}" received texts.
|
||||
local function giveVictoryItem(reward)
|
||||
if not require("src.inventory.Bag").add(Game.save, reward.item, 1, Game.data) then
|
||||
return false
|
||||
end
|
||||
if reward.gotFlag then
|
||||
Game.save.flags[reward.gotFlag] = true
|
||||
end
|
||||
local idef = Game.data.items[reward.item]
|
||||
Game.stringBuffer = idef and idef.name or reward.item
|
||||
return true
|
||||
end
|
||||
|
||||
-- Badges/items awarded after specific battles (data/scripts/victories.lua).
|
||||
-- `deactivate` retires unfought gym/dojo trainers the way the originals'
|
||||
-- SetEvent / SetEventRange do after the leader victory.
|
||||
@@ -3036,12 +3052,13 @@ function OverworldState:checkVictoryRewards(trainerClass, partyIndex)
|
||||
if reward.badge then
|
||||
Game.save.inventory[reward.badge] = 1
|
||||
end
|
||||
local tmGiven = false
|
||||
if reward.item then
|
||||
local inv = Game.save.inventory
|
||||
inv[reward.item] = (inv[reward.item] or 0) + 1
|
||||
local idef = Game.data.items[reward.item]
|
||||
-- GiveItem -> CopyToStringBuffer for "{RAM:wStringBuffer}" received texts
|
||||
Game.stringBuffer = idef and idef.name or reward.item
|
||||
-- pokered GiveItem (home/give.asm): AddItemToInventory first, and a
|
||||
-- full bag (jr nc, .BagFull) skips the received lines for the "make
|
||||
-- room" text, leaving EVENT_GOT_TM* unset so the leader's talk script
|
||||
-- retries the hand-over later (offerGymTm via gyms.lua)
|
||||
tmGiven = giveVictoryItem(reward)
|
||||
end
|
||||
local lines = {}
|
||||
if reward.dialogue then
|
||||
@@ -3051,13 +3068,29 @@ function OverworldState:checkVictoryRewards(trainerClass, partyIndex)
|
||||
table.insert(lines, text[label])
|
||||
end
|
||||
end
|
||||
if reward.item then
|
||||
for _, label in ipairs(reward.tmPre or {}) do
|
||||
if text[label] and text[label] ~= "" then
|
||||
table.insert(lines, text[label])
|
||||
end
|
||||
end
|
||||
if tmGiven then
|
||||
for _, label in ipairs(reward.tmDialogue or {}) do
|
||||
if text[label] and text[label] ~= "" then
|
||||
table.insert(lines, text[label])
|
||||
end
|
||||
end
|
||||
elseif reward.noRoom and text[reward.noRoom] and text[reward.noRoom] ~= "" then
|
||||
table.insert(lines, text[reward.noRoom])
|
||||
end
|
||||
end
|
||||
elseif reward.badge or reward.item then
|
||||
if reward.badge then
|
||||
local name = Game.data.items[reward.badge] and Game.data.items[reward.badge].name
|
||||
or reward.badge
|
||||
table.insert(lines, Strings("%s received\nthe %s!", Game.save.player.name, name))
|
||||
end
|
||||
if reward.item then
|
||||
if tmGiven then
|
||||
local name = Game.stringBuffer or reward.item
|
||||
table.insert(lines, Strings("%s received\n%s!", Game.save.player.name, name))
|
||||
end
|
||||
@@ -3068,6 +3101,33 @@ function OverworldState:checkVictoryRewards(trainerClass, partyIndex)
|
||||
self:runVictoryHook()
|
||||
end
|
||||
|
||||
-- A beaten leader re-running their ReceiveTM script when the bag was full
|
||||
-- at the victory (pokered's middle branch, e.g. PewterGymBrockText
|
||||
-- CheckEventReuseA EVENT_GOT_TM34 -> call PewterGymScriptReceiveTM34).
|
||||
-- The script's lead-in lines (tmPre: badge info / "Wait! Take this!")
|
||||
-- show again, then the same GiveItem check decides between the received
|
||||
-- lines and the "make room" text.
|
||||
function OverworldState:offerGymTm(reward, done)
|
||||
local text = Game.data.text or {}
|
||||
local lines = {}
|
||||
local function addLine(label)
|
||||
if label and text[label] and text[label] ~= "" then
|
||||
table.insert(lines, text[label])
|
||||
end
|
||||
end
|
||||
for _, label in ipairs(reward.tmPre or {}) do addLine(label) end
|
||||
if giveVictoryItem(reward) then
|
||||
for _, label in ipairs(reward.tmDialogue or {}) do addLine(label) end
|
||||
else
|
||||
addLine(reward.noRoom)
|
||||
end
|
||||
if #lines > 0 then
|
||||
Game.stack:push(TextBox.new(Game, table.concat(lines, "\f"), done))
|
||||
elseif done then
|
||||
done()
|
||||
end
|
||||
end
|
||||
|
||||
-- pokered reloads the map after every battle, re-running the map
|
||||
-- script (e.g. LoreleiShowOrHideExitBlock); this hook is the port's
|
||||
-- equivalent so seals/toggles refresh without leaving the map
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
-- Held directions must survive lifecycle resets while physically held
|
||||
-- (#799). Input state is event-driven, so any Input:reset (focus or
|
||||
-- visibility flip, joystick add/remove, resume) wipes a hold that never
|
||||
-- re-fires keypressed afterwards -- on macOS a Bluetooth controller
|
||||
-- re-enumerating mid-walk fired joystickadded under a held key and parked
|
||||
-- the player until the direction was released and pressed again. Game's
|
||||
-- lifecycle handlers rebuild holds from device ground truth after each
|
||||
-- reset; only what is physically down comes back, so the swallowed-release
|
||||
-- hazards the resets guard against stay cleared.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
if not _G.love then _G.love = require("tests.love_stub") end
|
||||
|
||||
local T = require("tests.harness")
|
||||
local check = T.check
|
||||
|
||||
local Input = require("src.core.Input")
|
||||
local Game = require("src.core.Game")
|
||||
|
||||
local realIsDown = love.keyboard.isDown
|
||||
local realJoystick = love.joystick
|
||||
local function restore()
|
||||
love.keyboard.isDown = realIsDown
|
||||
love.joystick = realJoystick
|
||||
end
|
||||
|
||||
Input:init()
|
||||
|
||||
-- Keyboard: direction still physically held across a spurious pad
|
||||
-- re-enumeration must keep walking (the #799 report).
|
||||
love.keyboard.isDown = function(key) return key == "up" end
|
||||
Input:reset()
|
||||
Input:keypressed("up")
|
||||
Input:step()
|
||||
check(Input:isDown("up"), "up held before joystick re-enumeration")
|
||||
Game:joystickadded({ getName = function() return "Wireless Controller" end })
|
||||
check(Input:isDown("up"), "held key survives a spurious joystickadded")
|
||||
|
||||
-- Same hold across a focus bounce (another reset source).
|
||||
Game:focus(false)
|
||||
check(not Input:isDown("up"), "focus loss still drops the hold")
|
||||
Game:focus(true)
|
||||
check(Input:isDown("up"), "held key re-arms on focus regain")
|
||||
|
||||
-- A key released while unfocused (keyup swallowed by the OS, the hazard
|
||||
-- the resets exist for) must NOT come back.
|
||||
love.keyboard.isDown = function() return false end
|
||||
Game:focus(false)
|
||||
Game:focus(true)
|
||||
check(not Input:isDown("up"), "swallowed release still clears the hold")
|
||||
|
||||
-- Controller: held d-pad across a disconnect/reconnect bounce.
|
||||
local pad = {
|
||||
isGamepad = function() return true end,
|
||||
isGamepadDown = function(_, button) return button == "dpleft" end,
|
||||
getGamepadAxis = function() return 0 end,
|
||||
}
|
||||
love.joystick = { getJoysticks = function() return { pad } end }
|
||||
love.keyboard.isDown = function() return false end
|
||||
Input:reset()
|
||||
Input:gamepadpressed(pad, "dpleft")
|
||||
Input:step()
|
||||
check(Input:isDown("left"), "d-pad held before reconnect")
|
||||
Game:joystickremoved(pad)
|
||||
Game:joystickadded(pad)
|
||||
check(Input:isDown("left"), "held d-pad survives a reconnect bounce")
|
||||
|
||||
-- Held stick across the same bounce (axis ground truth re-derived).
|
||||
pad.isGamepadDown = function() return false end
|
||||
pad.getGamepadAxis = function(_, axis) return axis == "leftx" and -0.9 or 0 end
|
||||
Input:reset()
|
||||
Input:gamepadaxis(pad, "leftx", -0.9)
|
||||
Input:step()
|
||||
check(Input:isDown("left"), "stick held before re-enumeration")
|
||||
Game:joystickadded(pad)
|
||||
check(Input:isDown("left"), "held stick survives re-enumeration")
|
||||
|
||||
-- A pad that vanished for real reports nothing held: its stale hold must
|
||||
-- stay cleared (the stuck-flag hazard reset-on-remove guards against).
|
||||
love.joystick = { getJoysticks = function() return {} end }
|
||||
Input:reset()
|
||||
Input:gamepadpressed(pad, "dpleft")
|
||||
Input:step()
|
||||
Game:joystickremoved(pad)
|
||||
check(not Input:isDown("left"), "vanished pad's hold stays cleared")
|
||||
|
||||
restore()
|
||||
T.finish()
|
||||
+60
-4
@@ -183,7 +183,7 @@ do
|
||||
new = function(game, text, done) return { text = text, onDone = done } end,
|
||||
}
|
||||
|
||||
local function driveLeader(mapId, textConst, beatFlag)
|
||||
local function driveLeader(mapId, textConst, beatFlag, gotFlag)
|
||||
local pushed, engaged
|
||||
local game = {
|
||||
save = { flags = {} },
|
||||
@@ -198,6 +198,9 @@ do
|
||||
mapId .. " leader talk (no badge) engages the leader battle")
|
||||
engaged, pushed = nil, nil
|
||||
game.save.flags[beatFlag] = true
|
||||
-- the advice/farewell branch is pokered's .afterBeat, reached only
|
||||
-- once EVENT_GOT_TM* is set (the TM went into the bag)
|
||||
if gotFlag then game.save.flags[gotFlag] = true end
|
||||
local state = {}
|
||||
script(game, ow, { def = {} }, function() state.doneCalled = true end)
|
||||
check(pushed and not engaged,
|
||||
@@ -206,17 +209,17 @@ do
|
||||
end
|
||||
|
||||
local _, box = driveLeader("CERULEAN_GYM", "TEXT_CERULEANGYM_MISTY",
|
||||
"EVENT_BEAT_MISTY")
|
||||
"EVENT_BEAT_MISTY", "EVENT_GOT_TM11")
|
||||
eq(box and box.text, Data.text._CeruleanGymMistyTM11ExplanationText,
|
||||
"Misty (beaten) shows the TM11 explanation text")
|
||||
|
||||
_, box = driveLeader("CINNABAR_GYM", "TEXT_CINNABARGYM_BLAINE",
|
||||
"EVENT_BEAT_BLAINE")
|
||||
"EVENT_BEAT_BLAINE", "EVENT_GOT_TM38")
|
||||
eq(box and box.text, Data.text._CinnabarGymBlainePostBattleAdviceText,
|
||||
"Blaine (beaten) shows his post-battle advice text")
|
||||
|
||||
local game, gbox, state = driveLeader("VIRIDIAN_GYM", "TEXT_VIRIDIANGYM_GIOVANNI",
|
||||
"EVENT_BEAT_GIOVANNI")
|
||||
"EVENT_BEAT_GIOVANNI", "EVENT_GOT_TM27")
|
||||
eq(gbox and gbox.text, Data.text._ViridianGymGiovanniPostBattleAdviceText,
|
||||
"Giovanni (beaten) shows his farewell text")
|
||||
|
||||
@@ -392,6 +395,59 @@ do
|
||||
check(cinnabarNpc and ow:trainerDefeated(cinnabarNpc),
|
||||
"unfought Cinnabar trainer is defeated via seeded header event")
|
||||
|
||||
-- #797: a full bag at the victory skips the TM hand-over (pokered's
|
||||
-- `call GiveItem` / `jr nc, .BagFull`): badge and beat flag still land,
|
||||
-- but EVENT_GOT_TM34 stays unset and the "make room" line replaces the
|
||||
-- received/explanation texts. Talking to Brock afterwards re-runs the
|
||||
-- ReceiveTM script and grants the TM once there is room.
|
||||
while Game.stack:top() do Game.stack:pop() end
|
||||
Game.save = SaveData.newGame()
|
||||
Game.save.flags = {}
|
||||
Game.save.inventory = {}
|
||||
Game.save.defeatedTrainers = {}
|
||||
local Bag = require("src.inventory.Bag")
|
||||
for i = 1, Bag.capacity(Data) do
|
||||
Bag.add(Game.save, "FULLBAG_" .. i, 1, Data)
|
||||
end
|
||||
eq(Bag.slots(Game.save), Bag.capacity(Data), "bag is full before Brock")
|
||||
Game.stack:push(OW, "PEWTER_GYM", 4, 13, "up")
|
||||
ow = Game.stack:top()
|
||||
ow:checkVictoryRewards("OPP_BROCK", 1)
|
||||
local fullBagText = stackedDialogue()
|
||||
check(Game.save.flags.EVENT_BEAT_BROCK,
|
||||
"full bag: Brock victory still sets EVENT_BEAT_BROCK")
|
||||
check(Game.save.inventory.BOULDERBADGE == 1,
|
||||
"full bag: Brock victory still awards BOULDERBADGE")
|
||||
check(not Game.save.flags.EVENT_GOT_TM34,
|
||||
"full bag: EVENT_GOT_TM34 stays unset (bag_full branch)")
|
||||
check(Game.save.inventory.TM_BIDE == nil,
|
||||
"full bag: TM34 is not forced into the bag")
|
||||
check(fullBagText:find("room", 1, true) ~= nil,
|
||||
"full bag: victory dialogue shows Brock's make-room line")
|
||||
check(fullBagText:find("BIDE", 1, true) == nil,
|
||||
"full bag: received/explanation texts are skipped")
|
||||
|
||||
-- make room, then talk to Brock: the middle branch re-runs ReceiveTM34
|
||||
while Game.stack:top() do Game.stack:pop() end
|
||||
Bag.remove(Game.save, "FULLBAG_1", 1)
|
||||
local brockTalk = init.talkScript("PEWTER_GYM", "TEXT_PEWTERGYM_BROCK")
|
||||
check(brockTalk ~= nil, "Brock's talk script is registered")
|
||||
brockTalk(Game, ow, { def = {} }, function() end)
|
||||
local retryText = stackedDialogue()
|
||||
check(retryText:find("Wait!", 1, true) ~= nil,
|
||||
"retry: ReceiveTM34 lead-in (Wait! Take this!) shows again")
|
||||
check(retryText:find("BIDE", 1, true) ~= nil,
|
||||
"retry: received/explanation texts show once the TM fits")
|
||||
eq(Game.save.inventory.TM_BIDE, 1, "retry: TM34 goes into the bag")
|
||||
check(Game.save.flags.EVENT_GOT_TM34, "retry: EVENT_GOT_TM34 is set")
|
||||
|
||||
-- once the TM is handed over, Brock falls back to his advice text
|
||||
while Game.stack:top() do Game.stack:pop() end
|
||||
brockTalk(Game, ow, { def = {} }, function() end)
|
||||
local adviceText = stackedDialogue()
|
||||
check(adviceText:find("CERULEAN", 1, true) ~= nil,
|
||||
"after the TM: Brock shows his post-battle advice text")
|
||||
|
||||
while Game.stack:top() do Game.stack:pop() end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
-- Parity test: using a RARE CANDY from the bag returns to the bag (#796).
|
||||
--
|
||||
-- pokered files RARE_CANDY under UsableItems_PartyMenu (data/items/
|
||||
-- use_party.asm), so after UseItem runs, start_sub_menus.asm's
|
||||
-- .useItem_partyMenu jumps back to StartMenu_Item with wBagSavedMenuItem
|
||||
-- still pointing at the candy -- the level text, PrintStatsBox, the
|
||||
-- level-up moves and any level evolution all happen first, then the item
|
||||
-- list is back with the cursor on the candy, which is what lets the
|
||||
-- original button-mash through a stack of them. The port closed the bag
|
||||
-- list before the level-up sequence and never reopened it, so every candy
|
||||
-- cost a full START -> ITEM trip.
|
||||
--
|
||||
-- Self-contained; run via `luajit tests/parity_rare_candy_menu.lua`.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
if not _G.love then _G.love = require("tests.love_stub") end
|
||||
local S = require("tests.harness").suite("parity rare candy menu")
|
||||
local check, eq = S.check, S.eq
|
||||
|
||||
local Data = require("src.core.Data")
|
||||
Data:load()
|
||||
|
||||
local Pokemon = require("src.pokemon.Pokemon")
|
||||
local Bag = require("src.inventory.Bag")
|
||||
|
||||
-- Real TextBoxes want a Font atlas; the flow under test only cares which
|
||||
-- states land on the stack and what each onDone does. BagMenu binds
|
||||
-- TextBox at require time, so it is reloaded against the stub here and
|
||||
-- dropped again at the bottom.
|
||||
local realTextBox = package.loaded["src.render.TextBox"]
|
||||
local realBag = package.loaded["src.ui.BagMenu"]
|
||||
local realParty = package.loaded["src.ui.PartyMenu"]
|
||||
package.loaded["src.render.TextBox"] = {
|
||||
new = function(_, text, done) return { textBox = true, text = text, done = done } end,
|
||||
}
|
||||
package.loaded["src.ui.BagMenu"] = nil
|
||||
package.loaded["src.ui.PartyMenu"] = nil
|
||||
local BagMenu = require("src.ui.BagMenu")
|
||||
local PartyMenu = require("src.ui.PartyMenu")
|
||||
require("src.ui.Screens").invalidate()
|
||||
|
||||
-- A stack that behaves like StateStack for the two things this flow reads:
|
||||
-- top() identity (ListMenu:close) and push/pop ordering.
|
||||
local function newStack()
|
||||
local stack = { states = {} }
|
||||
function stack:push(s) self.states[#self.states + 1] = s end
|
||||
function stack:pop() return table.remove(self.states) end
|
||||
function stack:top() return self.states[#self.states] end
|
||||
return stack
|
||||
end
|
||||
|
||||
-- One button per call: PartyMenu:update reads game.input once per fixed step.
|
||||
local function newInput()
|
||||
local input = { pressed = nil }
|
||||
function input:wasPressed(b) return self.pressed == b end
|
||||
return input
|
||||
end
|
||||
|
||||
-- CHARIZARD learns nothing at level 51 and has no evolution left, so a
|
||||
-- candy on it ends after the stat window -- no MoveLearnMenu, no
|
||||
-- EvolutionState clouding which state the stack returns to.
|
||||
local function freshGame(candies)
|
||||
local lead = Pokemon.new(Data, "CHARIZARD", 50)
|
||||
local game = {
|
||||
data = Data,
|
||||
stack = newStack(),
|
||||
input = newInput(),
|
||||
save = {
|
||||
party = { lead },
|
||||
player = { name = "RED" },
|
||||
inventory = {},
|
||||
options = { battleStyle = "set", battleAnim = "on" },
|
||||
pokedex = { seen = {}, owned = {} },
|
||||
flags = {},
|
||||
money = 0,
|
||||
},
|
||||
}
|
||||
Bag.add(game.save, "RARE_CANDY", candies or 3)
|
||||
return game, lead
|
||||
end
|
||||
|
||||
local function isPicker(s) return getmetatable(s) == PartyMenu end
|
||||
local function isBox(s) return type(s) == "table" and s.textBox == true end
|
||||
|
||||
-- TextBox pops itself BEFORE firing onDone.
|
||||
local function dismiss(stack, box)
|
||||
if stack:top() == box then stack:pop() end
|
||||
if box.done then box.done() end
|
||||
end
|
||||
|
||||
local function rowFor(list, id)
|
||||
for i, r in ipairs(list.items) do
|
||||
if r.value == id then return i end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- From an already-open bag list: choose the candy, take USE off the
|
||||
-- submenu, press A on the party picker. Returns the level-up text box.
|
||||
local function useCandy(game, list)
|
||||
local row = rowFor(list, "RARE_CANDY")
|
||||
if not row then return nil, "no RARE CANDY row in the bag" end
|
||||
list.index = row
|
||||
list.onChoose(list.items[row], list)
|
||||
-- out of battle the bag offers USE / TOSS first (start_sub_menus.asm)
|
||||
local sub = game.stack:top()
|
||||
if sub and sub.items and sub.items[1] and sub.items[1].onSelect then
|
||||
game.stack:pop()
|
||||
sub.items[1].onSelect()
|
||||
end
|
||||
local picker = game.stack:top()
|
||||
if not isPicker(picker) then return nil, "party picker never opened" end
|
||||
game.input.pressed = "a"
|
||||
picker:update(1 / 60)
|
||||
game.input.pressed = nil
|
||||
return game.stack:top()
|
||||
end
|
||||
|
||||
-- Walk the rest of the level-up sequence: dismiss the level text, then A
|
||||
-- through the stat window (PrintStatsBox).
|
||||
local function finishLevelUp(game, box)
|
||||
dismiss(game.stack, box)
|
||||
local top = game.stack:top()
|
||||
if isBox(top) then return end -- a "learned MOVE" line, dismissed by caller
|
||||
if top and top.update then
|
||||
game.input.pressed = "a"
|
||||
top:update(1 / 60)
|
||||
game.input.pressed = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- ---- the report: one candy closed the whole menu -------------------------
|
||||
do
|
||||
local game, lead = freshGame(3)
|
||||
local list = BagMenu.new(game, {})
|
||||
game.stack:push(list)
|
||||
local row = rowFor(list, "RARE_CANDY")
|
||||
check(row ~= nil, "the candy is in the bag")
|
||||
|
||||
local box = useCandy(game, list)
|
||||
check(isBox(box), "the level text opened")
|
||||
eq(lead.level, 51, "the candy leveled the mon")
|
||||
eq(game.save.inventory.RARE_CANDY, 2, "the candy was consumed")
|
||||
check(game.stack.states[1] == list,
|
||||
"the bag list is STILL on the stack under the level text (#796)")
|
||||
|
||||
finishLevelUp(game, box)
|
||||
eq(game.stack:top(), list,
|
||||
"after the stat window the bag is back on top (StartMenu_Item)")
|
||||
eq(list.index, row, "the cursor is still on the RARE CANDY row")
|
||||
eq(list.items[row] and list.items[row].right, "x2",
|
||||
"the count refreshed in place")
|
||||
|
||||
-- the point of the original's behavior: a second candy needs no menu trip
|
||||
local box2 = useCandy(game, list)
|
||||
check(isBox(box2), "a second candy fires from the still-open bag")
|
||||
eq(lead.level, 52, "and it levels the mon again")
|
||||
finishLevelUp(game, box2)
|
||||
eq(game.stack:top(), list, "still on the bag after the second candy")
|
||||
eq(game.save.inventory.RARE_CANDY, 1, "two candies spent")
|
||||
end
|
||||
|
||||
-- ---- the last candy: the row empties but the bag still stays up ----------
|
||||
do
|
||||
local game = freshGame(1)
|
||||
local list = BagMenu.new(game, {})
|
||||
game.stack:push(list)
|
||||
local box = useCandy(game, list)
|
||||
check(isBox(box), "the last candy levels too")
|
||||
finishLevelUp(game, box)
|
||||
eq(game.stack:top(), list, "the bag stays open after the last candy")
|
||||
eq(#list.items, 0, "the emptied row left the list")
|
||||
eq(game.save.inventory.RARE_CANDY, nil, "no candies left in the inventory")
|
||||
end
|
||||
|
||||
package.loaded["src.render.TextBox"] = realTextBox
|
||||
package.loaded["src.ui.BagMenu"] = realBag
|
||||
package.loaded["src.ui.PartyMenu"] = realParty
|
||||
require("src.ui.Screens").invalidate()
|
||||
S.finish()
|
||||
Reference in New Issue
Block a user