2026-11-25 15:36:55 -06:00
|
|
|
extends AppTestBase
|
2026-11-14 13:40:20 -06:00
|
|
|
## List values: the "Add to list" change row (picking a list, the result's own
|
|
|
|
|
## text as the item, a new value made there is a list), and "Allow repeats".
|
2026-11-25 15:36:55 -06:00
|
|
|
## Run: tools/run_tests.sh lists
|
2026-11-14 13:40:20 -06:00
|
|
|
|
|
|
|
|
|
2026-11-25 15:36:55 -06:00
|
|
|
func run() -> void:
|
|
|
|
|
if not await start_main(false):
|
2026-11-14 13:40:20 -06:00
|
|
|
return
|
|
|
|
|
main.set_mode(Main.Mode.BUILD)
|
|
|
|
|
main.data.load_dict({"format_version": 2, "id": "list-test", "name": "List test", "tables": [
|
|
|
|
|
{"id": "groc", "name": "Groceries", "kind": "variable", "var_name": "groceries", "var_type": "list", "x": 40, "y": 40, "entries": []},
|
|
|
|
|
{"id": "shop", "name": "Shop", "x": 340, "y": 40, "entries": [{"id": "e1", "text": "[b]Eggs[/b]"}]},
|
|
|
|
|
]})
|
|
|
|
|
main.persistent_vars.clear()
|
|
|
|
|
main._rebuild_cards()
|
|
|
|
|
await _frames(4)
|
|
|
|
|
await _test_add_to_list_row()
|
|
|
|
|
_test_repeats()
|
|
|
|
|
finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _test_add_to_list_row() -> void:
|
|
|
|
|
main.select_result("shop", "e1")
|
|
|
|
|
await _frames(2)
|
|
|
|
|
var fx := main.inspector.effects
|
|
|
|
|
fx.add_row()
|
|
|
|
|
fx.set_row_op(0, "append")
|
|
|
|
|
_eq(fx.rows[0]["amount"], "Eggs", "Add to list offers the result's own text")
|
|
|
|
|
fx.set_row_var(0, "@groceries")
|
|
|
|
|
_eq(main.data.get_table("shop").find_entry("e1").effects, "@groceries += \"Eggs\"", "and writes it as the item")
|
|
|
|
|
var picker := ValuePicker.new(main)
|
|
|
|
|
picker.kinds = ["list", "text"]
|
|
|
|
|
var made := picker.create_value("Inventory", true)
|
|
|
|
|
var card := main.variable_card(made.trim_prefix("@"))
|
|
|
|
|
_check(card != null and card.var_type == "list", "a new value made from a list picker is a list")
|
|
|
|
|
picker.free()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _test_repeats() -> void:
|
|
|
|
|
_eq(Effects.list_with("Eggs", "eggs"), "Eggs", "without repeats an item already there isn't added again")
|
|
|
|
|
_eq(Effects.list_with("Eggs", "Eggs", false, true), "Eggs, Eggs", "with repeats it's added every time, in order")
|
|
|
|
|
_eq(Effects.list_with("Eggs, Milk, Eggs", "Eggs", true), "Milk, Eggs", "removing takes out the first match")
|
|
|
|
|
var groc := main.data.get_table("groc")
|
|
|
|
|
groc.list_repeats = true
|
|
|
|
|
_check(RollTable.from_dict(groc.to_dict()).list_repeats, "Allow repeats is saved with the card")
|
|
|
|
|
var ctx := Roller.new_context(main.data, main.rng, {}, {})
|
|
|
|
|
Effects.run("@groceries += \"Eggs\"\n@groceries += \"Eggs\"", ctx, "shop")
|
|
|
|
|
_eq(ctx.get_value("@groceries"), "Eggs, Eggs", "a list that allows repeats collects each one")
|