- CardCatalog: one list of card kinds for the palette, right-click New card and new-card names; Dice table and Deck are their own items. - LeftDock holds the palette and List view in the shared dock tab style. - Play greys the palette under a Switch to Build notice (replaces the greyed + Card button); + Card menu removed; Card palette button in Build. - Templates dropped from the palette land where they are let go. - Phones: + opens the palette full screen. - docs/SHEETS.md: the Sheets and unified editor plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
230 lines
11 KiB
GDScript
230 lines
11 KiB
GDScript
extends AppTestBase
|
||
## The top bar's menus (View ▾, the zoom control, Spread ▾ with Pack, Help ▾),
|
||
## striped result rows, the Build card's ⋯ menu and the row × that shows on
|
||
## hover or selection, and the Help window's topics and links.
|
||
## Run: tools/run_tests.sh top_bar
|
||
|
||
|
||
func run() -> void:
|
||
if not await start_main():
|
||
return
|
||
main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
|
||
main.size = Vector2(1440, 900)
|
||
_test_bar()
|
||
await _test_zoom()
|
||
await _test_view_menu()
|
||
await _test_stripes()
|
||
await _test_card_menu()
|
||
await _test_help()
|
||
await _test_build_hint()
|
||
await _test_palette()
|
||
await _test_welcome()
|
||
finish()
|
||
|
||
|
||
func _test_bar() -> void:
|
||
var bar := main.top_bar
|
||
_check(bar.view_menu != null and bar.help_menu != null and bar.zoom != null, "View ▾, Help ▾ and the zoom control are on the bar")
|
||
var texts: Array[String] = []
|
||
for n in bar._build_tools.find_children("*", "Button", true, false):
|
||
texts.append((n as Button).text)
|
||
_check(not texts.has("Arrange ▾"), "Arrange ▾ is gone from the Build tools: %s" % str(texts))
|
||
var pm := bar._board_menu.get_popup()
|
||
_check(pm.get_item_index(IoMenu.ID_PACK) >= 0, "Spread ▾ has Pack collapsed groups")
|
||
_check(main.nav._search_button.text == "", "Search is an icon button")
|
||
|
||
|
||
func _test_zoom() -> void:
|
||
var z := main.top_bar.zoom
|
||
z.activate(ZoomControl.ID_ACTUAL)
|
||
await _frames()
|
||
_eq(main.board.zoom, 1.0, "Zoom to 100% sets the zoom")
|
||
_eq(z.menu.text, "100% ▾", "the percentage follows")
|
||
main.board.set_zoom(0.5)
|
||
await _frames()
|
||
_eq(z.menu.text, "50% ▾", "and follows zoom changes from elsewhere")
|
||
z.activate(ZoomControl.ID_FIT)
|
||
_check(main.board.zoom != 0.5, "Fit spread changes the zoom")
|
||
|
||
|
||
func _test_view_menu() -> void:
|
||
var v := main.top_bar.view_menu
|
||
v.activate(ViewMenu.ID_TEXT)
|
||
_eq(main.rules_view(), "text", "Rule text")
|
||
v.activate(ViewMenu.ID_PLAIN)
|
||
_eq(main.rules_view(), "plain", "Plain words")
|
||
var was := main.board.minimap.visible
|
||
v.activate(ViewMenu.ID_MINIMAP)
|
||
_check(main.board.minimap.visible != was, "Minimap toggles")
|
||
v.activate(ViewMenu.ID_MINIMAP)
|
||
v.activate(ViewMenu.ID_COLLAPSE)
|
||
await _frames()
|
||
_eq(v.collapse_label(), "Expand all tables", "after Collapse all the menu offers Expand")
|
||
v.activate(ViewMenu.ID_COLLAPSE)
|
||
await _frames()
|
||
_eq(v.collapse_label(), "Collapse all tables", "and Expand all puts it back")
|
||
v.sync()
|
||
var pm := v.get_popup()
|
||
_check(pm.is_item_checked(pm.get_item_index(ViewMenu.ID_PLAIN)) and pm.is_item_checked(pm.get_item_index(ViewMenu.ID_STRIPES)),
|
||
"the menu checks Plain words and Striped rows")
|
||
|
||
|
||
func _row_bg(card: TableCard, index: int) -> Color:
|
||
var e := card.table.entries[index]
|
||
return ((card.rows[e.id] as PanelContainer).get_theme_stylebox("panel") as StyleBoxFlat).bg_color
|
||
|
||
|
||
func _test_stripes() -> void:
|
||
var card := main.card_for("loot")
|
||
_check(main.local_state.striped_rows(), "stripes are on by default")
|
||
_eq(_row_bg(card, 0), Color(0, 0, 0, 0), "the first row is clear")
|
||
_eq(_row_bg(card, 1), Style.STRIPE, "the second row is striped")
|
||
_eq(_row_bg(card, 2), Color(0, 0, 0, 0), "the third row is clear")
|
||
card.rows_ui.set_row_state(card.table.entries[1].id, TableCardRows.RowState.LIT)
|
||
_eq(_row_bg(card, 1), Style.LIT, "a lit row shows lit, not striped")
|
||
card.rows_ui.restate(card.table.entries[1].id)
|
||
main.top_bar.view_menu.activate(ViewMenu.ID_STRIPES)
|
||
_eq(_row_bg(card, 1), Color(0, 0, 0, 0), "turning stripes off clears them")
|
||
main.top_bar.view_menu.activate(ViewMenu.ID_STRIPES)
|
||
_eq(_row_bg(card, 1), Style.STRIPE, "and back on")
|
||
await _frames()
|
||
|
||
|
||
func _test_card_menu() -> void:
|
||
main.set_mode(Main.Mode.BUILD)
|
||
await _frames()
|
||
var card := main.card_for("loot")
|
||
var menus := card.find_children("*", "MenuButton", true, false)
|
||
_check(menus.size() == 1 and (menus[0] as MenuButton).tooltip_text == "Table actions", "the card has one ⋯ menu")
|
||
var texts: Array[String] = []
|
||
for n in card.find_children("*", "Button", true, false):
|
||
texts.append((n as Button).text)
|
||
_check(not texts.has("⚙") and not texts.has("Delete"), "no gear and no footer Delete: %s" % str(texts))
|
||
|
||
var eid := card.table.entries[2].id
|
||
var del: Button = card.rows_ui.parts[eid]["delete"]
|
||
_eq(del.modulate.a, 0.0, "a row's × is hidden until hovered")
|
||
card.select_entry(eid)
|
||
_eq(del.modulate.a, 1.0, "the selected row shows its ×")
|
||
card.select_entry("")
|
||
_eq(del.modulate.a, 0.0, "and hides it again when deselected")
|
||
|
||
var pm := (menus[0] as MenuButton).get_popup()
|
||
_check(Actions.press(pm, "Delete table"), "⋯ has Delete table")
|
||
await _frames()
|
||
_check(main.data.get_table("loot") == null, "⋯ → Delete table deletes it")
|
||
main.undo_redo.undo()
|
||
await _frames()
|
||
_check(main.data.get_table("loot") != null, "and undo brings it back")
|
||
|
||
|
||
func _test_help() -> void:
|
||
var titles := HelpDialog.titles()
|
||
_check(titles.size() >= 10 and titles.has("Deck mode") and titles.has("Roll modifiers"), "help has its topics: %s" % str(titles))
|
||
var src := FileAccess.get_file_as_string(HelpDialog.PATH)
|
||
var re := RegEx.create_from_string("\\[topic\\](.+?)\\[/topic\\]")
|
||
for m in re.search_all(src):
|
||
_check(titles.has(m.get_string(1)), "the link to “%s” has a topic" % m.get_string(1))
|
||
for t: Dictionary in HelpDialog.topics():
|
||
_check(str(t["body"]).length() > 80, "“%s” has text" % t["title"])
|
||
_check(HelpDialog._inline("`[[Loot]]`").contains("[lb][lb]Loot[rb][rb]"), "code spans keep their brackets")
|
||
|
||
var d := main.top_bar.help_menu.open("deck MODE")
|
||
await _frames()
|
||
_eq(d.current, "Deck mode", "Help opens at the asked topic, any case")
|
||
d._on_meta("topic:Roll modifiers")
|
||
_eq(d.current, "Roll modifiers", "a topic link switches topics")
|
||
_check(d.text.get_parsed_text().contains("Luck"), "and shows its text")
|
||
d.close()
|
||
await _frames()
|
||
|
||
|
||
## Play shows that Build mode exists: the card palette is greyed under a
|
||
## notice with Switch to Build, a greyed item explains, and the ☰ menu shows
|
||
## a greyed "New card".
|
||
func _test_build_hint() -> void:
|
||
main.set_mode(Main.Mode.PLAY)
|
||
var bar := main.top_bar
|
||
var palette := main.left_dock.palette
|
||
main.left_dock.show_tab(LeftDock.CARDS)
|
||
await _frames()
|
||
_check(palette.notice.visible and not bar._build_tools.visible, "Play shows the palette notice, not the Build tools")
|
||
var names := Actions.background(main, Vector2.ZERO).map(func(a: Dictionary) -> String: return str(a.get("text", "")))
|
||
var item: Dictionary = Actions.background(main, Vector2.ZERO)[names.find("New card")] if names.has("New card") else {}
|
||
_check(item.get("disabled", false), "the ☰ menu shows New card greyed in Play")
|
||
var before := main.data.tables.size()
|
||
(palette.find_child("Roll table", true, false) as Button).pressed.emit()
|
||
_eq(main.data.tables.size(), before, "a greyed palette item adds nothing in Play")
|
||
_eq(bar._toast_label.text, BuildModeHint.MESSAGE, "clicking it explains Build mode")
|
||
_check(bar._toast_undo.visible and bar._toast_undo.text == "Switch to Build", "the toast offers Switch to Build")
|
||
bar._toast_undo.pressed.emit()
|
||
await _frames()
|
||
_eq(main.mode, Main.Mode.BUILD, "Switch to Build switches")
|
||
await _frames()
|
||
_check(not palette.notice.visible, "Build hides the palette notice")
|
||
main.toast("Saved")
|
||
_eq(bar._toast_undo.text, "Undo", "a later toast's button is Undo again")
|
||
|
||
|
||
## Morgan's welcome: not in a session that doesn't save; open() shows it with
|
||
## its three ways to start, and Explore the demo closes it.
|
||
func _test_welcome() -> void:
|
||
WelcomeDialog.maybe_show(main)
|
||
await _frames()
|
||
_check(main.find_children("*", "ModalCard", true, false).is_empty(), "no welcome in a session that doesn't save")
|
||
var dialog := WelcomeDialog.open(main)
|
||
await _frames()
|
||
var labels: Array = dialog.footer.get_children().map(func(b: Node) -> String: return (b as Button).text)
|
||
_eq(labels, ["Import a spread…", "Start a blank spread", "Explore the demo"], "the welcome's buttons")
|
||
(dialog.footer.get_child(2) as Button).pressed.emit()
|
||
await _frames(20)
|
||
_check(not is_instance_valid(dialog) or dialog.is_queued_for_deletion(), "Explore the demo closes it")
|
||
|
||
|
||
## The card palette: search narrows it, a click adds in the middle of the
|
||
## view, a drop on the spread adds there, Enter adds the first match.
|
||
func _test_palette() -> void:
|
||
main.set_mode(Main.Mode.BUILD)
|
||
var palette := main.left_dock.palette
|
||
main.left_dock.show_tab(LeftDock.CARDS)
|
||
palette.search.text = "dice"
|
||
palette.search.text_changed.emit("dice")
|
||
_check(palette.find_child("Dice table", true, false) != null and palette.find_child("Branch", true, false) == null, "search narrows the palette")
|
||
palette.search.text = "zzqx"
|
||
palette.search.text_changed.emit("zzqx")
|
||
_check(palette.find_child("Dice table", true, false) == null, "a search with no match empties it")
|
||
palette.search.text = ""
|
||
palette.search.text_changed.emit("")
|
||
var before := main.data.tables.size()
|
||
(palette.find_child("Deck", true, false) as Button).pressed.emit()
|
||
var deck := main.data.tables[main.data.tables.size() - 1]
|
||
_check(main.data.tables.size() == before + 1 and deck.card_mode, "clicking Deck adds a deck")
|
||
var spot := main.board.global_position + main.board.size / 2.0 + Vector2(40, 30)
|
||
var item: Dictionary = CardCatalog.find(RollTable.KIND_CHECK)
|
||
_check(palette.drop_at(palette._add_card.bind(item), spot), "a drop on the spread is taken")
|
||
var check := main.data.tables[main.data.tables.size() - 1]
|
||
var want := (main.board.screen_to_world(spot - main.board.global_position) - Vector2(128, 20)).round()
|
||
_check(check.kind == RollTable.KIND_CHECK and check.position == want, "the dropped card sits where it was let go")
|
||
_check(not palette.drop_at(palette._add_card.bind(item), Vector2(-50, -50)), "a drop off the spread adds nothing")
|
||
var button := main.top_bar.palette_button
|
||
_check(button.is_visible_in_tree() and button.button_pressed, "Build shows a lit Card palette button")
|
||
button.pressed.emit()
|
||
_check(not main.left_dock.visible and not button.button_pressed, "the button closes the palette")
|
||
button.pressed.emit()
|
||
_check(main.left_dock.showing(LeftDock.CARDS) and button.button_pressed, "and opens it again")
|
||
var tpl_id := str(main.templating.templates().list()[0]["id"])
|
||
var spot2 := spot + Vector2(-200, 60)
|
||
var at2 := (main.board.screen_to_world(spot2 - main.board.global_position) - Vector2(128, 20)).round()
|
||
var tpl := main.templating.templates().get_template(tpl_id)
|
||
var made: Dictionary = main.templating.insert_template(tpl, {}, at2)
|
||
var top_left := Vector2(INF, INF)
|
||
for t: RollTable in made["tables"]:
|
||
top_left = Vector2(minf(top_left.x, t.position.x), minf(top_left.y, t.position.y))
|
||
for g: TableGroup in made.get("groups", []):
|
||
top_left = Vector2(minf(top_left.x, g.position.x), minf(top_left.y, g.position.y))
|
||
_eq(top_left, at2, "a template dropped on the spread lands where it was let go")
|
||
palette.search.text = "branch"
|
||
palette.search.text_submitted.emit("branch")
|
||
_eq(main.data.tables[main.data.tables.size() - 1].kind, RollTable.KIND_ROUTER, "Enter adds the first match")
|
||
palette.search.text = ""
|
||
palette.search.text_changed.emit("")
|