-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitest_main.lua
94 lines (77 loc) · 2.62 KB
/
itest_main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
-- main source file for all itests, used to run itests in pico8
-- must require at main top, to be used in any required modules from here
require("engine/pico8/api")
require("engine/test/integrationtest")
--#if log
local logging = require("engine/debug/logging")
--#endif
local demo_app = require("application/demo_app")
-- set app immediately so during itest registration by require,
-- time_trigger can access app fps
local app = demo_app()
itest_runner.app = app
-- tag to add require for itest files here
--[[add_require]]
local current_itest_index = 0
function _init()
--#if log
-- register log streams to output logs to both the console and the file log
logging.logger:register_stream(logging.console_log_stream)
logging.logger:register_stream(logging.file_log_stream)
logging.file_log_stream.file_prefix = "picoboots_demo"
-- clear log file on new itest session
logging.file_log_stream:clear()
--#endif
app.initial_gamestate = ':main_menu'
-- start first itest
init_game_and_start_next_itest()
end
function _update60()
handle_input()
itest_runner:update_game_and_test()
end
function _draw()
itest_runner:draw_game_and_test()
end
function init_game_and_start_next_itest()
init_game_and_start_itest_by_relative_index(1)
end
function init_game_and_start_itest_by_relative_index(delta)
-- clamp new index
local new_index = mid(1, current_itest_index + delta, #itest_manager.itests)
-- check that an effective idnex change occurs
if new_index ~= current_itest_index then
current_itest_index = new_index
itest_manager:init_game_and_start_by_index(new_index)
end
end
-- press left/right to navigate freely in itests, even if not finished
-- press x to skip itest only if finished
function handle_input()
-- since input.mode is simulated during itests, use pico8 api directly for input
if btnp(button_ids.left) then
-- go back to previous itest
init_game_and_start_itest_by_relative_index(-1)
return
elseif btnp(button_ids.right) then
-- skip current itest
init_game_and_start_next_itest()
return
elseif btnp(button_ids.up) then
-- go back 10 itests
init_game_and_start_itest_by_relative_index(-10)
return
elseif btnp(button_ids.down) then
-- skip many itests
init_game_and_start_itest_by_relative_index(10)
return
end
if itest_runner.current_state == test_states.success or
itest_runner.current_state == test_states.failure or
itest_runner.current_state == test_states.timeout then
-- previous itest has finished, wait for x press to continue to next itest
if btnp(button_ids.x) then
init_game_and_start_next_itest()
end
end
end