Tables are cards on a felt board, joined by copper pipes that carry a roll from one table to the next. Play mode rolls with a flicker and a bead down each pipe; Build mode edits names, results, ranges and pipes. - core/: data model (RollTable, TableEntry, TowerBoard), sample board with a d100 table of 100 trinkets and a weighted d100 range table, and a Roller with a depth limit - ui/: board with pan and zoom, pipe and port layers, collapsible table cards, result tray with earlier rolls, undo toasts, and a Collapse all / Expand all button - assets/fonts/: Rokkitt and Atkinson Hyperlegible (SIL OFL) - tests/test_roller.gd: headless checks for the model and roller Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.1 KiB
GDScript
43 lines
1.1 KiB
GDScript
class_name TableEntry
|
||
extends RefCounted
|
||
## One possible result on a table. An entry may pipe into other tables, and on a
|
||
## ranged (dice) table it covers a span of die values such as 01–30.
|
||
|
||
var id: String = ""
|
||
var text: String = ""
|
||
## IDs of the tables this entry rolls on next.
|
||
var pipes: Array[String] = []
|
||
var has_range: bool = false
|
||
var range_lo: int = 1
|
||
var range_hi: int = 1
|
||
|
||
|
||
func _init(p_id: String = "", p_text: String = "") -> void:
|
||
id = p_id
|
||
text = p_text
|
||
|
||
|
||
## How many die faces this entry covers. Plain entries cover exactly one.
|
||
func span() -> int:
|
||
return range_hi - range_lo + 1 if has_range else 1
|
||
|
||
|
||
func to_dict() -> Dictionary:
|
||
var d := {"id": id, "text": text}
|
||
if not pipes.is_empty():
|
||
d["pipes"] = pipes.duplicate()
|
||
if has_range:
|
||
d["range"] = [range_lo, range_hi]
|
||
return d
|
||
|
||
|
||
static func from_dict(d: Dictionary) -> TableEntry:
|
||
var e := TableEntry.new(str(d.get("id", "")), str(d.get("text", "")))
|
||
for p in d.get("pipes", []):
|
||
e.pipes.append(str(p))
|
||
var r: Variant = d.get("range")
|
||
if r is Array and r.size() == 2:
|
||
e.has_range = true
|
||
e.range_lo = int(r[0])
|
||
e.range_hi = int(r[1])
|
||
return e
|