64 lines
1.8 KiB
GDScript3
64 lines
1.8 KiB
GDScript3
|
|
class_name AppTestBase
|
||
|
|
extends TestBase
|
||
|
|
## For suites that load the app. Call `if not await start_main(): return` first.
|
||
|
|
|
||
|
|
## Long demo tables are cut to this many rows: rebuilding them costs up to a
|
||
|
|
## second per mode switch. test_roller checks the demo's full tables.
|
||
|
|
const MAX_DEMO_ROWS := 12
|
||
|
|
|
||
|
|
var main: Main
|
||
|
|
|
||
|
|
|
||
|
|
## Hook: suites that need a customised Main override this.
|
||
|
|
func _create_main() -> Main:
|
||
|
|
return load("res://ui/main.tscn").instantiate()
|
||
|
|
|
||
|
|
|
||
|
|
## The app's demo spread with short tables.
|
||
|
|
func _short_demo() -> TowerBoard:
|
||
|
|
var board := SampleBoard.create()
|
||
|
|
board.id = "fantasy-loot"
|
||
|
|
board.name = "Fantasy Loot"
|
||
|
|
for table in board.tables:
|
||
|
|
if not table.is_ranged() and table.entries.size() > MAX_DEMO_ROWS:
|
||
|
|
table.entries.resize(MAX_DEMO_ROWS)
|
||
|
|
return board
|
||
|
|
|
||
|
|
|
||
|
|
func _empty_spread() -> TowerBoard:
|
||
|
|
var board := TowerBoard.new()
|
||
|
|
board.id = "fantasy-loot"
|
||
|
|
board.name = "Fantasy Loot"
|
||
|
|
return board
|
||
|
|
|
||
|
|
|
||
|
|
## A suite that loads its own board first should pass `with_demo` false: the
|
||
|
|
## demo's cards take about half a second to build. Guard, then loads the app under root and waits for it. Returns false (after
|
||
|
|
## aborting) if the guard fails or the app would save.
|
||
|
|
func start_main(with_demo: bool = true) -> bool:
|
||
|
|
if not require_sample():
|
||
|
|
return false
|
||
|
|
main = _create_main()
|
||
|
|
if main.data == null:
|
||
|
|
main.data = _short_demo() if with_demo else _empty_spread()
|
||
|
|
root.add_child(main)
|
||
|
|
await _frames(5)
|
||
|
|
if main._saving_enabled:
|
||
|
|
abort("Saving is enabled; refusing to run.")
|
||
|
|
return false
|
||
|
|
return true
|
||
|
|
|
||
|
|
|
||
|
|
## Back to the default theme, window and shared UI state.
|
||
|
|
func clean_up() -> void:
|
||
|
|
if main != null:
|
||
|
|
main.queue_free()
|
||
|
|
ThemeStore.DIR = "user://themes/"
|
||
|
|
ThemeStore.carry_board = null
|
||
|
|
ThemeStore.current = {}
|
||
|
|
ThemeAssets._cache.clear()
|
||
|
|
Spellcheck.ignored.clear()
|
||
|
|
TestBoardDialog.last = {}
|
||
|
|
RulesView.fallback_plain = true
|
||
|
|
SpreadLinks.loader = Callable()
|