TableTower/tests/test_entry_drag.gd
RobinFiredrake 194f157140 Build mode: drag a result's handle to reorder a card's results
Ranged cards keep their ranges in place so the results move through
them. The router case arrows share the same move_entry.

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

58 lines
2.1 KiB
GDScript

extends TestBase
## Build mode: dragging a result's handle reorders the card's results. Ranged
## cards keep their ranges in place; the move is one undo step.
## Run: godot --headless --path . -s res://tests/test_entry_drag.gd -- --sample
func _init() -> void:
if not await start_main():
return
main.set_mode(Main.Mode.BUILD)
await _frames()
await _test_plain()
await _test_ranged()
finish()
func _handle(card: TableCard, eid: String) -> EntryHandle:
var hs := (card.rows[eid] as Control).find_children("*", "EntryHandle", true, false)
return hs[0] if not hs.is_empty() else null
func _ids(t: RollTable) -> Array:
return t.entries.map(func(e: TableEntry) -> String: return e.id)
func _test_plain() -> void:
var t := main.data.get_table("monsters")
var card := main.card_for(t.id)
var before := _ids(t)
var h := _handle(card, before[0])
_check(h != null, "build rows have a drag handle")
var last := (card.rows[before[-1]] as Control).get_global_rect()
_eq(h.track(last.end + Vector2(0, 10)), before.size() - 1, "below the last row lands at the end")
_check(h._line != null and h._line.visible, "an insertion line shows")
h.finish()
await _frames()
var after := _ids(t)
_check(after[-1] == before[0] and after[0] == before[1], "the first result moved to the end")
main.undo_redo._commit_edits()
main.undo_redo.undo()
await _frames()
_eq(_ids(main.data.get_table("monsters")), before, "undo puts the order back")
func _test_ranged() -> void:
var t := main.data.get_table("wilderness")
var card := main.card_for(t.id)
var ranges := t.entries.map(func(e: TableEntry) -> Vector2i: return Vector2i(e.range_lo, e.range_hi))
var moved: String = t.entries[0].id
var h := _handle(card, moved)
var second := (card.rows[t.entries[2].id] as Control).get_global_rect()
h.track(second.get_center() + Vector2(0, 2))
h.finish()
await _frames()
_eq(t.entries.find(t.find_entry(moved)), 2, "the result moved down two places")
_eq(t.entries.map(func(e: TableEntry) -> Vector2i: return Vector2i(e.range_lo, e.range_hi)), ranges,
"the ranges stay in place")
_eq(t.range_problems(), "", "the ranges still cover the dice")