diff --git a/src/ui/game3/mystery_gift.lua b/src/ui/game3/mystery_gift.lua index 1dde08cc..851a4e4b 100644 --- a/src/ui/game3/mystery_gift.lua +++ b/src/ui/game3/mystery_gift.lua @@ -17,34 +17,20 @@ local MUS_OBTAIN_ITEM = 258 local SE_BOO = 22 local SE_POKENAV_ON = 103 --- pokefirered/src/union_room.c:2471 -Ui.SEARCH_MIN_FRAMES = 120 -Ui.COMMUNICATING_FRAMES = 30 --- pokefirered/src/mystery_gift_menu.c:604 -Ui.COMPLETED_FRAMES = 120 -- pokefirered/src/mystery_gift_menu.c:968 Ui.SUCCESS_FRAMES = 240 Ui.STATE = { MAIN_MENU = "main_menu", - DONT_HAVE_ANY = "dont_have_any", - SOURCE_PROMPT = "source_prompt", - SOURCE_INPUT = "source_input", SEARCHING = "searching", OFFER_LIST = "offer_list", - COMMUNICATING = "communicating", - COMM_COMPLETED = "comm_completed", ASK_REPLACE = "ask_replace", ASK_REPLACE_UNRECEIVED = "ask_replace_unreceived", RESULT_MSG = "result_msg", SAVE = "save", SAVE_DONE = "save_done", GIFT_INPUT = "gift_input", - GIFT_SELECT = "gift_select", - ASK_TOSS = "ask_toss", - ASK_TOSS_UNRECEIVED = "ask_toss_unreceived", - TOSSED = "tossed", - NO_LINK = "no_link", + NEWS_VIEW = "news_view", EXIT = "exit", } @@ -56,10 +42,6 @@ local THREE_WIN = Window.template(8, 5, 14, 5) local OFFER_WIN = Window.template(1, 3, 17, 10) -- pokefirered/src/mystery_gift_menu.c:157 sWindowTemplate_YesNoBox local YESNO_WIN = Window.template(23, 15, 6, 4) --- pokefirered/src/mystery_gift_menu.c:167 sWindowTemplate_GiftSelect_3Options -local GIFT3_WIN = Window.template(22, 12, 7, 7) --- pokefirered/src/mystery_gift_menu.c:177 sWindowTemplate_GiftSelect_2Options -local GIFT2_WIN = Window.template(22, 14, 7, 5) -- pokefirered/src/mystery_gift_show_card.c:67 sWindowTemplates local CARD_HEADER = Window.template(1, 1, 25, 4) local CARD_BODY = Window.template(1, 6, 28, 8) @@ -214,11 +196,6 @@ function Ui.mainRows(st) return rows end --- pokefirered/src/mystery_gift_menu.c:203 sListMenuItems_WirelessOrFriend -function Ui.sourceRows() - return RomText.list("sListMenuItems_WirelessOrFriend") -end - -- pokefirered/src/mystery_gift_menu.c:630 function Ui.threeOptionTemplate(rows) local width = 0 @@ -231,15 +208,6 @@ function Ui.threeOptionTemplate(rows) return Window.template(math.floor((30 - final) / 2), THREE_WIN.top, final, THREE_WIN.height) end --- pokefirered/src/mystery_gift_menu.c:230 sListMenuItems_ReceiveSendToss -function Ui.giftRows(st) - local allowed = st.isNews and MysteryGift.isSendingNewsAllowed(session(st)) - or (not st.isNews and MysteryGift.isSendingCardAllowed(session(st))) - local name = allowed and "sListMenuItems_ReceiveSendToss" or "sListMenuItems_ReceiveToss" - st.giftActions = allowed and { "receive", "send", "toss", "cancel" } or { "receive", "toss", "cancel" } - return RomText.list(name) -end - -- pokefirered/src/list_menu.c:331 maxShowed local function setRows(st, rows, cursor, visible) st.rows = rows @@ -283,40 +251,30 @@ function Ui.new(opts) end function Ui.card(st) - return MysteryGift.getSavedCard(session(st)) + return st.viewCard or MysteryGift.getSavedCard(session(st)) +end + +function Ui.cardMetadata(st) + if st.viewCard then + return { iconSpecies = st.viewCard.iconSpecies, stampData = { ids = {}, species = {} } } + end + return MysteryGift.getSavedCardMetadata(session(st)) end function Ui.news(st) - return MysteryGift.getSavedNews(session(st)) -end - --- pokefirered/src/mystery_gift_menu.c:1153 MG_STATE_DONT_HAVE_ANY -local function toSourcePrompt(st) - st.state = Ui.STATE.SOURCE_PROMPT + return st.viewNews or MysteryGift.getSavedNews(session(st)) end -- pokefirered/src/mystery_gift_menu.c:855 SaveOnMysteryGiftMenu -local function beginSave(st, nextState) - st.saveNext = nextState +local function beginSave(st) st.state = Ui.STATE.SAVE -- pokefirered/src/strings.c:1321 gText_DataWillBeSaved say(st, RomText.plain("gText_DataWillBeSaved"), nil, true) end --- pokefirered/src/mystery_gift_menu.c:1153 gText_DontHaveCardNewOneInput -local function dontHaveAny(st) - st.state = Ui.STATE.DONT_HAVE_ANY - if st.isNews then - say(st, RomText.plain("gText_DontHaveNewsNewOneInput"), toSourcePrompt) - else - say(st, RomText.plain("gText_DontHaveCardNewOneInput"), toSourcePrompt) - end -end - -- pokefirered/src/mystery_gift_menu.c:1159 MG_STATE_LOAD_GIFT local function loadGift(st) st.state = Ui.STATE.GIFT_INPUT - st.newsScroll = 0 st.msg = nil st.prompt = nil end @@ -340,11 +298,6 @@ local function closeOffers(st) st.prompt = nil end -local function toSourcePromptOffline(st) - iconOff() - toSourcePrompt(st) -end - local function toMainMenuOffline(st) iconOff() toMainMenu(st) @@ -356,7 +309,7 @@ local function clientResult(st, textKey, success) if success then fanfare(MUS_OBTAIN_ITEM) say(st, RomText.plain(textKey), function(s) - beginSave(s, Ui.STATE.MAIN_MENU) + beginSave(s) end, true, Ui.SUCCESS_FRAMES) else say(st, RomText.plain(textKey), toMainMenu) @@ -366,53 +319,35 @@ end -- pokefirered/src/mystery_gift_menu.c:1344 local function commCompleted(st, textKey, success) iconOff() - st.state = Ui.STATE.COMM_COMPLETED - st.prompt = RomText.plain("gText_CommunicationCompleted") - st.timer = 0 - st.pendingResult = { key = textKey, success = success } + closeOffers(st) + clientResult(st, textKey, success) end -- pokefirered/src/mystery_gift_client.c:208 CLI_SAVE_CARD local function receiveFrom(st, entry) local sess = session(st) - local ok - if st.isNews then - ok = entry.news ~= nil - and MysteryGift.receiveNews(sess, entry.news, MysteryGift.WONDER_NEWS_RECV_WIRELESS) - if ok then MysteryGift.claimNews(sess, entry.news) end - else - ok = entry.card ~= nil and MysteryGift.receiveCard(sess, entry.card) - if ok then MysteryGift.claimCard(sess, entry.card) end - end + local ok = entry.card ~= nil and MysteryGift.receiveCard(sess, entry.card) + if ok then MysteryGift.claimCard(sess, entry.card) end if not ok then -- pokefirered/src/mystery_gift_menu.c:935 commCompleted(st, "gText_CommunicationError", false) return false end -- pokefirered/src/mystery_gift_menu.c:899 - commCompleted(st, st.isNews and "gText_WonderNewsReceived" or "gText_WonderCardReceived", true) + commCompleted(st, "gText_WonderCardReceived", true) return true end +local openOffers + local function canceledClient(st) - -- pokefirered/src/mystery_gift_menu.c:927 - commCompleted(st, "gText_CommunicationCanceled", false) + st.state = Ui.STATE.OFFER_LIST + openOffers(st, st.feed) end -- pokefirered/src/mystery_gift_menu.c:1292 MG_STATE_CLIENT_ASK_TOSS local function deliverOffer(st, entry) local sess = session(st) - if st.isNews then - -- pokefirered/src/mystery_gift_menu.c:919 - if MysteryGift.hasClaimedNews(sess, entry.news) then - return commCompleted(st, "gText_AlreadyHadNews", false) - end - return receiveFrom(st, entry) - end - -- pokefirered/src/mystery_gift_menu.c:911 - if MysteryGift.hasClaimedCard(sess, entry.card) then - return commCompleted(st, "gText_AlreadyHadCard", false) - end if not MysteryGift.validateSavedCard(sess) then return receiveFrom(st, entry) end st.state = Ui.STATE.ASK_REPLACE st.prompt = nil @@ -435,8 +370,7 @@ function Ui.offerRows(st) local ListMenu = require("src.ui.game3.list_menu") local items = {} for i, entry in ipairs(st.offers or {}) do - local claimed = st.isNews and MysteryGift.hasClaimedNews(sess, entry.news) - or (not st.isNews and MysteryGift.hasClaimedCard(sess, entry.card)) + local claimed = not st.isNews and MysteryGift.hasClaimedCard(sess, entry.card) items[i] = { label = entry.label, id = i, @@ -456,22 +390,34 @@ local function inputAdapter(pressed) } end +function Ui.listPrompt(st) + if st.isNews then return Strings("Which WONDER NEWS\nwould you like to read?") end + return Strings("Which WONDER CARD\nwould you like?") +end + +function Ui.isHeldCard(st, card) + local held = MysteryGift.validateSavedCard(session(st)) and Ui.card(st) or nil + return held ~= nil and type(card) == "table" and tonumber(held.idNumber) == tonumber(card.idNumber) +end + -- pokefirered/src/union_room.c:2458 -local function openOffers(st, list) +function openOffers(st, list) + st.feed = list st.offers = st.isNews and list.news or list.cards if #(st.offers or {}) == 0 then se(SE_BOO) closeOffers(st) st.state = Ui.STATE.RESULT_MSG -- pokefirered/src/union_room.c:2560 - say(st, RomText.at("gTexts_UR_NoWonderShared", st.isNews and 1 or 0), toSourcePromptOffline) + say(st, RomText.at("gTexts_UR_NoWonderShared", st.isNews and 1 or 0), + toMainMenuOffline) return end se(SE_POKENAV_ON) WirelessIcon.force("3bars") st.state = Ui.STATE.OFFER_LIST -- pokefirered/src/union_room.c:2521 - st.prompt = RomText.plain("gText_UR_WirelessLinkEstablished") + st.prompt = Ui.listPrompt(st) local ListMenu = require("src.ui.game3.list_menu") st.list = ListMenu.new({ template = OFFER_WIN, @@ -500,10 +446,10 @@ end -- pokefirered/src/mystery_gift_menu.c:1240 local function pickOffer(st, entry) st.list = nil - st.offer = entry - st.state = Ui.STATE.COMMUNICATING - st.timer = 0 - st.prompt = RomText.plain("gText_Communicating") + st.viewCard = nil + st.viewOffer = nil + st.prompt = nil + deliverOffer(st, entry) end function Ui.close(st) @@ -514,38 +460,6 @@ function Ui.close(st) WirelessIcon.force(nil) end --- pokefirered/src/mystery_gift_menu.c:1484 MG_STATE_TOSS -local function tossGift(st) - local sess = session(st) - if st.isNews then - MysteryGift.clearNewsAndRelated(sess) - else - MysteryGift.clearCardAndRelated(sess) - end - beginSave(st, Ui.STATE.TOSSED) -end - --- pokefirered/src/mystery_gift_menu.c:839 AskDiscardGift -local function askToss(st) - st.state = Ui.STATE.ASK_TOSS - local text = st.isNews - and RomText.plain("gText_OkayToDiscardNews") - or RomText.plain("gText_IfThrowAwayCardEventWontHappen") - ask(st, text, function(s) - if not s.isNews and MysteryGift.isGiftNotReceived(session(s)) then - s.state = Ui.STATE.ASK_TOSS_UNRECEIVED - -- pokefirered/src/strings.c:1320 gText_HaventReceivedGiftOkayToDiscard - ask(s, RomText.plain("gText_HaventReceivedGiftOkayToDiscard"), tossGift, function(s2) - s2.state = Ui.STATE.GIFT_SELECT - end) - return - end - tossGift(s) - end, function(s) - s.state = Ui.STATE.GIFT_SELECT - end) -end - local function tickMsg(st, pressed) local m = st.msg if m.revealed < m.total then @@ -648,11 +562,12 @@ function Ui.update(st, pressed, dt) if st.state == S.MAIN_MENU then local pick = tickList(st, pressed) local action = pick == -1 and "exit" or (st.mainActions or {})[pick] - if action == "cards" or action == "news" then - st.isNews = (action == "news") - local held = st.isNews and MysteryGift.validateSavedNews(session(st)) - or (not st.isNews and MysteryGift.validateSavedCard(session(st))) - if held then loadGift(st) else dontHaveAny(st) end + if action == "news" then + st.isNews = true + startSearch(st) + elseif action == "cards" then + st.isNews = false + startSearch(st) elseif action == "exit" then st.state = S.EXIT Ui.close(st) @@ -661,35 +576,6 @@ function Ui.update(st, pressed, dt) return nil end - if st.state == S.SOURCE_PROMPT then - setRows(st, Ui.sourceRows(), 1) - st.state = S.SOURCE_INPUT - -- pokefirered/src/strings.c:1282 gText_WhereShouldCardBeAccessed - st.prompt = st.isNews - and RomText.plain("gText_WhereShouldNewsBeAccessed") - or RomText.plain("gText_WhereShouldCardBeAccessed") - return nil - end - - -- pokefirered/src/mystery_gift_menu.c:1176 - if st.state == S.SOURCE_INPUT then - local pick = tickList(st, pressed) - if pick == 1 then - startSearch(st) - elseif pick == 2 then - st.prompt = nil - st.state = S.RESULT_MSG - -- pokefirered/src/strings.c:24 - say(st, RomText.plain("gText_WirelessNotConnected"), toSourcePrompt) - elseif pick then - st.prompt = nil - local held = st.isNews and MysteryGift.validateSavedNews(session(st)) - or (not st.isNews and MysteryGift.validateSavedCard(session(st))) - if held then loadGift(st) else toMainMenu(st) end - end - return nil - end - -- pokefirered/src/union_room.c:2458 if st.state == S.SEARCHING then st.timer = (st.timer or 0) + 1 @@ -699,11 +585,11 @@ function Ui.update(st, pressed, dt) closeOffers(st) st.state = S.RESULT_MSG -- pokefirered/src/union_room.c:2551 - say(st, RomText.plain("gText_UR_WirelessSearchCanceled"), toSourcePromptOffline) + say(st, RomText.plain("gText_UR_WirelessSearchCanceled"), toMainMenuOffline) return nil end local status, result = MysteryGift.pollOnline(st.job) - if status == "pending" or st.timer <= Ui.SEARCH_MIN_FRAMES then return nil end + if status == "pending" then return nil end st.job = nil if status == "ok" then openOffers(st, result) @@ -715,7 +601,7 @@ function Ui.update(st, pressed, dt) st.lastError = result if result == "offline" then -- pokefirered/src/strings.c:24 - say(st, RomText.plain("gText_WirelessNotConnected"), toSourcePromptOffline) + say(st, RomText.plain("gText_WirelessNotConnected"), toMainMenuOffline) else -- pokefirered/src/mystery_gift_menu.c:1590 say(st, RomText.plain("gText_CommunicationError"), toMainMenuOffline) @@ -729,33 +615,32 @@ function Ui.update(st, pressed, dt) local verdict = list and list:handleInput(inputAdapter(pressed)) or nil if verdict == "select" then local item = list:selected() - if item and item.entry then pickOffer(st, item.entry) end + if item and item.entry and st.isNews then + st.viewNews = item.entry.news + st.newsScroll = 0 + st.prompt = nil + st.state = S.NEWS_VIEW + elseif item and item.entry and Ui.isHeldCard(st, item.entry.card) then + loadGift(st) + elseif item and item.entry then + st.viewCard = item.entry.card + st.viewOffer = item.entry + loadGift(st) + end elseif verdict == "cancel" then closeOffers(st) - st.state = S.RESULT_MSG - -- pokefirered/src/union_room.c:2551 - say(st, RomText.plain("gText_UR_WirelessSearchCanceled"), toSourcePromptOffline) + toMainMenuOffline(st) end return nil end - if st.state == S.COMMUNICATING then - st.timer = (st.timer or 0) + 1 - if st.timer >= Ui.COMMUNICATING_FRAMES then - local entry = st.offer - st.offer = nil - deliverOffer(st, entry) - end - return nil - end - - if st.state == S.COMM_COMPLETED then - st.timer = (st.timer or 0) + 1 - if st.timer > Ui.COMPLETED_FRAMES then - local r = st.pendingResult or {} - st.pendingResult = nil - closeOffers(st) - clientResult(st, r.key or "gText_CommunicationError", r.success) + if st.state == S.NEWS_VIEW then + tickNewsScroll(st, pressed) + if pressed("a") or pressed("b") then + se(5) + st.viewNews = nil + st.state = S.OFFER_LIST + st.prompt = Ui.listPrompt(st) end return nil end @@ -763,54 +648,23 @@ function Ui.update(st, pressed, dt) if st.state == S.SAVE then local ok = true if st.onSave then ok = st.onSave(session(st)) ~= false end - local nextState = st.saveNext - st.saveNext = nil st.state = S.SAVE_DONE -- pokefirered/src/strings.c:1322 gText_SaveCompletedPressA say(st, ok and RomText.plain("gText_SaveCompletedPressA") - or Strings("Save failed."), function(s) - if nextState == S.TOSSED then - s.state = S.TOSSED - -- pokefirered/src/strings.c:1323 gText_WonderCardThrownAway - say(s, s.isNews and RomText.plain("gText_WonderNewsThrownAway") - or RomText.plain("gText_WonderCardThrownAway"), toMainMenu) - else - toMainMenu(s) - end - end) + or Strings("Save failed."), toMainMenu) return nil end if st.state == S.GIFT_INPUT then - if st.isNews then tickNewsScroll(st, pressed) end - if pressed("a") then + if pressed("a") and st.viewOffer then se(5) - st.state = S.GIFT_SELECT - setRows(st, Ui.giftRows(st), 1) - elseif pressed("b") then + pickOffer(st, st.viewOffer) + elseif pressed("a") or pressed("b") then se(5) - toMainMenu(st) - end - return nil - end - - if st.state == S.GIFT_SELECT then - local pick = tickList(st, pressed) - if not pick then return nil end - local action = (pick > 0) and (st.giftActions or {})[pick] or nil - if pick == -1 or action == "cancel" then - st.state = S.GIFT_INPUT - elseif action == "receive" then - toSourcePrompt(st) - elseif action == "send" then - st.state = S.NO_LINK - -- pokefirered/src/strings.c:24 gText_WirelessNotConnected - say(st, RomText.plain("gText_WirelessNotConnected"), function(s) - s.state = S.GIFT_SELECT - setRows(s, Ui.giftRows(s), 1) - end) - elseif action == "toss" then - askToss(st) + st.viewCard = nil + st.viewOffer = nil + st.state = S.OFFER_LIST + st.prompt = Ui.listPrompt(st) end return nil end @@ -828,8 +682,8 @@ end local function drawTopBar(st) Window.printPx(RomText.plain("gText_MysteryGift2"), 2, 2, { colors = TOP_TEXT }) local S = Ui.STATE - local useExit = st.state == S.SOURCE_INPUT or st.state == S.SEARCHING - or st.state == S.OFFER_LIST or st.state == S.COMMUNICATING + local useExit = st.state == S.SEARCHING + or st.state == S.OFFER_LIST local hint = useExit and RomText.plain("gText_PickOKExit") or RomText.plain("gText_PickOKCancel") @@ -926,7 +780,7 @@ function Ui.drawCard(st) if (tonumber(card.type) or 0) == MysteryGift.CARD_TYPE_GIFT then Window.printPx(card.footerLine2Text or "", fx, fy + off + 16, { colors = footerColors }) elseif (tonumber(card.type) or 0) == MysteryGift.CARD_TYPE_LINK_STAT then - local meta = MysteryGift.getSavedCardMetadata(session(st)) + local meta = Ui.cardMetadata(st) local line = string.format("%03d - %03d - %03d", math.min(tonumber(meta.battlesWon) or 0, MysteryGift.MAX_WONDER_CARD_STAT), math.min(tonumber(meta.battlesLost) or 0, MysteryGift.MAX_WONDER_CARD_STAT), @@ -934,7 +788,7 @@ function Ui.drawCard(st) Window.printPx(line, fx, fy + off + 16, { colors = footerColors }) end - local meta = MysteryGift.getSavedCardMetadata(session(st)) + local meta = Ui.cardMetadata(st) drawMonIcon(tonumber(meta.iconSpecies), 220, 20) -- pokefirered/src/mystery_gift_show_card.c:460 CreateCardSprites local maxStamps = tonumber(card.maxStamps) or 0 @@ -974,9 +828,7 @@ end function Ui.draw(st) local S = Ui.STATE - if st.state == S.GIFT_INPUT or st.state == S.GIFT_SELECT - or st.state == S.ASK_TOSS or st.state == S.ASK_TOSS_UNRECEIVED - or st.state == S.NO_LINK then + if st.state == S.GIFT_INPUT or st.state == S.NEWS_VIEW then if st.isNews then Ui.drawNews(st) else Ui.drawCard(st) end else drawMenuBg() @@ -985,12 +837,8 @@ function Ui.draw(st) if st.state == S.MAIN_MENU then drawList(st, Ui.threeOptionTemplate(st.rows)) - elseif st.state == S.SOURCE_INPUT then - drawList(st, Ui.threeOptionTemplate(st.rows)) elseif st.state == S.OFFER_LIST and st.list then st.list:draw() - elseif st.state == S.GIFT_SELECT then - drawList(st, (#(st.rows or {}) > 3) and GIFT3_WIN or GIFT2_WIN) end if st.yesno then diff --git a/tests/drivers/g3gift_wireless.lua b/tests/drivers/g3gift_wireless.lua index e0b7000d..7c501670 100644 --- a/tests/drivers/g3gift_wireless.lua +++ b/tests/drivers/g3gift_wireless.lua @@ -109,13 +109,9 @@ return function(game) return st.state == S.MAIN_MENU and not st.msg end - local function searchFromPicker(label) - if not result(advance(function() return st.state == S.SOURCE_INPUT end), - label .. ": the source picker opened") then return false end - result(st.cursor == 1, label .. ": the cursor starts on WIRELESS COMMUNICATION") - U.tap(game, "a") - result(st.state == S.SEARCHING, label .. ": WIRELESS COMMUNICATION starts the search") - return true + local function startFetch(label) + return result(advance(function() return st.state == S.SEARCHING end), + label .. ": the card fetch starts with no source picker") end local function waitList(label) @@ -132,9 +128,20 @@ return function(game) U.tap(game, "a") end + local function openCards(label) + U.tap(game, "a") + if not startFetch(label) then return false end + return waitList(label) + end + + local function replaceYes() + result(advance(function() return st.state == S.ASK_REPLACE end), "the cart asks to throw away the held card") + U.tap(game, "a") + if st.state == S.ASK_REPLACE_UNRECEIVED then U.tap(game, "a") end + end + U.tap(game, "a") - result(st.state == S.DONT_HAVE_ANY, "WONDER CARDS with no card asks for one") - if not searchFromPicker("owner key") then return finish() end + if not startFetch("owner key") then return finish() end result(advance(function() return st.state ~= S.SEARCHING end, 15) and st.lastError == "bad_signature", "a feed not signed by the owner's key is refused, err=" .. tostring(st.lastError)) U.wait(90) @@ -146,11 +153,9 @@ return function(game) MysteryGift.GIFT_PUBKEY = TEST_PUBKEY U.tap(game, "a") - result(st.state == S.DONT_HAVE_ANY, "WONDER CARDS with no card asks for one") - if not searchFromPicker("card") then return finish() end - U.wait(8) + if not startFetch("card") then return finish() end + U.wait(2) result(WirelessIcon.anim() == "searching", "the wireless icon is searching") - result(st.state == S.SEARCHING, "the searching text holds") U.still(game, DIR .. "/g3gift_searching.png") if not waitList("card") then return finish() end U.wait(12) @@ -163,8 +168,12 @@ return function(game) U.still(game, DIR .. "/g3gift_card_list.png") pickRow(2) - result(advance(function() return st.state == S.COMM_COMPLETED end), "MEW: communication completes") - result(advance(function() return st.state == S.RESULT_MSG end), "MEW: the result message is up") + result(st.state == S.GIFT_INPUT and st.viewCard ~= nil and st.viewCard.titleText == "MEW", + "MEW: pressing the row shows the card first") + U.wait(10) + U.still(game, DIR .. "/g3gift_card_preview.png") + U.tap(game, "a") + result(advance(function() return st.state == S.RESULT_MSG end), "MEW: A receives it") print("[driver] result: " .. tostring(st.msg and st.msg.text)) result(advance(atMenu, 15), "MEW: saved and back on the Mystery Gift menu") local sess = st.session @@ -172,18 +181,24 @@ return function(game) result(card ~= nil and card.idNumber == 7 and card.titleText == "MEW", "the MEW Wonder Card is installed") result(MysteryGift.hasClaimedCard(sess, 7), "and claimed on this save") - U.tap(game, "a") - result(st.state == S.GIFT_INPUT, "WONDER CARDS opens the received card") + if not openCards("held") then return finish() end + U.wait(12) + U.still(game, DIR .. "/g3gift_card_list_marked.png") + pickRow(2) + result(st.state == S.GIFT_INPUT and st.viewCard == nil, "pressing the held MEW opens it") U.wait(10) U.still(game, DIR .. "/g3gift_received_wonder_card.png") U.tap(game, "b") - U.wait(6) + U.wait(4) + result(st.state == S.OFFER_LIST, "B goes back to the card list") + U.tap(game, "b") + U.wait(4) + result(atMenu(), "B on the list goes back to the Mystery Gift menu") U.tap(game, "down") U.wait(4) U.tap(game, "a") - result(st.state == S.DONT_HAVE_ANY and st.isNews, "WONDER NEWS with no news asks for one") - if not searchFromPicker("news") then return finish() end + result(st.state == S.SEARCHING and st.isNews, "WONDER NEWS fetches the list at once") if not waitList("news") then return finish() end labels = {} for i, entry in ipairs(st.offers or {}) do labels[i] = tostring(entry.label) end @@ -192,56 +207,42 @@ return function(game) U.wait(6) U.still(game, DIR .. "/g3gift_news_list.png") pickRow(1) - result(advance(atMenu, 15), "news: saved and back on the Mystery Gift menu") - result(MysteryGift.validateSavedNews(sess), "the Wonder News is installed") - U.tap(game, "down") - U.wait(4) - U.tap(game, "a") - result(st.state == S.GIFT_INPUT and st.isNews, "WONDER NEWS opens the received news") + result(st.state == S.NEWS_VIEW and st.viewNews ~= nil, "pressing the row opens that news") U.wait(10) U.still(game, DIR .. "/g3gift_wonder_news.png") U.tap(game, "b") - U.wait(6) - - U.tap(game, "a") U.wait(4) - U.tap(game, "a") - result(st.state == S.GIFT_SELECT, "the card menu is up") - local tossRow - for i, a in ipairs(st.giftActions or {}) do if a == "toss" then tossRow = i end end - pickRow(tossRow or 2) - result(st.state == S.ASK_TOSS, "TOSS asks first") - U.tap(game, "a") - if st.state == S.ASK_TOSS_UNRECEIVED then U.tap(game, "a") end - result(advance(atMenu, 15), "the MEW card is tossed") - result(not MysteryGift.validateSavedCard(sess), "no card is held") - U.tap(game, "a") - if not searchFromPicker("reclaim") then return finish() end - if not waitList("reclaim") then return finish() end - pickRow(2) - result(advance(function() return st.state == S.RESULT_MSG end), "reclaim: the result message is up") - U.wait(60) - print("[driver] reclaim: " .. tostring(st.msg and st.msg.text)) - result(st.msg ~= nil and tostring(st.msg.text):find("already") ~= nil, "a second MEW is refused as already had") - U.still(game, DIR .. "/g3gift_already_had.png") - result(advance(atMenu, 15), "back on the menu") - result(not MysteryGift.validateSavedCard(sess), "and nothing was installed") + result(st.state == S.OFFER_LIST, "B goes back to the news list") + U.tap(game, "b") + U.wait(4) + result(atMenu(), "B on the list goes back to the Mystery Gift menu") + result(not MysteryGift.validateSavedNews(sess), "reading news saves nothing") - U.tap(game, "a") - if not searchFromPicker("stamp") then return finish() end - if not waitList("stamp") then return finish() end + if not openCards("stamp") then return finish() end pickRow(3) + U.tap(game, "a") + replaceYes() result(advance(atMenu, 15), "stamp: saved and back on the menu") card = MysteryGift.getSavedCard(sess) - result(card ~= nil and card.type == MysteryGift.CARD_TYPE_STAMP, "the STAMP CARD is installed") + result(card ~= nil and card.type == MysteryGift.CARD_TYPE_STAMP, "switching installs the STAMP CARD") MysteryGift.trySaveStamp(sess, { species = 25, id = 11111 }) MysteryGift.trySaveStamp(sess, { species = 4, id = 22222 }) - U.tap(game, "a") - result(st.state == S.GIFT_INPUT, "the STAMP CARD opens") + if not openCards("stamp view") then return finish() end + pickRow(3) + result(st.state == S.GIFT_INPUT and st.viewCard == nil, "the held STAMP CARD opens") U.wait(10) U.still(game, DIR .. "/g3gift_stamp_card.png") U.tap(game, "b") - U.wait(6) + U.wait(4) + + U.tap(game, "up") + U.wait(4) + U.tap(game, "a") + U.tap(game, "a") + replaceYes() + result(advance(atMenu, 15), "switch back: saved and back on the menu") + card = MysteryGift.getSavedCard(sess) + result(card ~= nil and card.idNumber == 7, "the MEW card you had before installs again") local SaveData = require("src.core.SaveData") local okLoad, saved = pcall(SaveData.load) @@ -251,7 +252,6 @@ return function(game) local have7 = false for _, id in ipairs(claims.cards or {}) do if tonumber(id) == 7 then have7 = true end end result(have7, "the MEW claim is on the save file") - result(rec ~= nil and rec.news ~= nil, "the news is on the save file") U.tap(game, "b") for _ = 1, 400 do diff --git a/tests/drivers/game3_gift_menu.lua b/tests/drivers/game3_gift_menu.lua index 1c0fa3ef..89e0bea5 100644 --- a/tests/drivers/game3_gift_menu.lua +++ b/tests/drivers/game3_gift_menu.lua @@ -106,80 +106,48 @@ return function(game) "it opens on WONDER CARDS / WONDER NEWS / EXIT") U.shot(game, DIR .. "/gift_menu_03_front_end.png") - U.tap(game, "a") - U.wait(20) - result(st.state == Ui.STATE.GIFT_INPUT, "WONDER CARDS opens the saved card, state=" .. - tostring(st.state)) - local card = Ui.card(st) - print("[driver] card title: " .. tostring(card and card.titleText)) - result(card ~= nil and card.titleText == "MYSTIC TICKET", "the card is the MYSTIC TICKET") - U.wait(10) - U.shot(game, DIR .. "/gift_menu_04_wonder_card.png") + local function backToMenu() + if st.state == Ui.STATE.OFFER_LIST then U.tap(game, "b") end + for _ = 1, 300 do + if st.state == Ui.STATE.MAIN_MENU and not st.msg then break end + if st.msg and st.msg.revealed >= st.msg.total then U.tap(game, "a") end + U.wait(4) + end + end U.tap(game, "a") - U.wait(12) - result(st.state == Ui.STATE.GIFT_SELECT, "A opens RECEIVE / TOSS / CANCEL") - print("[driver] card menu rows: " .. table.concat(st.rows or {}, " | ")) - U.shot(game, DIR .. "/gift_menu_05_card_menu.png") - - U.tap(game, "b") - U.wait(12) - U.tap(game, "b") - U.wait(12) + U.wait(2) + result(st.state == Ui.STATE.SEARCHING and not st.isNews, + "WONDER CARDS fetches the list, not the saved card, state=" .. tostring(st.state)) + local cardDeadline = love.timer.getTime() + 15 + while st.state == Ui.STATE.SEARCHING and love.timer.getTime() < cardDeadline do U.wait(1) end + print("[driver] card fetch ended in state=" .. tostring(st.state) .. " err=" .. tostring(st.lastError)) + result(st.state == Ui.STATE.OFFER_LIST or st.state == Ui.STATE.RESULT_MSG, + "the fetch ends on the card list or the cart's error, state=" .. tostring(st.state)) + U.wait(30) + U.shot(game, DIR .. "/gift_menu_04_card_list.png") + backToMenu() result(st.state == Ui.STATE.MAIN_MENU, "B backs out to the Mystery Gift menu") U.tap(game, "down") U.wait(6) U.tap(game, "a") - U.wait(12) - for _ = 1, 300 do - if st.state == Ui.STATE.SOURCE_INPUT then break end - U.tap(game, "a") - U.wait(4) - end - -- pokefirered/src/mystery_gift_menu.c:1176 - result(st.state == Ui.STATE.SOURCE_INPUT, - "WONDER NEWS with no saved news asks where to access it, state=" .. tostring(st.state)) - print("[driver] news source rows: " .. table.concat(st.rows or {}, " | ")) - -- pokefirered/src/mystery_gift_menu.c:203 - result(#(st.rows or {}) == 3, "WIRELESS COMMUNICATION / FRIEND / CANCEL") + result(st.state == Ui.STATE.SEARCHING and st.isNews, "WONDER NEWS fetches the list at once") + local fetchDeadline = love.timer.getTime() + 15 + while st.state == Ui.STATE.SEARCHING and love.timer.getTime() < fetchDeadline do U.wait(1) end + print("[driver] news fetch ended in state=" .. tostring(st.state) .. " err=" .. tostring(st.lastError)) + result(st.state == Ui.STATE.OFFER_LIST or st.state == Ui.STATE.RESULT_MSG, + "the fetch ends on the news list or the cart's error, state=" .. tostring(st.state)) U.wait(30) - U.shot(game, DIR .. "/gift_menu_06_news_source_prompt.png") - U.tap(game, "b") + U.shot(game, DIR .. "/gift_menu_06_news_list.png") + if st.state == Ui.STATE.OFFER_LIST then U.tap(game, "b") end for _ = 1, 300 do if st.state == Ui.STATE.MAIN_MENU and not st.msg then break end + if st.msg and st.msg.revealed >= st.msg.total then U.tap(game, "a") end U.wait(4) end result(st.state == Ui.STATE.MAIN_MENU, "B comes back to the Mystery Gift menu") - U.tap(game, "a") - U.wait(12) - U.tap(game, "a") - U.wait(12) - for _ = 1, 300 do - if st.state == Ui.STATE.GIFT_SELECT then break end - U.tap(game, "a") - U.wait(4) - end - result(st.state == Ui.STATE.GIFT_SELECT, "the card menu is back up") - U.tap(game, "a") - for _ = 1, 300 do - if st.state == Ui.STATE.SOURCE_INPUT then break end - U.tap(game, "a") - U.wait(4) - end - result(st.state == Ui.STATE.SOURCE_INPUT, "RECEIVE asks where the WONDER CARD should be accessed") - print("[driver] source rows: " .. table.concat(st.rows or {}, " | ")) - -- pokefirered/src/mystery_gift_menu.c:203 - result(#(st.rows or {}) == 3, "WIRELESS COMMUNICATION / FRIEND / CANCEL") - U.wait(10) - U.shot(game, DIR .. "/gift_menu_07_source_picker.png") - - U.tap(game, "b") - U.wait(12) - U.tap(game, "b") - U.wait(12) - U.tap(game, "b") for _ = 1, 200 do if phase() == Boot.PHASE.MENU then break end diff --git a/tests/drivers/game3_gift_ticket.lua b/tests/drivers/game3_gift_ticket.lua index 3df9969e..a1b49650 100644 --- a/tests/drivers/game3_gift_ticket.lua +++ b/tests/drivers/game3_gift_ticket.lua @@ -150,16 +150,8 @@ return function(game) end local st = game.boot.gift - U.tap(game, "a") - for _ = 1, 300 do - if st.state == GiftUi.STATE.GIFT_INPUT then break end - if st.msg then U.tap(game, "a") end - U.wait(4) - end - result(st.state == GiftUi.STATE.GIFT_INPUT, "the saved WONDER CARD opens") - U.shot(game, DIR .. "/gift_ticket_03_wonder_card.png") - U.tap(game, "b") - U.wait(20) + result(st.state == GiftUi.STATE.MAIN_MENU, "the Mystery Gift menu is up") + U.shot(game, DIR .. "/gift_ticket_03_mystery_gift_menu.png") U.tap(game, "b") for _ = 1, 200 do if phase() == Boot.PHASE.MENU then break end diff --git a/tests/game3_gift_menu_test.lua b/tests/game3_gift_menu_test.lua index 3309b794..a11c5434 100644 --- a/tests/game3_gift_menu_test.lua +++ b/tests/game3_gift_menu_test.lua @@ -145,10 +145,13 @@ local function giftSession(save) end local function openWireless(st, d, isNews) - if isNews then d.step("down") end - d.step("a") - d.waitFor(function() return st.state == Ui.STATE.SOURCE_INPUT end) + if isNews then + d.step("down") + d.step("a") + return + end d.step("a") + d.waitFor(function() return st.state == Ui.STATE.SEARCHING end) end print("[test] 1. The main menu rows") @@ -256,28 +259,11 @@ do teq(rows[3], "EXIT", "EXIT is the third row") step("a") - eq(st.state, Ui.STATE.DONT_HAVE_ANY, "no card saved takes the input branch") - check(st.msg ~= nil, "it says so first") - finishMessage() - eq(st.state, Ui.STATE.SOURCE_PROMPT, "then asks where to read one from") - step(nil) - eq(st.state, Ui.STATE.SOURCE_INPUT, "the source picker opens") - tcheck(type(st.prompt) == "string" and st.prompt:find("WONDER CARD"), - "the prompt names the WONDER CARD") - - eq(#st.rows, 3, "the picker has three rows") - -- pokefirered/src/mystery_gift_menu.c:203 - teq(st.rows[1], "WIRELESS COMMUNICATION", "row 1 is WIRELESS COMMUNICATION") - teq(st.rows[2], "FRIEND", "row 2 is FRIEND") - teq(st.rows[3], "CANCEL", "the picker ends in CANCEL") - step("a") - eq(st.state, Ui.STATE.SEARCHING, "WIRELESS COMMUNICATION starts the search") + eq(st.state, Ui.STATE.SEARCHING, "WONDER CARDS fetches the card list at once") eq(feedTransport.calls, 1, "one request goes out") eq(WirelessIcon.anim(), "searching", "the wireless icon plays its searching anim") tcheck(type(st.prompt) == "string" and st.prompt:find("Searching for a WIRELESS"), "with the cart's searching text") - for _ = 1, Ui.SEARCH_MIN_FRAMES - 1 do step(nil) end - eq(st.state, Ui.STATE.SEARCHING, "the search holds for the cart's two seconds") d.waitFor(function() return st.state ~= Ui.STATE.SEARCHING end) eq(st.state, Ui.STATE.OFFER_LIST, "the verified feed opens the card list") eq(WirelessIcon.anim(), "3bars", "the icon shows the link") @@ -289,11 +275,15 @@ do eq(lm and lm.items[2].label, "MEW", "row 2 is MEW") eq(lm and lm.opts.maxShowed, 5, "five rows show at once") step("a") - eq(st.state, Ui.STATE.COMMUNICATING, "picking a card starts communicating") - d.waitFor(function() return st.state == Ui.STATE.COMM_COMPLETED end) + eq(st.state, Ui.STATE.GIFT_INPUT, "pressing a card shows it first") + eq(Ui.card(st).titleText, "MYSTIC TICKET", "the preview is the picked card") + check(not MysteryGift.validateSavedCard(sess), "a preview installs nothing") + local okDraw, err = pcall(Ui.draw, st) + tcheck(okDraw, "the preview draws: " .. tostring(err)) + step("a") + eq(st.state, Ui.STATE.RESULT_MSG, "A receives it at once") eq(WirelessIcon.anim(), nil, "the icon goes away when the link ends") check(MysteryGift.validateSavedCard(sess), "the card is installed") - d.waitFor(function() return st.state == Ui.STATE.RESULT_MSG end) tcheck(st.msg ~= nil and tostring(st.msg.text):find("WONDER CARD"), "the received message names the card") check(st.msg ~= nil and st.msg.hold == Ui.SUCCESS_FRAMES, "the success message holds for the fanfare") eq(fanfares[#fanfares], 258, "MUS_OBTAIN_ITEM plays") @@ -312,76 +302,36 @@ do "FLAG_SYS_MYSTERY_GIFT_ENABLED reached the save table") end -print("[test] 5. The card view and its menu") +print("[test] 5. The list marks the held card and opens it") do - local keys = {} - local function pressed(k) return keys[k] == true end - local function step(k) - keys = {} - if k then keys[k] = true end - Ui.update(st, pressed, 1 / 60) - end - local function confirmMessage() - for _ = 1, 600 do - if not st.msg then return end - if st.msg.revealed >= st.msg.total then - step("a") - return - end - step(nil) - end - end - - step("a") - eq(st.state, Ui.STATE.GIFT_INPUT, "WONDER CARDS now opens the card") + local d = driver(st) + d.step("a") + eq(st.state, Ui.STATE.SEARCHING, "WONDER CARDS fetches again") + d.waitFor(function() return st.state ~= Ui.STATE.SEARCHING end) + eq(st.state, Ui.STATE.OFFER_LIST, "the list opens") + local lm = ListStub.last + -- pokefirered/src/union_room.c:4072 + eq(lm and lm.items[1].colors, ListStub.COLOR_WHITE, "the MYSTIC TICKET shows as already had") + eq(lm and lm.items[2].colors, nil, "MEW does not") + d.step("a") + eq(st.state, Ui.STATE.GIFT_INPUT, "pressing the held card opens it") local card = Ui.card(st) eq(card.titleText, "MYSTIC TICKET", "the saved card is the MYSTIC TICKET") eq(#card.bodyText, 4, "the card carries four body lines") - - step("a") - eq(st.state, Ui.STATE.GIFT_SELECT, "A opens the card menu") - -- pokefirered/src/mystery_gift_menu.c:237 sListMenuItems_ReceiveToss - eq(#st.rows, 3, "a card that may not be sent shows three rows") - teq(st.rows[1], "RECEIVE", "row 1 is RECEIVE") - teq(st.rows[2], "TOSS", "row 2 is TOSS") - teq(st.rows[3], "CANCEL", "row 3 is CANCEL") - - step("down") - step("a") - eq(st.state, Ui.STATE.ASK_TOSS, "TOSS asks first") - tcheck(st.yesno ~= nil and st.yesno.text:find("event won't happen"), - "and warns that the event will not happen") - step("a") - eq(st.state, Ui.STATE.ASK_TOSS_UNRECEIVED, "an uncollected gift asks a second time") - step("a") - eq(st.state, Ui.STATE.SAVE, "yes tosses the card and saves") - confirmMessage() - step(nil) - eq(st.state, Ui.STATE.SAVE_DONE, "the toss is saved too") - confirmMessage() - eq(st.state, Ui.STATE.TOSSED, "the thrown-away message follows the save") - tcheck(st.msg ~= nil and st.msg.text:find("thrown away"), "and it names the WONDER CARD") - confirmMessage() - eq(st.state, Ui.STATE.MAIN_MENU, "then back to the Mystery Gift menu") - check(not MysteryGift.validateSavedCard(sess), "the saved card is gone") - check(MysteryGift.applyToSave(sess, save), "the cleared record writes back") - check(save.modData.mysteryGift.card == nil, "the save table lost the card") + local okDraw, err = pcall(Ui.draw, st) + tcheck(okDraw, "the card view draws: " .. tostring(err)) + d.step("b") + eq(st.state, Ui.STATE.OFFER_LIST, "B goes back to the list") + d.step("b") + eq(st.state, Ui.STATE.MAIN_MENU, "B on the list goes back to the menu") + check(MysteryGift.validateSavedCard(sess), "the held card stays") end print("[test] 6. Wonder News paging") do - local newsSave = {} - local newsSess = giftSession(newsSave) local body = {} for i = 1, 10 do body[i] = "LINE " .. i end - check(MysteryGift.receiveNews(newsSess, { - id = 7, - sendType = MysteryGift.SEND_TYPE_ALLOWED, - bgType = 1, - titleText = "WONDER NEWS", - bodyText = body, - }), "the news saves") - local nst = Ui.new({ session = newsSess, onSave = function() return true end }) + local nst = Ui.new({ session = giftSession({}), onSave = function() return true end }) local keys = {} local function pressed(k) return keys[k] == true end local function step(k) @@ -389,11 +339,10 @@ do if k then keys[k] = true end Ui.update(nst, pressed, 1 / 60) end - step("down") - step("a") - eq(nst.state, Ui.STATE.GIFT_INPUT, "WONDER NEWS opens the news") - check(nst.isNews, "the news branch is active") - eq(nst.newsScroll, 0, "the news starts unscrolled") + nst.isNews = true + nst.viewNews = { id = 7, bgType = 1, titleText = "WONDER NEWS", bodyText = body } + nst.newsScroll = 0 + nst.state = Ui.STATE.NEWS_VIEW step("down") eq(nst.newsScroll, 1, "down scrolls one line") step("down") @@ -405,6 +354,9 @@ do eq(nst.newsScroll, 1, "up scrolls back") local okDraw, err = pcall(Ui.draw, nst) tcheck(okDraw, "the news view draws: " .. tostring(err)) + step("b") + eq(nst.state, Ui.STATE.OFFER_LIST, "B goes back to the news list") + check(nst.viewNews == nil, "and drops the news it showed") end local function freshScreen(t, save) @@ -426,20 +378,22 @@ print("[test] 7. Wonder News over WIRELESS COMMUNICATION") do local st2, d, sess2 = freshScreen(okFeed()) openWireless(st2, d, true) - eq(st2.state, Ui.STATE.SEARCHING, "WONDER NEWS searches too") + eq(st2.state, Ui.STATE.SEARCHING, "WONDER NEWS fetches the list at once") searchResult(st2, d) eq(st2.state, Ui.STATE.OFFER_LIST, "the news list opens") eq(#ListStub.last.items, 1, "only news rows are listed") eq(ListStub.last.items[1].label, "WONDER NEWS", "the news title is the row") d.step("a") - d.waitFor(function() return st2.state == Ui.STATE.SAVE end) - check(MysteryGift.validateSavedNews(sess2), "the news is installed") - eq(MysteryGift.getSavedNewsMetadata(sess2).newsType, MysteryGift.WONDER_NEWS_RECV_WIRELESS, - "the reward is the wireless one") - check(MysteryGift.hasClaimedNews(sess2, 1), "the news id is claimed") + eq(st2.state, Ui.STATE.NEWS_VIEW, "pressing a row opens that news") + eq(st2.viewNews and st2.viewNews.titleText, "WONDER NEWS", "the picked news is the one shown") + check(not MysteryGift.validateSavedNews(sess2), "reading saves nothing") + d.step("b") + eq(st2.state, Ui.STATE.OFFER_LIST, "B goes back to the list") + d.step("b") + eq(st2.state, Ui.STATE.MAIN_MENU, "B on the list goes back to the menu") end -print("[test] 8. One claim per card per save") +print("[test] 8. Cards you had before stay marked and can be switched back to") do local save = {} local st2, d, sess2 = freshScreen(okFeed(), save) @@ -447,8 +401,12 @@ do searchResult(st2, d) d.step("down") d.step("a") + d.step("a") d.waitFor(function() return st2.state == Ui.STATE.MAIN_MENU and not st2.msg end) eq(MysteryGift.getSavedCard(sess2).idNumber, 7, "the MEW card is installed") + local giftFlag = MysteryGift.receivedGiftFlag(MysteryGift.getSavedCard(sess2).flagId) + check(giftFlag ~= nil, "the MEW card has a received-gift flag") + MysteryGift.setFlag(sess2, giftFlag, true) MysteryGift.clearCardAndRelated(sess2) check(not MysteryGift.validateSavedCard(sess2), "then tossed") @@ -458,20 +416,23 @@ do "the claimed card prints greyed in the list") d.step("down") d.step("a") - d.waitFor(function() return st2.state == Ui.STATE.RESULT_MSG end) - -- pokefirered/src/mystery_gift_menu.c:911 - tcheck(st2.msg ~= nil and tostring(st2.msg.text):find("already"), "the second claim says it was already had") - check(not MysteryGift.validateSavedCard(sess2), "and installs nothing") + d.step("a") d.waitFor(function() return st2.state == Ui.STATE.MAIN_MENU and not st2.msg end) - eq(st2.state, Ui.STATE.MAIN_MENU, "back to the Mystery Gift menu") + eq(MysteryGift.getSavedCard(sess2).idNumber, 7, "a card you had before installs again") + check(not MysteryGift.isGiftNotReceived(sess2), "and a gift already collected stays collected") local reopened, d2, sess3 = freshScreen(okFeed(), save) check(MysteryGift.hasClaimedCard(sess3, 7), "the claim was saved with the game") openWireless(reopened, d2, false) searchResult(reopened, d2) + eq(ListStub.last.items[2].colors, ListStub.COLOR_WHITE, "and still prints greyed after a reload") d2.step("a") + d2.step("a") + d2.waitFor(function() return reopened.state == Ui.STATE.ASK_REPLACE end) + d2.step("a") + if reopened.state == Ui.STATE.ASK_REPLACE_UNRECEIVED then d2.step("a") end d2.waitFor(function() return reopened.state == Ui.STATE.SAVE end) - eq(MysteryGift.getSavedCard(sess3).idNumber, 1, "a different card still installs") + eq(MysteryGift.getSavedCard(sess3).idNumber, 1, "switching to another card replaces the held one") end print("[test] 9. Replacing a held card asks first") @@ -479,25 +440,16 @@ do local st2, d, sess2 = freshScreen(okFeed()) MysteryGift.receiveCard(sess2, MysteryGift.builtins()[2].card) d.step("a") - eq(st2.state, Ui.STATE.GIFT_INPUT, "the held card opens") - d.step("a") - eq(st2.state, Ui.STATE.GIFT_SELECT, "its menu opens") - d.step("a") - eq(st2.state, Ui.STATE.SOURCE_PROMPT, "RECEIVE asks where from") - d.step(nil) - d.step("a") - eq(st2.state, Ui.STATE.SEARCHING, "WIRELESS COMMUNICATION searches") + eq(st2.state, Ui.STATE.SEARCHING, "WONDER CARDS fetches the list") searchResult(st2, d) d.step("a") + d.step("a") d.waitFor(function() return st2.state == Ui.STATE.ASK_REPLACE end) check(st2.yesno ~= nil, "the cart's throw-away question is up") d.step("a") eq(st2.state, Ui.STATE.ASK_REPLACE_UNRECEIVED, "an uncollected gift asks again") d.step("b") - eq(st2.state, Ui.STATE.COMM_COMPLETED, "declining ends the link") - d.waitFor(function() return st2.state == Ui.STATE.RESULT_MSG end) - -- pokefirered/src/mystery_gift_menu.c:927 - tcheck(st2.msg ~= nil and tostring(st2.msg.text):find("canceled"), "with communication canceled") + eq(st2.state, Ui.STATE.OFFER_LIST, "declining goes back to the list") eq(MysteryGift.getSavedCard(sess2).idNumber, 2, "the held card stays") end @@ -509,8 +461,8 @@ do eq(st2.state, Ui.STATE.RESULT_MSG, "no network ends the search") eq(WirelessIcon.anim(), "error", "the icon shows the error") tcheck(st2.msg ~= nil and tostring(st2.msg.text):find("Wireless Adapter"), "with the cart's not-connected text") - d.waitFor(function() return st2.state == Ui.STATE.SOURCE_INPUT end) - eq(st2.state, Ui.STATE.SOURCE_INPUT, "and it goes back to the source picker") + d.waitFor(function() return st2.state == Ui.STATE.MAIN_MENU end) + eq(st2.state, Ui.STATE.MAIN_MENU, "and it goes back to the menu") eq(WirelessIcon.anim(), nil, "with the icon gone") local body = FIXTURE_BODY:gsub('\\"item\\":370', '\\"item\\":371') @@ -542,8 +494,8 @@ do eq(empty.state, Ui.STATE.RESULT_MSG, "an empty news set ends the search") -- pokefirered/src/union_room.c:2559 tcheck(empty.msg ~= nil and tostring(empty.msg.text):find("NEWS"), "with the cart's no-news-shared text") - ed.waitFor(function() return empty.state == Ui.STATE.SOURCE_INPUT end) - eq(empty.state, Ui.STATE.SOURCE_INPUT, "and it goes back to the source picker") + ed.waitFor(function() return empty.state == Ui.STATE.MAIN_MENU end) + eq(empty.state, Ui.STATE.MAIN_MENU, "and it goes back to the menu") local slow = transport({ status = "pending" }) local canceled, cd = freshScreen(slow) @@ -554,16 +506,6 @@ do eq(canceled.state, Ui.STATE.RESULT_MSG, "B stops the search") tcheck(canceled.msg ~= nil and tostring(canceled.msg.text):find("canceled"), "with the cart's search-canceled text") - local friend, frd = freshScreen(okFeed()) - friend.state = Ui.STATE.MAIN_MENU - frd.step("a") - frd.waitFor(function() return friend.state == Ui.STATE.SOURCE_INPUT end) - frd.step("down") - frd.step("a") - eq(friend.state, Ui.STATE.RESULT_MSG, "FRIEND answers with a message") - tcheck(friend.msg ~= nil and tostring(friend.msg.text):find("Wireless Adapter"), "the not-connected text") - frd.waitFor(function() return friend.state == Ui.STATE.SOURCE_INPUT end) - eq(friend.state, Ui.STATE.SOURCE_INPUT, "and back to the picker") end print("[test] 11. The save message runs the save with no button press") @@ -579,6 +521,7 @@ do openWireless(st2, d, false) searchResult(st2, d) step("a") + step("a") d.waitFor(function() return st2.state == Ui.STATE.RESULT_MSG end) eq(st2.state, Ui.STATE.RESULT_MSG, "the card arrives") for _ = 1, 1200 do @@ -639,7 +582,7 @@ do teq(locked.rows[2], "EXIT", "row 2 is EXIT") Ui.update(locked, function(k) return k == "a" end, 1 / 60) check(locked.isNews, "the first row opens the news branch") - eq(locked.state, Ui.STATE.DONT_HAVE_ANY, "with no news saved yet") + eq(locked.state, Ui.STATE.SEARCHING, "which fetches the news list") local open = Ui.new({ session = giftSession({}), onSave = function() return true end }) eq(#open.rows, 3, "the passphrase adds WONDER CARDS back")