wait for initial load when transitioning states

develop
Myk Taylor 2023-09-24 17:01:06 -07:00
parent 4ffa78c96c
commit 92b35e32cb
No known key found for this signature in database
1 changed files with 15 additions and 10 deletions

@ -151,18 +151,14 @@ end
test_envvars.require = clean_require test_envvars.require = clean_require
test_envvars.reqscript = clean_reqscript test_envvars.reqscript = clean_reqscript
local function is_title_screen(scr) local function is_title_screen()
scr = scr or dfhack.gui.getCurViewscreen() return dfhack.gui.matchFocusString('title/Default')
return df.viewscreen_titlest:is_instance(scr)
end end
-- This only handles pre-fortress-load screens. It will time out if the player local function wait_for_game_load()
-- has already loaded a fortress or is in any screen that can't get to the title
-- screen by sending ESC keys.
local function ensure_title_screen()
local start_ms = dfhack.getTickCount() local start_ms = dfhack.getTickCount()
local prev_ms = start_ms local prev_ms = start_ms
while df.viewscreen_initial_prepst:is_instance(dfhack.gui.getCurViewscreen()) do while df.viewscreen_initial_prepst:is_instance(dfhack.gui.getDFViewscreen()) do
delay(10) delay(10)
-- wait up to 1 minute for the game to load and show the title screen -- wait up to 1 minute for the game to load and show the title screen
local now_ms = dfhack.getTickCount() local now_ms = dfhack.getTickCount()
@ -175,12 +171,19 @@ local function ensure_title_screen()
prev_ms = now_ms prev_ms = now_ms
end end
end end
end
-- This only handles pre-fortress-load screens. It will time out if the player
-- has already loaded a fortress or is in any screen that can't get to the title
-- screen by sending ESC keys.
local function ensure_title_screen()
wait_for_game_load()
if df.viewscreen_dwarfmodest:is_instance(dfhack.gui.getDFViewscreen(true)) then if df.viewscreen_dwarfmodest:is_instance(dfhack.gui.getDFViewscreen(true)) then
qerror('Cannot reach title screen from loaded fort') qerror('Cannot reach title screen from loaded fort')
end end
for i = 1, 100 do for i = 1, 100 do
local scr = dfhack.gui.getCurViewscreen() local scr = dfhack.gui.getCurViewscreen()
if is_title_screen(scr) then if is_title_screen() then
print('Found title screen') print('Found title screen')
return return
end end
@ -239,15 +242,17 @@ end
-- the "Continue active game" option in the title screen. Otherwise the function -- the "Continue active game" option in the title screen. Otherwise the function
-- will time out and/or exit with error. -- will time out and/or exit with error.
local function ensure_fortress(config) local function ensure_fortress(config)
wait_for_game_load()
for screen_timeout = 1,10 do for screen_timeout = 1,10 do
if is_fortress() then if is_fortress() then
print('Loaded fortress map') print('Fortress map is loaded')
-- pause the game (if it's not already paused) -- pause the game (if it's not already paused)
dfhack.gui.resetDwarfmodeView(true) dfhack.gui.resetDwarfmodeView(true)
return return
end end
local scr = dfhack.gui.getDFViewscreen(true) local scr = dfhack.gui.getDFViewscreen(true)
if dfhack.gui.matchFocusString('title/Default') then if dfhack.gui.matchFocusString('title/Default') then
print('Attempting to load the test fortress')
-- TODO: reinstate loading of a specified save dir; for now -- TODO: reinstate loading of a specified save dir; for now
-- just load the first possible save, which will at least let us -- just load the first possible save, which will at least let us
-- run fortress tests in CI -- run fortress tests in CI