TableTower/tests/test_inspector.gd

571 lines
25 KiB
GDScript3
Raw Normal View History

extends SceneTree
## The Build inspector (docs/PLAIN.md §6): selection, the effects and
## condition builders, Otherwise, pipe inputs, check fields and the modifier
## picker, collection members, options source, the value picker, the
## Plain/Text switch, undo, and dirty/save.
## Run: godot --headless --path . -s res://tests/test_inspector.gd -- --sample
var _failures := 0
var main: Main
var insp: Inspector
func _init() -> void:
if not OS.get_cmdline_user_args().has("--sample"):
print("Run with -- --sample so the test can't touch saved data.")
quit(2)
return
main = load("res://ui/main.tscn").instantiate()
root.add_child(main)
for i in 5:
await process_frame
if main._saving_enabled:
print("Saving is enabled; refusing to run.")
quit(2)
return
main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
main.size = Vector2(1440, 900)
main.set_mode(Main.Mode.BUILD)
insp = main.inspector
await _load()
await _test_selection()
await _test_effects()
await _test_unparseable()
await _test_conditions()
await _test_otherwise()
await _test_pipe_inputs()
await _test_check()
await _test_collection()
await _test_options()
await _test_value_picker()
await _test_rules_view()
await _test_undo()
await _test_dirty_and_save()
await _test_other_cards()
await _test_add_kinds()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
func _check(ok: bool, what: String) -> void:
if ok:
print(" ok %s" % what)
else:
_failures += 1
print(" FAIL %s" % what)
func _eq(a: Variant, b: Variant, what: String) -> void:
_check(a == b, "%s (got %s, want %s)" % [what, JSON.stringify(a), JSON.stringify(b)])
func _frames(n: int = 2) -> void:
for i in n:
await process_frame
func _board_dict() -> Dictionary:
return {"format_version": 2, "id": "insp-test", "name": "Inspector test", "tables": [
{"id": "gate", "name": "Force the gate", "kind": "check", "x": 40, "y": 40, "check_dice": "2d6",
"check_mod": "dm(@str)", "check_cmp": "ge", "check_target": "8",
"entries": [{"id": "e1", "text": "Success", "pipes": ["beyond"]}, {"id": "e2", "text": "Failure"}]},
{"id": "beyond", "name": "Beyond the gate", "x": 340, "y": 40, "entries": [
{"id": "e1", "text": "Store room"},
{"id": "e2", "text": "The warden's vault", "effects": "@luck -= 1", "pipes": [
{"table": "loot", "with": {"tier": "3"}, "when": "@luck >= 2"},
{"table": "curios", "with": {"tier": "1"}, "otherwise": true}]}]},
{"id": "loot", "name": "Loot", "x": 700, "y": 20, "inputs": [{"name": "tier", "label": "Tier", "default": "1"}],
"entries": [{"id": "e1", "text": "Silver"}]},
{"id": "curios", "name": "Curios", "x": 700, "y": 300, "inputs": [{"name": "tier", "label": "Tier", "default": "1"}],
"entries": [{"id": "e1", "text": "A curio"}]},
{"id": "learn", "name": "Learn", "kind": "choice", "choice": "pick", "x": 340, "y": 380,
"entries": [{"id": "e1", "text": "Option 1"}, {"id": "e2", "text": "Option 2"}]},
{"id": "str", "name": "Strength", "kind": "variable", "var_name": "str", "var_type": "number", "initial": "9", "x": 40, "y": 330, "entries": []},
{"id": "luck", "name": "Luck", "kind": "variable", "var_name": "luck", "var_type": "number", "initial": "2", "x": 40, "y": 470, "entries": []},
{"id": "skills", "name": "Skills", "kind": "variable", "var_name": "skill", "var_type": "collection", "x": 40, "y": 610, "entries": []},
{"id": "rt", "name": "Router", "kind": "router", "x": 1000, "y": 40, "entries": [
{"id": "c1", "text": "Strong", "when": "@str >= 8"}, {"id": "c2", "text": "Otherwise"}]},
{"id": "lp", "name": "Repeat", "kind": "loop", "loop_mode": "times", "loop_expr": "3", "x": 1000, "y": 300,
"entries": [{"id": "e1", "text": "Each time"}, {"id": "e2", "text": "Afterwards"}]},
]}
func _load() -> void:
main.data.load_dict(_board_dict())
main.lit_entries.clear()
main.lit_pipes.clear()
main.persistent_vars.clear()
main._rebuild_cards()
main.clear_inspector()
await _frames(4)
func _t(id: String) -> RollTable:
return main.data.get_table(id)
func _vault() -> TableEntry:
return _t("beyond").find_entry("e2")
# ---------- Selection ----------
func _test_selection() -> void:
print("Selection")
_check(insp.visible, "the inspector shows in Build mode")
_check(insp.selection.is_empty(), "nothing is selected at first")
_check(_has_text(insp, "Select a card, a result or a pipe to edit it."), "the empty state says how to select")
main.select_card("gate")
_eq(main.inspector_selection(), {"kind": "card", "tid": "gate"}, "select_card")
_check(insp.fields.has("check_dice"), "a check card shows its dice field")
main.select_result("beyond", "e2")
_eq(insp.selection.get("kind"), "result", "select_result")
_check(insp.effects != null and insp.pipe_parts.has("loot") and insp.pipe_parts.has("curios"), "a result shows its effects and both pipes")
main.inspecting.select_pipe("beyond:e2>loot")
_eq(insp.selection.get("to"), "loot", "select_pipe")
_eq(insp.pipe_parts.keys(), ["loot"], "a pipe shows only its own box")
_eq(main.board.pipes.select_key, "beyond:e2>loot", "the selected pipe is highlighted on the board")
main.clear_inspector()
_check(insp.selection.is_empty(), "clear_inspector")
main.open_pipe_options("beyond:e2>curios", Vector2(10, 10))
_eq(insp.selection.get("to"), "curios", "clicking a pipe in Build selects it in the inspector")
main.request_table_settings("loot")
_eq(insp.selection, {"kind": "card", "tid": "loot"}, "the card's ⚙ selects the card")
main.select_result("beyond", "nope")
_eq(insp.selection.get("tid"), "loot", "a missing result isn't selected")
main.set_mode(Main.Mode.PLAY)
_check(not insp.visible and insp.selection.is_empty(), "Play hides and clears the inspector")
main.set_mode(Main.Mode.BUILD)
_check(insp.visible, "Build shows it again")
insp.set_collapsed(true)
_check(insp.custom_minimum_size.x == Inspector.STRIP, "the inspector collapses to a strip")
main.select_card("gate")
_check(not insp.collapsed, "selecting something opens it again")
# Deleting the selected card empties the inspector.
main.select_card("lp")
var keep := _t("lp").to_dict()
main.delete_table("lp")
await _frames(2)
_check(insp.selection.is_empty(), "deleting the selected card clears the inspector")
main.undo_redo.undo()
await _frames(2)
_check(_t("lp") != null, "(undo brings the card back)")
_eq(_t("lp").to_dict()["name"], keep["name"], "(same card)")
func _has_text(n: Node, s: String) -> bool:
for c in n.get_children():
if (c is Label and (c as Label).text == s) or _has_text(c, s):
return true
return false
# ---------- Effects ----------
func _test_effects() -> void:
print("Effects builder")
main.select_result("beyond", "e2")
var fx := insp.effects
_eq(fx.rows.size(), 1, "one row per statement")
_eq([fx.rows[0]["op"], fx.rows[0]["var"], fx.rows[0]["amount"]], ["subtract", "@luck", "1"], "the row reads Subtract 1 from Luck")
fx.set_row_amount(0, "2")
_eq(_vault().effects, "@luck -= 2", "changing the amount writes the statement")
fx.set_row_op(0, "add")
_eq(_vault().effects, "@luck += 2", "changing the op")
fx.add_row()
_eq(_vault().effects, "@luck += 2", "a new row isn't written until it's filled in")
fx.set_row_var(1, "@str")
_eq(_vault().effects, "@luck += 2\n@str += 1", "picking its value writes it, joined by a newline")
fx.set_row_op(1, "set")
fx.set_row_amount(1, "Millbrook")
_eq(_vault().effects, "@luck += 2\n@str = \"Millbrook\"", "a word typed as an amount becomes quoted text")
fx.set_row_amount(1, "1d6 + 2")
_eq(_vault().effects, "@luck += 2\n@str = 1d6 + 2", "an expression stays as written")
fx.set_row_op(1, "append")
fx.set_row_var(1, "@traits")
fx.set_row_amount(1, "Psionic")
_eq(_vault().effects, "@luck += 2\n@traits += \"Psionic\"", "Add to list")
fx.set_row_op(1, "remove")
_eq(_vault().effects, "@luck += 2\n@traits -= \"Psionic\"", "Remove from list")
fx.set_row_op(1, "reset")
_eq(_vault().effects, "@luck += 2\nreset @traits", "Clear")
fx.set_row_op(1, "multiply")
_eq(_vault().effects, "@luck += 2\n@traits *= 1", "Multiply after Clear starts at 1")
fx.remove_row(1)
_eq(_vault().effects, "@luck += 2", "× removes the row")
# Typing in the row's field.
var amt := InspectorKit.find_tagged(fx, "res.fx.0.amount") as LineEdit
amt.text = "3"
amt.text_changed.emit("3")
_eq(_vault().effects, "@luck += 3", "typing in the amount field writes the statement")
# Edit as text and back.
fx.set_text_mode(true)
_check(fx.text_mode and InspectorKit.find_tagged(fx, "res.fx.raw") != null, "Edit as text shows the whole effects text")
fx.set_raw("@luck -= 1\n@str += 2")
_eq(_vault().effects, "@luck -= 1\n@str += 2", "the text is written as typed")
fx.set_text_mode(false)
_eq(fx.rows.size(), 2, "Use the builder brings back one row per statement")
_eq(Builder.parse_effects(_vault().effects).size(), 2, "(still two statements)")
await _frames()
func _test_unparseable() -> void:
print("Unparseable statements")
_vault().effects = "@luck -= 1\n@gold += 2 +\n@str += 1"
main.mark_dirty()
await _frames(2)
var fx := insp.effects
_eq(fx.rows.size(), 3, "every statement gets a row")
_check(not fx.rows[1]["ok"], "the broken statement isn't a builder row")
var le := InspectorKit.find_tagged(fx, "res.fx.1.src") as LineEdit
_check(le != null and le.text == "@gold += 2 +", "it shows as a text field with its text")
fx.set_row_amount(0, "5")
_eq(_vault().effects, "@luck -= 5\n@gold += 2 +\n@str += 1", "editing another row keeps it exactly")
fx.set_text_mode(true)
fx.set_text_mode(false)
_check(fx.text_mode, "Use the builder waits until every statement parses")
fx.set_raw("@luck -= 5\n@gold += 2\n@str += 1")
fx.set_text_mode(false)
_check(not fx.text_mode and fx.rows.size() == 3 and fx.rows[1]["ok"], "then the builder takes over")
_vault().effects = "@luck -= 1"
main.mark_dirty()
await _frames(2)
# ---------- Conditions ----------
func _test_conditions() -> void:
print("Condition builder")
main.select_result("beyond", "e2")
var cond: ConditionBuilder = insp.pipe_parts["loot"]["when"]
_eq(cond.clauses, [{"var": "@luck", "cmp": "ge", "value": "2"}], "the Only if reads as one clause")
cond.add_clause()
_eq(_vault().when_for("loot"), "@luck >= 2", "an empty clause isn't written")
cond.set_clause_var(1, "@str")
cond.set_clause_value(1, "8")
_eq(_vault().when_for("loot"), "@luck >= 2 and @str >= 8", "two clauses join with and")
cond.set_join("or")
_eq(_vault().when_for("loot"), "@luck >= 2 or @str >= 8", "the switch makes it or")
cond.set_clause_cmp(1, "eq")
cond.set_clause_value(1, "Aslan")
_eq(_vault().when_for("loot"), "@luck >= 2 or @str = \"Aslan\"", "a word is compared as quoted text")
cond.set_clause_cmp(1, "set")
_eq(_vault().when_for("loot"), "@luck >= 2 or @str", "is set has no amount")
cond.remove_clause(1)
_eq(_vault().when_for("loot"), "@luck >= 2", "× removes a clause")
# A condition the builder can't show stays text.
_vault().set_pipe_when("loot", "@luck >= 2 and @str > 1 or @x")
main.mark_dirty()
await _frames(2)
cond = insp.pipe_parts["loot"]["when"]
_check(cond.text_mode, "mixed and/or shows as text")
cond.set_raw("@luck >= 3")
_eq(_vault().when_for("loot"), "@luck >= 3", "the text is written")
cond.set_raw("@luck >= = 3")
_eq(_vault().when_for("loot"), "@luck >= 3", "text that doesn't work isn't written")
cond.set_raw("@luck >= 2")
cond.set_text_mode(false)
_check(not cond.text_mode and cond.clauses.size() == 1, "Use the builder once it parses")
await _frames()
func _test_otherwise() -> void:
print("Otherwise")
main.select_result("beyond", "e2")
var loot_other: CheckBox = insp.pipe_parts["loot"]["otherwise"]
var cur_other: CheckBox = insp.pipe_parts["curios"]["otherwise"]
_check(cur_other.button_pressed and not cur_other.disabled, "the otherwise pipe is ticked")
_check(loot_other.disabled and not loot_other.button_pressed, "Otherwise is off while Only if is set")
insp.set_pipe_when("loot", "")
_check(not loot_other.disabled, "clearing Only if allows Otherwise")
insp.set_pipe_otherwise("loot", true)
_check(_vault().is_otherwise("loot") and loot_other.button_pressed, "ticking Otherwise writes it")
insp.set_pipe_when("loot", "@luck >= 2")
_check(not _vault().is_otherwise("loot") and loot_other.disabled, "an Only if turns Otherwise off")
insp.set_pipe_otherwise("curios", false)
_check(not _vault().is_otherwise("curios"), "unticking")
cur_other.toggled.emit(true)
_check(_vault().is_otherwise("curios"), "the checkbox writes it too")
insp.set_pipe_count("loot", "2")
_eq(_vault().count_text("loot"), "2", "count")
insp.set_pipe_count("loot", "@x +")
_eq(_vault().count_text("loot"), "2", "a bad count isn't written")
insp.set_pipe_save("loot", "@weapon")
_eq(_vault().save_for("loot"), "@weapon", "saves as")
insp.set_pipe_save("loot", "not a name")
_eq(_vault().save_for("loot"), "@weapon", "a bad name isn't saved")
insp.set_pipe_save("loot", "")
insp.set_pipe_count("loot", "1")
await _frames()
func _test_pipe_inputs() -> void:
print("Pipe inputs")
main.select_result("beyond", "e2")
var le: LineEdit = insp.pipe_parts["loot"]["inputs"]["tier"]
_eq(le.text, "3", "the target's input shows the passed value")
_eq(le.placeholder_text, "1", "its default is the placeholder")
le.text = "5"
le.text_changed.emit("5")
_eq(_vault().with_for("loot"), {"tier": "5"}, "typing writes pipe_with")
insp.set_pipe_input("loot", "tier", "@luck + 1")
_eq(_vault().with_for("loot"), {"tier": "@luck + 1"}, "an expression")
insp.set_pipe_input("loot", "tier", "@luck +")
_eq(_vault().with_for("loot"), {"tier": "@luck + 1"}, "a broken one isn't written")
insp.set_pipe_input("loot", "tier", "")
_eq(_vault().with_for("loot"), {}, "empty uses the default")
insp.set_pipe_input("loot", "tier", "3")
await _frames()
# ---------- Cards ----------
func _test_check() -> void:
print("Check card")
main.select_card("gate")
var t := _t("gate")
var sentence: Label = insp.fields["sentence"]
_eq(sentence.text, Describe.check(t, main.data), "a live sentence")
_check(sentence.text.contains("Strength"), "it names the modifier's value: %s" % sentence.text)
InspectorCard.set_check(insp, "check_target", "9")
_eq(t.check_target, "9", "target")
_check(sentence.text.contains("9"), "the sentence follows: %s" % sentence.text)
InspectorCard.set_check(insp, "check_cmp", "le")
_check(t.check_cmp == "le" and sentence.text.contains("or less"), "or less")
InspectorCard.set_check(insp, "check_dice", "3d6")
_eq(t.check_dice, "3d6", "dice")
InspectorCard.set_check(insp, "check_dice", "")
_eq(t.check_dice, "3d6", "empty dice aren't written")
_eq(InspectorCard.modifier_value("dm(@str)"), "@str", "dm(@str) reads as Strength in the picker")
_eq(InspectorCard.modifier_value(""), InspectorCard.NONE, "empty is none")
_eq(InspectorCard.modifier_value("@str + 1"), InspectorCard.AS_TEXT, "anything else is text")
var picker: ValuePicker = insp.fields["check_mod_picker"]
_eq(picker.value, "@str", "the picker shows the modifier's value")
picker.choose("@luck")
_eq(t.check_mod, "dm(@luck)", "picking Luck writes dm(@luck)")
InspectorCard.choose_modifier(insp, InspectorCard.NONE)
_eq(t.check_mod, "", "none clears it")
InspectorCard.choose_modifier(insp, InspectorCard.AS_TEXT)
var le: LineEdit = insp.fields.get("check_mod")
_check(le != null, "Edit as text shows the modifier as a field")
le.text = "@str - 1"
le.text_changed.emit("@str - 1")
_eq(t.check_mod, "@str - 1", "typed text is written")
insp.rebuild()
_check(insp.fields.has("check_mod"), "a modifier the picker can't show stays text")
InspectorCard.set_check(insp, "check_mod", "dm(@str)")
InspectorCard.set_check(insp, "check_cmp", "ge")
InspectorCard.set_check(insp, "check_target", "8")
InspectorCard.set_check(insp, "check_dice", "2d6")
await _frames()
func _test_collection() -> void:
print("Collection members")
main.select_card("skills")
var t := _t("skills")
_eq(insp.members(t), [], "no members at first")
var item := InspectorCard.add_member(insp, t)
_eq(item, "new", "+ Add member")
_eq(main.persistent_vars.get("skill_new", {}).get("value"), 0, "it's the board value @skill_new = 0")
InspectorCard.set_member(insp, t, "new", "2")
InspectorCard.rename_member(insp, t, "new", "pilot")
_check(not main.persistent_vars.has("skill_new"), "renaming drops the old name")
_eq(main.persistent_vars.get("skill_pilot", {}).get("value"), 2, "and keeps the value under the new one")
InspectorCard.add_member(insp, t)
InspectorCard.rename_member(insp, t, "new", "gun_combat")
_eq(insp.members(t), [["gun_combat", "0"], ["pilot", "2"]], "members list name and value")
_check(InspectorKit.find_tagged(insp, "member.pilot.value") != null, "each member has a value field")
InspectorCard.remove_member(insp, t, "gun_combat")
_eq(insp.members(t), [["pilot", "2"]], "× removes a member")
_eq(Describe.label("@skill_pilot", main.data), "Pilot", "(members are labelled through the collection)")
await _frames()
func _test_options() -> void:
print("Options source")
main.select_card("learn")
var t := _t("learn")
_check(not t.is_dynamic(), "a fixed list at first")
var err := InspectorCard.set_options(insp, "@skill_*", "")
_eq(err, "", "From a collection")
_check(t.is_dynamic() and t.options_from == "@skill_*", "options come from Skills")
var where: ConditionBuilder = insp.fields.get("options_where")
_check(where != null, "a where builder")
where.add_clause("option_value", "ge", "1")
_eq(t.options_where, "option_value >= 1", "where Its value is at least 1")
var picker: ValuePicker = insp.fields["options_from"]
_eq(picker.value, "@skill_*", "the source picker shows the collection")
_check(picker.items().any(func(it: Dictionary) -> bool: return it["name"] == "@skill_*"), "it offers collections")
_check(not picker.items().any(func(it: Dictionary) -> bool: return it["name"] == "@luck"), "but not numbers")
_eq(insp.apply_settings({"options_mode": "fixed"}, true), "", "back to a fixed list")
_check(t.options_from == "" and not t.is_dynamic(), "options_from is cleared")
await _frames()
func _test_value_picker() -> void:
print("Value picker")
var p := ValuePicker.new(main, "")
root.add_child(p)
var names := p.items().map(func(it: Dictionary) -> String: return it["name"])
_check(names.has("@luck") and names.has("@str"), "it lists the board's values")
var luck: Dictionary = p.items().filter(func(it: Dictionary) -> bool: return it["name"] == "@luck")[0]
_eq([luck["label"], luck["kind"], luck["group"]], ["Luck", "number", "Variables"], "with label, kind and group")
_check(names.find("@luck") < names.find("@skill_pilot") or not names.has("@skill_pilot"), "variables come first")
_check(names.has("@skill_pilot"), "collection members with values are offered")
_check(not names.has("@skill_*"), "collection patterns only where they fit")
p.allow_patterns = true
_check(p.items().any(func(it: Dictionary) -> bool: return it["name"] == "@skill_*" and it["group"] == "Collections"), "grouped under Collections")
_eq(p.filtered("lu").map(func(it: Dictionary) -> String: return it["name"]), ["@luck"], "search by label")
p.open_menu()
await _frames()
_check(p.shown_names().has("@luck"), "the open menu lists them")
p.close_menu()
var got: Array = []
p.value_chosen.connect(func(n: String) -> void: got.append(n))
p.choose("@str")
_eq(got, ["@str"], "choosing emits value_chosen")
_check(p.text.begins_with("Strength"), "the button shows the label: %s" % p.text)
var n := p.create_value("Fame", true)
_eq(n, "@fame", "+ New value… names it")
var card := main.variable_card("fame")
_check(card != null and card.name == "Fame", "Show on the board adds a variable card")
_eq(got.back(), "@fame", "and picks it")
var steps := main.undo_redo.edits.undo_stack.size()
n = p.create_value("Mood", false)
_eq(n, "@mood", "without a card")
_check(main.variable_card("mood") == null and main.undo_redo.edits.undo_stack.size() == steps, "no card, no board change")
p.queue_free()
await _frames()
func _test_rules_view() -> void:
print("Plain / Text switch")
var got: Array = []
main.rules_view_changed.connect(func(v: String) -> void: got.append(v))
_check(main.rules_plain() and main.rules_view() == "plain", "plain words by default")
main.select_result("beyond", "e2")
main.set_rules_view("text")
_eq(got, ["text"], "rules_view_changed fires")
_check(not main.rules_plain(), "rules_plain() follows")
_check(insp.effects.text_mode, "the inspector shows rule text")
_check((insp.pipe_parts["loot"]["when"] as ConditionBuilder).text_mode, "conditions too")
main.set_rules_view("text")
_eq(got.size(), 1, "setting the same view again doesn't fire")
main.set_rules_view("bogus")
_eq(main.rules_view(), "text", "unknown views are ignored")
main.top_bar._rules_buttons[0].pressed.emit()
_eq(main.rules_view(), "plain", "the top-bar switch sets it")
_check(not insp.effects.text_mode, "builders are back")
await _frames()
func _test_undo() -> void:
print("Undo")
main.undo_redo._commit_edits()
main.select_result("beyond", "e2")
var before := _vault().effects
insp.effects.set_row_amount(0, "7")
main.undo_redo._commit_edits()
_eq(_vault().effects, "@luck -= 7", "(the edit)")
main.undo_redo.undo()
await _frames(2)
_eq(_vault().effects, before, "undo puts the effects back")
_eq(insp.effects.rows[0]["amount"], "1", "the inspector shows the old text")
_eq(insp.selection.get("eid"), "e2", "and keeps the selection")
main.undo_redo.redo()
await _frames(2)
_eq(_vault().effects, "@luck -= 7", "redo")
# Typing in a field is one step once it pauses.
var le: LineEdit = insp.fields["text"]
le.grab_focus()
var steps := main.undo_redo.edits.undo_stack.size()
for s in ["The vault", "The vaults", "The vaults!"]:
le.text = s
le.text_changed.emit(s)
_eq(main.undo_redo.edits.undo_stack.size(), steps, "typing waits for a pause")
main.undo_redo._commit_edits()
_eq(main.undo_redo.edits.undo_stack.size(), steps + 1, "then makes one step")
le.release_focus()
main.undo_redo.undo()
await _frames(2)
_eq(_vault().text, "The warden's vault", "one undo takes all the typing back")
await _frames()
func _test_dirty_and_save() -> void:
print("Dirty and save")
main.select_card("loot")
var rev := main.edit_rev
main._saving_enabled = true
main._save_timer.stop()
insp.apply_settings({"tags": "loot, treasure"})
_check(main.edit_rev > rev, "an inspector edit marks the board dirty")
_check(not main._save_timer.is_stopped(), "and schedules a save")
main._save_timer.stop()
main._saving_enabled = false
_eq(_t("loot").tags, ["loot", "treasure"], "tags")
var copy := TowerBoard.new()
copy.load_dict(main.data.to_dict())
_eq(copy.get_table("loot").tags, ["loot", "treasure"], "the saved form has it")
_eq(copy.get_table("beyond").find_entry("e2").with_for("loot"), {"tier": "3"}, "pipe inputs are saved")
main.undo_redo._commit_edits()
_check(main.undo_redo.can_undo(), "and it's an undo step")
await _frames()
func _test_other_cards() -> void:
print("Other cards")
main.select_card("loot")
var t := _t("loot")
var rows: Array = insp.fields["inputs_rows"]
_eq(rows.size(), 1, "declared inputs are listed")
var le := InspectorKit.find_tagged(insp, "card.in.0.default") as LineEdit
le.text = "2"
le.text_changed.emit("2")
_eq(t.inputs, [{"name": "tier", "label": "Tier", "default": "2"}], "editing a default")
(InspectorKit.find_tagged(insp, "card.name") as LineEdit).text_changed.emit("Treasure")
_eq(t.name, "Treasure", "name")
# Router cases.
main.select_card("rt")
var rt := _t("rt")
InspectorCard.add_case(insp)
_eq(rt.entries.size(), 3, "+ Add case")
_eq(rt.entries[2].id, "c2", "it goes before the Otherwise case")
insp.set_case_when(rt.entries[1].id, "@luck >= 1")
_eq(rt.entries[1].when, "@luck >= 1", "a case's condition")
_eq(Roller.lint_router(rt), [], "the router is fine")
# A router case from the result side.
main.select_result("rt", "c1")
_check(insp.case_builder != null and insp.case_builder.clauses.size() == 1, "a case result shows its condition builder")
# Loop.
main.select_card("lp")
InspectorCard.set_loop_mode(insp, "while")
_check(_t("lp").loop_mode == "while" and _t("lp").loop_expr == "i < 3", "a loop switches to while with a condition")
(insp.fields["loop_cond"] as ConditionBuilder).set_clause_value(0, "5")
_eq(_t("lp").loop_expr, "i < 5", "and the builder edits it")
InspectorCard.set_loop_mode(insp, "times")
_eq(_t("lp").loop_expr, "3", "back to times")
# Variable card.
main.select_card("luck")
_eq(insp.apply_settings({"initial": "3"}), "", "a variable's starting value")
_eq(_t("luck").initial, "3", "(written)")
_check(insp.apply_settings({"var_name": "Bad Name"}) != "", "a bad name is refused")
await _frames()
func _test_add_kinds() -> void:
print("+ Card ▾")
var labels: Array = main.editing.ADD_KINDS.map(func(k: Array) -> String: return k[0])
_check(labels.any(func(s: String) -> bool: return s.begins_with("Check")), "Check card is in the menu")
_check(labels.any(func(s: String) -> bool: return s.begins_with("Collection")), "Collection is in the menu")
_eq(main.editing._add_menu.text, "+ Card ▾", "the button reads + Card ▾")
var c := main.editing.add_table(RollTable.KIND_CHECK)
_check(c.kind == RollTable.KIND_CHECK and c.name == "Check" and c.entries.size() == 2, "adding a check card")
_eq(insp.selection.get("tid"), c.id, "a new card is selected in the inspector")
var col := main.editing.add_table(RollTable.KIND_VARIABLE, RollTable.VAR_COLLECTION)
_check(col.is_collection() and col.name == "Skills" and col.var_name == "skill_2", "adding a collection (%s, @%s)" % [col.name, col.var_name])
var v := main.editing.add_table(RollTable.KIND_VARIABLE, "number")
_eq(v.name, "New variable", "a plain variable keeps its name")
await _frames()