TableTower/tests/app_testbase.gd
RobinFiredrake 7ea2bbf3a8 Speed: lazy format menus, one-call dashed threads, kept inspector sections, queued card rebuilds
Profiling showed the delays come from Godot's own calls, not GDScript:
- Right-click format menus are made on the first right-click, not for
  every text field at build time.
- Dashed reference threads draw all their dashes in one call.
- Inspector rebuilds keep the closed sections and only remake open ones.
- Card rows are styled before they join the card.
- A Play/Build switch rebuilds cards in view at once and the rest a few
  per frame (CardRefreshQueue); threads redraw only now and then meanwhile.

Adds tests/perf_actions.gd, a timing tool for everyday actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:20:31 -06:00

64 lines
1.9 KiB
GDScript

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)
main.card_refresh.frame_usec = 1 << 40
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()