Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
class_name Main
|
|
|
|
|
|
extends Control
|
|
|
|
|
|
## The app window: top bar, felt board and result tray. Owns the board data,
|
|
|
|
|
|
## the Play/Build mode, roll animation, and editing actions with undo.
|
|
|
|
|
|
|
|
|
|
|
|
enum Mode { PLAY, BUILD }
|
|
|
|
|
|
|
|
|
|
|
|
const HISTORY_SIZE := 6
|
|
|
|
|
|
const SAVE_DELAY := 0.6
|
|
|
|
|
|
const HINTS := {
|
2026-11-08 12:53:39 -06:00
|
|
|
|
Mode.PLAY: "Click a die to roll. Shift-click skips straight to the result.",
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
Mode.BUILD: "Type to edit. Drag from a ● to another table to lay a pipe. Click a pipe for its options.",
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var data: TowerBoard
|
2026-11-08 12:11:26 -06:00
|
|
|
|
var library: LibraryStore
|
|
|
|
|
|
var state: StateStore
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var mode: Mode = Mode.PLAY
|
|
|
|
|
|
var cards: Dictionary = {} # table id -> TableCard
|
|
|
|
|
|
var lit_entries: Dictionary = {} # "tid:eid" -> true
|
|
|
|
|
|
var lit_pipes: Dictionary = {} # "tid:eid>to" -> true
|
|
|
|
|
|
var current: Dictionary = {}
|
|
|
|
|
|
var history: Array = []
|
|
|
|
|
|
var rng := RandomNumberGenerator.new()
|
|
|
|
|
|
|
|
|
|
|
|
var board: BoardView
|
|
|
|
|
|
var tray: ResultTray
|
|
|
|
|
|
|
|
|
|
|
|
var _token := 0
|
|
|
|
|
|
var _pulse_tween: Tween
|
|
|
|
|
|
var _link_from: Dictionary = {}
|
|
|
|
|
|
var _drop_card: TableCard
|
|
|
|
|
|
var _hint: Label
|
|
|
|
|
|
var _play_button: Button
|
|
|
|
|
|
var _build_button: Button
|
|
|
|
|
|
var _build_tools: Control
|
|
|
|
|
|
var _collapse_all: Button
|
|
|
|
|
|
var _toast: PanelContainer
|
|
|
|
|
|
var _toast_label: Label
|
|
|
|
|
|
var _toast_undo: Button
|
|
|
|
|
|
var _toast_timer: Timer
|
|
|
|
|
|
var _save_timer: Timer
|
|
|
|
|
|
var _undo_snapshot := ""
|
|
|
|
|
|
var _saving_enabled := true
|
|
|
|
|
|
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
# Local state for the current collection (see load_local_state). Kept in memory
|
|
|
|
|
|
# and written to `state` when there is one (saving disabled: memory only).
|
|
|
|
|
|
var decks: Dictionary = {} # table id -> DeckState
|
|
|
|
|
|
var persistent_vars: Dictionary = {} # name without "@" -> {"value", "source"}
|
|
|
|
|
|
var lit_texts: Dictionary = {} # "tid:eid" -> expanded BBCode from the last roll
|
|
|
|
|
|
var _details_popup: DetailsPopup
|
|
|
|
|
|
var _pipe_popover: PipePopover
|
|
|
|
|
|
var _ref_cache: Dictionary = {} # entry text -> Array[String] of referenced table ids
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
## Choice cards: func(request: Dictionary) -> Variant, awaited by the roller
|
|
|
|
|
|
## (docs/LOGIC.md §8). Until the pop-up exists this gives the headless answers.
|
|
|
|
|
|
var prompt_hook: Callable = func(req: Dictionary) -> Variant: return Roller.default_reply(req)
|
|
|
|
|
|
## The context of the roll in progress, or null; its root is the tree so far
|
|
|
|
|
|
## (Roller.progress()).
|
|
|
|
|
|
var rolling_ctx: RollContext = null
|
|
|
|
|
|
## Chains longer than this show at once instead of animating.
|
|
|
|
|
|
const LONG_CHAIN := 40
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
|
rng.randomize()
|
|
|
|
|
|
theme = Style.app_theme()
|
|
|
|
|
|
var args := OS.get_cmdline_user_args()
|
|
|
|
|
|
if args.has("--sample") or _arg_value(args, "--screenshot") != "":
|
|
|
|
|
|
_saving_enabled = false
|
|
|
|
|
|
if _saving_enabled:
|
2026-11-08 12:11:26 -06:00
|
|
|
|
_open_library()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
if data == null:
|
|
|
|
|
|
data = SampleBoard.create()
|
2026-11-08 12:11:26 -06:00
|
|
|
|
data.id = "fantasy-loot"
|
|
|
|
|
|
data.name = "Fantasy Loot"
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
_build_ui()
|
|
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
_seed_session()
|
|
|
|
|
|
_update_collapse_all()
|
|
|
|
|
|
# Let the cards lay out before fitting them to the window.
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
board.fit()
|
|
|
|
|
|
_run_cli(args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree() -> void:
|
2026-11-08 12:11:26 -06:00
|
|
|
|
_save_now()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Migrates the old board.json if needed, then opens the last collection (or the
|
|
|
|
|
|
## first one, or a new "Fantasy Loot" made from the sample tables).
|
|
|
|
|
|
func _open_library() -> void:
|
|
|
|
|
|
state = StateStore.new()
|
|
|
|
|
|
library = LibraryStore.new("user://", state)
|
|
|
|
|
|
library.migrate_legacy()
|
|
|
|
|
|
var last := str(state.get_setting("last_collection", ""))
|
|
|
|
|
|
if last != "":
|
|
|
|
|
|
data = library.load_collection(last)
|
|
|
|
|
|
if data == null:
|
|
|
|
|
|
for entry in library.list():
|
|
|
|
|
|
data = library.load_collection(str(entry["id"]))
|
|
|
|
|
|
if data:
|
|
|
|
|
|
break
|
|
|
|
|
|
if data == null:
|
|
|
|
|
|
data = library.create("Fantasy Loot")
|
|
|
|
|
|
data.tables = SampleBoard.create().tables
|
|
|
|
|
|
library.save(data)
|
|
|
|
|
|
state.set_setting("last_collection", data.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _save_now() -> void:
|
|
|
|
|
|
if _saving_enabled and data and library:
|
|
|
|
|
|
library.save(data)
|
|
|
|
|
|
state.set_setting("last_collection", data.id)
|
|
|
|
|
|
state.save()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- UI ----------
|
|
|
|
|
|
|
|
|
|
|
|
func _build_ui() -> void:
|
|
|
|
|
|
set_anchors_and_offsets_preset(PRESET_FULL_RECT)
|
|
|
|
|
|
var root := VBoxContainer.new()
|
|
|
|
|
|
root.set_anchors_and_offsets_preset(PRESET_FULL_RECT)
|
|
|
|
|
|
root.add_theme_constant_override("separation", 0)
|
|
|
|
|
|
add_child(root)
|
|
|
|
|
|
root.add_child(_build_top_bar())
|
|
|
|
|
|
board = BoardView.new()
|
|
|
|
|
|
board.setup(self)
|
|
|
|
|
|
root.add_child(board)
|
|
|
|
|
|
tray = ResultTray.new()
|
|
|
|
|
|
tray.setup(self)
|
|
|
|
|
|
root.add_child(tray)
|
|
|
|
|
|
_build_toast()
|
|
|
|
|
|
|
|
|
|
|
|
_save_timer = Timer.new()
|
|
|
|
|
|
_save_timer.one_shot = true
|
|
|
|
|
|
_save_timer.wait_time = SAVE_DELAY
|
|
|
|
|
|
_save_timer.timeout.connect(func() -> void:
|
2026-11-08 12:11:26 -06:00
|
|
|
|
_save_now()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
)
|
|
|
|
|
|
add_child(_save_timer)
|
|
|
|
|
|
resized.connect(_place_toast)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _build_top_bar() -> Control:
|
|
|
|
|
|
var bar := PanelContainer.new()
|
|
|
|
|
|
var sb := Style.box(Style.FELT_DEEP, 0, [16, 10, 16, 10])
|
|
|
|
|
|
sb.border_width_bottom = 1
|
|
|
|
|
|
sb.border_color = Color(1, 1, 1, 0.07)
|
|
|
|
|
|
bar.add_theme_stylebox_override("panel", sb)
|
|
|
|
|
|
var h := HBoxContainer.new()
|
|
|
|
|
|
h.add_theme_constant_override("separation", 16)
|
|
|
|
|
|
bar.add_child(h)
|
|
|
|
|
|
|
|
|
|
|
|
var brand := HBoxContainer.new()
|
|
|
|
|
|
brand.add_theme_constant_override("separation", 9)
|
|
|
|
|
|
var mark := Control.new()
|
|
|
|
|
|
mark.custom_minimum_size = Vector2(20, 24)
|
|
|
|
|
|
mark.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
mark.draw.connect(func() -> void: Icons.draw_tower(mark, Vector2(0, 0), 20.0 / 22.0, Style.ON_FELT, Style.BRASS))
|
|
|
|
|
|
brand.add_child(mark)
|
|
|
|
|
|
var title := Style.make_label("TableTower", Style.display(), 23, Style.ON_FELT)
|
|
|
|
|
|
title.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
brand.add_child(title)
|
|
|
|
|
|
h.add_child(brand)
|
|
|
|
|
|
|
|
|
|
|
|
var seg := PanelContainer.new()
|
|
|
|
|
|
seg.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.28), 9, [3, 3, 3, 3]))
|
|
|
|
|
|
seg.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
var seg_row := HBoxContainer.new()
|
|
|
|
|
|
seg_row.add_theme_constant_override("separation", 0)
|
|
|
|
|
|
seg.add_child(seg_row)
|
|
|
|
|
|
var group := ButtonGroup.new()
|
|
|
|
|
|
_play_button = _seg_button("Play", group)
|
|
|
|
|
|
_build_button = _seg_button("Build", group)
|
|
|
|
|
|
_play_button.button_pressed = true
|
|
|
|
|
|
_play_button.pressed.connect(func() -> void: set_mode(Mode.PLAY))
|
|
|
|
|
|
_build_button.pressed.connect(func() -> void: set_mode(Mode.BUILD))
|
|
|
|
|
|
seg_row.add_child(_play_button)
|
|
|
|
|
|
seg_row.add_child(_build_button)
|
|
|
|
|
|
h.add_child(seg)
|
|
|
|
|
|
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_switcher = CollectionSwitcher.new()
|
|
|
|
|
|
_switcher.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
_switcher.setup(self)
|
|
|
|
|
|
h.add_child(_switcher)
|
|
|
|
|
|
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_hint = Style.make_label(HINTS[mode], Style.body(), 15, Style.ON_FELT_MUTED)
|
|
|
|
|
|
_hint.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
|
|
|
|
_hint.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
_hint.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
|
|
|
|
|
_hint.custom_minimum_size = Vector2(60, 0)
|
|
|
|
|
|
h.add_child(_hint)
|
|
|
|
|
|
|
|
|
|
|
|
var tools := HBoxContainer.new()
|
|
|
|
|
|
tools.add_theme_constant_override("separation", 6)
|
|
|
|
|
|
_build_tools = tools
|
|
|
|
|
|
var add := Style.bar_button("+ Table", true)
|
|
|
|
|
|
add.pressed.connect(add_table)
|
|
|
|
|
|
tools.add_child(add)
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_board_menu = IoMenu.new()
|
|
|
|
|
|
_board_menu.setup(true, collections_enabled())
|
|
|
|
|
|
_board_menu.reset_requested.connect(reset_sample)
|
|
|
|
|
|
_board_menu.import_requested.connect(import_collection)
|
|
|
|
|
|
_board_menu.export_requested.connect(export_collection)
|
|
|
|
|
|
tools.add_child(_board_menu)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
tools.visible = false
|
|
|
|
|
|
h.add_child(tools)
|
|
|
|
|
|
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_endless_chip = _make_endless_chip()
|
|
|
|
|
|
h.add_child(_endless_chip)
|
|
|
|
|
|
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_collapse_all = Style.bar_button("Collapse all")
|
|
|
|
|
|
_collapse_all.tooltip_text = "Collapse or expand every table at once"
|
|
|
|
|
|
_collapse_all.pressed.connect(func() -> void: set_all_collapsed(_any_expanded()))
|
|
|
|
|
|
h.add_child(_collapse_all)
|
|
|
|
|
|
|
|
|
|
|
|
var zoom := HBoxContainer.new()
|
|
|
|
|
|
zoom.add_theme_constant_override("separation", 6)
|
|
|
|
|
|
var zout := Style.bar_button("−")
|
|
|
|
|
|
zout.tooltip_text = "Zoom out"
|
|
|
|
|
|
zout.custom_minimum_size = Vector2(34, 0)
|
|
|
|
|
|
zout.pressed.connect(func() -> void: board.set_zoom(board.zoom / 1.15))
|
|
|
|
|
|
var zfit := Style.bar_button("Fit")
|
|
|
|
|
|
zfit.tooltip_text = "Show every table"
|
|
|
|
|
|
zfit.pressed.connect(func() -> void: board.fit())
|
|
|
|
|
|
var zin := Style.bar_button("+")
|
|
|
|
|
|
zin.tooltip_text = "Zoom in"
|
|
|
|
|
|
zin.custom_minimum_size = Vector2(34, 0)
|
|
|
|
|
|
zin.pressed.connect(func() -> void: board.set_zoom(board.zoom * 1.15))
|
|
|
|
|
|
for b in [zout, zfit, zin]:
|
|
|
|
|
|
zoom.add_child(b)
|
|
|
|
|
|
h.add_child(zoom)
|
|
|
|
|
|
return bar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _seg_button(text: String, group: ButtonGroup) -> Button:
|
|
|
|
|
|
var b := Button.new()
|
|
|
|
|
|
b.text = text
|
|
|
|
|
|
b.toggle_mode = true
|
|
|
|
|
|
b.button_group = group
|
|
|
|
|
|
b.add_theme_font_override("font", Style.body_bold())
|
|
|
|
|
|
b.add_theme_font_size_override("font_size", 16)
|
|
|
|
|
|
var normal := Style.box(Color(0, 0, 0, 0), 7, [16, 6, 16, 6])
|
|
|
|
|
|
var hover := Style.box(Color(1, 1, 1, 0.06), 7, [16, 6, 16, 6])
|
|
|
|
|
|
var pressed := Style.box(Style.CARD, 7, [16, 6, 16, 6])
|
|
|
|
|
|
Style.skin_button(b, normal, hover, pressed, Style.ON_FELT_MUTED, Style.ON_FELT, Style.INK)
|
|
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _build_toast() -> void:
|
|
|
|
|
|
_toast = PanelContainer.new()
|
|
|
|
|
|
var sb := Style.box(Style.CARD, 10, [16, 9, 10, 9])
|
|
|
|
|
|
sb.shadow_color = Color(0, 0, 0, 0.4)
|
|
|
|
|
|
sb.shadow_size = 18
|
|
|
|
|
|
sb.shadow_offset = Vector2(0, 8)
|
|
|
|
|
|
_toast.add_theme_stylebox_override("panel", sb)
|
|
|
|
|
|
var h := HBoxContainer.new()
|
|
|
|
|
|
h.add_theme_constant_override("separation", 12)
|
|
|
|
|
|
_toast.add_child(h)
|
|
|
|
|
|
_toast_label = Style.make_label("", Style.body(), 15, Style.INK)
|
|
|
|
|
|
_toast_label.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
h.add_child(_toast_label)
|
|
|
|
|
|
_toast_undo = Button.new()
|
|
|
|
|
|
_toast_undo.text = "Undo"
|
|
|
|
|
|
_toast_undo.add_theme_font_override("font", Style.body_bold())
|
|
|
|
|
|
_toast_undo.add_theme_font_size_override("font_size", 15)
|
|
|
|
|
|
var un := Style.box(Style.FELT, 7, [12, 5, 12, 5])
|
|
|
|
|
|
var uh := Style.box(Style.FELT_HOVER, 7, [12, 5, 12, 5])
|
|
|
|
|
|
Style.skin_button(_toast_undo, un, uh, uh, Style.BRASS)
|
|
|
|
|
|
_toast_undo.pressed.connect(_undo)
|
|
|
|
|
|
h.add_child(_toast_undo)
|
|
|
|
|
|
_toast.hide()
|
|
|
|
|
|
add_child(_toast)
|
|
|
|
|
|
_toast_timer = Timer.new()
|
|
|
|
|
|
_toast_timer.one_shot = true
|
|
|
|
|
|
_toast_timer.wait_time = 5.0
|
|
|
|
|
|
_toast_timer.timeout.connect(func() -> void:
|
|
|
|
|
|
_toast.hide()
|
|
|
|
|
|
_undo_snapshot = ""
|
|
|
|
|
|
)
|
|
|
|
|
|
add_child(_toast_timer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func toast(message: String, snapshot: String = "") -> void:
|
|
|
|
|
|
_undo_snapshot = snapshot
|
|
|
|
|
|
_toast_label.text = message
|
|
|
|
|
|
_toast_undo.visible = snapshot != ""
|
|
|
|
|
|
_toast.show()
|
|
|
|
|
|
_toast.reset_size()
|
|
|
|
|
|
_place_toast()
|
|
|
|
|
|
_toast_timer.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _place_toast() -> void:
|
|
|
|
|
|
if _toast and _toast.visible:
|
|
|
|
|
|
_toast.reset_size()
|
|
|
|
|
|
_toast.position = Vector2((size.x - _toast.size.x) / 2.0, size.y - _toast.size.y - 20.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _undo() -> void:
|
|
|
|
|
|
if _undo_snapshot == "":
|
|
|
|
|
|
return
|
|
|
|
|
|
data.load_json(_undo_snapshot)
|
|
|
|
|
|
_undo_snapshot = ""
|
|
|
|
|
|
_toast.hide()
|
|
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _snapshot() -> String:
|
|
|
|
|
|
return data.to_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Cards ----------
|
|
|
|
|
|
|
|
|
|
|
|
func card_for(id: String) -> TableCard:
|
|
|
|
|
|
return cards.get(id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func is_entry_lit(tid: String, eid: String) -> bool:
|
|
|
|
|
|
return lit_entries.has(Roller.entry_key(tid, eid))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _rebuild_cards() -> void:
|
|
|
|
|
|
for c in board.cards.get_children():
|
|
|
|
|
|
board.cards.remove_child(c)
|
|
|
|
|
|
c.queue_free()
|
|
|
|
|
|
cards.clear()
|
|
|
|
|
|
for t in data.tables:
|
|
|
|
|
|
var card := TableCard.new()
|
|
|
|
|
|
board.cards.add_child(card)
|
|
|
|
|
|
card.setup(self, t)
|
|
|
|
|
|
cards[t.id] = card
|
|
|
|
|
|
_update_collapse_all()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _refresh_lit() -> void:
|
|
|
|
|
|
for card in cards.values():
|
|
|
|
|
|
(card as TableCard).refresh_lit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_mode(m: Mode) -> void:
|
|
|
|
|
|
mode = m
|
|
|
|
|
|
_play_button.set_pressed_no_signal(m == Mode.PLAY)
|
|
|
|
|
|
_build_button.set_pressed_no_signal(m == Mode.BUILD)
|
|
|
|
|
|
_hint.text = HINTS[m]
|
|
|
|
|
|
_build_tools.visible = m == Mode.BUILD
|
|
|
|
|
|
board.pipes.hover_key = ""
|
|
|
|
|
|
for card in cards.values():
|
|
|
|
|
|
(card as TableCard).rebuild()
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_update_endless_chip()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func mark_dirty() -> void:
|
|
|
|
|
|
if _saving_enabled:
|
|
|
|
|
|
_save_timer.start()
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
_ref_cache.clear()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_update_collapse_all()
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_update_endless_chip()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _any_expanded() -> bool:
|
|
|
|
|
|
for t in data.tables:
|
|
|
|
|
|
if not t.collapsed:
|
|
|
|
|
|
return true
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _update_collapse_all() -> void:
|
|
|
|
|
|
if _collapse_all:
|
|
|
|
|
|
_collapse_all.text = "Collapse all" if _any_expanded() else "Expand all"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Editing actions ----------
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_collapse(tid: String) -> void:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
t.collapsed = not t.collapsed
|
|
|
|
|
|
card_for(tid).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_all_collapsed(collapsed: bool) -> void:
|
|
|
|
|
|
for t in data.tables:
|
|
|
|
|
|
if t.collapsed != collapsed:
|
|
|
|
|
|
t.collapsed = collapsed
|
|
|
|
|
|
card_for(t.id).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func add_table() -> void:
|
|
|
|
|
|
var center := board.screen_to_world(board.size / 2.0)
|
|
|
|
|
|
var t := RollTable.new(TowerBoard.new_id("t"), "New table")
|
|
|
|
|
|
t.position = Vector2(maxf(20.0, roundf(center.x - 128.0)), maxf(20.0, roundf(center.y - 120.0)))
|
|
|
|
|
|
for n in range(1, 5):
|
|
|
|
|
|
t.entries.append(TableEntry.new(TowerBoard.new_id("e"), "Result %d" % n))
|
|
|
|
|
|
data.tables.append(t)
|
|
|
|
|
|
var card := TableCard.new()
|
|
|
|
|
|
board.cards.add_child(card)
|
|
|
|
|
|
card.setup(self, t)
|
|
|
|
|
|
cards[t.id] = card
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func reset_sample() -> void:
|
|
|
|
|
|
var snap := _snapshot()
|
2026-11-08 12:11:26 -06:00
|
|
|
|
data.tables = SampleBoard.create().tables
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
lit_entries.clear()
|
|
|
|
|
|
lit_pipes.clear()
|
|
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
board.fit()
|
|
|
|
|
|
toast("Board reset to the sample tables", snap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func add_entry(tid: String) -> void:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
var e := TableEntry.new(TowerBoard.new_id("e"), "Result %d" % (t.entries.size() + 1))
|
|
|
|
|
|
if t.is_ranged():
|
|
|
|
|
|
var hi := 0
|
|
|
|
|
|
for x in t.entries:
|
|
|
|
|
|
hi = maxi(hi, x.range_hi)
|
|
|
|
|
|
e.has_range = true
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
e.range_lo = clampi(hi + 1, t.min_value(), t.die_size())
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
e.range_hi = e.range_lo
|
|
|
|
|
|
e.text = "New range"
|
|
|
|
|
|
t.entries.append(e)
|
|
|
|
|
|
t.collapsed = false
|
|
|
|
|
|
card_for(tid).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func delete_entry(tid: String, eid: String) -> void:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
var e := t.find_entry(eid)
|
|
|
|
|
|
if e == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var snap := _snapshot()
|
|
|
|
|
|
t.entries.erase(e)
|
|
|
|
|
|
card_for(tid).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
toast("Deleted “%s”" % e.text, snap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func delete_table(tid: String) -> void:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var snap := _snapshot()
|
|
|
|
|
|
data.remove_table(tid)
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
forget_table_state(tid)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var card := card_for(tid)
|
|
|
|
|
|
cards.erase(tid)
|
|
|
|
|
|
card.queue_free()
|
|
|
|
|
|
for c in cards.values():
|
|
|
|
|
|
(c as TableCard).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
toast("Deleted %s" % t.name, snap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func remove_pipe(key: String) -> void:
|
|
|
|
|
|
var from := key.get_slice(">", 0)
|
|
|
|
|
|
var to := key.get_slice(">", 1)
|
|
|
|
|
|
var t := data.get_table(from.get_slice(":", 0))
|
|
|
|
|
|
var target := data.get_table(to)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var e := t.find_entry(from.get_slice(":", 1))
|
|
|
|
|
|
if e == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var snap := _snapshot()
|
|
|
|
|
|
e.pipes.erase(to)
|
|
|
|
|
|
lit_pipes.erase(key)
|
|
|
|
|
|
board.pipes.hover_key = ""
|
|
|
|
|
|
card_for(t.id).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
toast("Removed pipe from “%s” to %s" % [e.text, target.name if target else to], snap)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func start_link(tid: String, eid: String) -> void:
|
|
|
|
|
|
_link_from = {"tid": tid, "eid": eid}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func update_link() -> void:
|
|
|
|
|
|
var over := _card_under_mouse()
|
|
|
|
|
|
if over != _drop_card:
|
|
|
|
|
|
if is_instance_valid(_drop_card):
|
|
|
|
|
|
_drop_card.set_drop_target(false)
|
|
|
|
|
|
_drop_card = over
|
|
|
|
|
|
if _drop_card:
|
|
|
|
|
|
_drop_card.set_drop_target(true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func finish_link() -> void:
|
|
|
|
|
|
var over := _card_under_mouse()
|
|
|
|
|
|
if is_instance_valid(_drop_card):
|
|
|
|
|
|
_drop_card.set_drop_target(false)
|
|
|
|
|
|
_drop_card = null
|
|
|
|
|
|
if _link_from.is_empty() or over == null:
|
|
|
|
|
|
_link_from = {}
|
|
|
|
|
|
return
|
|
|
|
|
|
var t := data.get_table(_link_from["tid"])
|
|
|
|
|
|
var e := t.find_entry(_link_from["eid"]) if t else null
|
|
|
|
|
|
_link_from = {}
|
|
|
|
|
|
if e == null or e.pipes.has(over.table.id):
|
|
|
|
|
|
return
|
|
|
|
|
|
# Each range on a ranged table takes a single pipe, so a new one replaces the old.
|
|
|
|
|
|
var replaced: RollTable = null
|
|
|
|
|
|
if t.is_ranged():
|
|
|
|
|
|
if not e.pipes.is_empty():
|
|
|
|
|
|
replaced = data.get_table(e.pipes[0])
|
|
|
|
|
|
e.pipes.clear()
|
|
|
|
|
|
e.pipes.append(over.table.id)
|
|
|
|
|
|
card_for(t.id).rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
var msg := "“%s” now rolls on %s" % [e.text, over.table.name]
|
|
|
|
|
|
if replaced:
|
|
|
|
|
|
msg += " instead of %s" % replaced.name
|
|
|
|
|
|
toast(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _card_under_mouse() -> TableCard:
|
|
|
|
|
|
var gp := get_global_mouse_position()
|
|
|
|
|
|
var kids := board.cards.get_children()
|
|
|
|
|
|
for i in range(kids.size() - 1, -1, -1):
|
|
|
|
|
|
var card := kids[i] as TableCard
|
|
|
|
|
|
if card and card.get_global_rect().has_point(gp):
|
|
|
|
|
|
return card
|
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Rolling ----------
|
|
|
|
|
|
|
2026-11-08 12:53:39 -06:00
|
|
|
|
## Rolls a table and plays the result down its pipes. A fast roll (Shift held
|
|
|
|
|
|
## while clicking, or `fast`) skips the flicker and the beads and shows the
|
|
|
|
|
|
## whole result at once.
|
|
|
|
|
|
func start_roll(tid: String, fast: bool = false) -> void:
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var t := data.get_table(tid)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if t == null or t.kind == RollTable.KIND_VARIABLE:
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
return
|
2026-11-08 12:53:39 -06:00
|
|
|
|
fast = fast or Input.is_key_pressed(KEY_SHIFT)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_archive_current()
|
|
|
|
|
|
_token += 1
|
|
|
|
|
|
var my := _token
|
|
|
|
|
|
if _pulse_tween and _pulse_tween.is_valid():
|
|
|
|
|
|
_pulse_tween.kill()
|
|
|
|
|
|
board.pipes.pulse_key = ""
|
|
|
|
|
|
for c in cards.values():
|
|
|
|
|
|
(c as TableCard).set_rolling(false)
|
|
|
|
|
|
(c as TableCard).clear_flick()
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var ctx := Roller.new_context(data, rng, persistent_vars, decks)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
ctx.prompt = prompt_hook
|
|
|
|
|
|
rolling_ctx = ctx
|
|
|
|
|
|
var tree: Dictionary = await Roller.roll_async(data, tid, ctx)
|
|
|
|
|
|
if rolling_ctx == ctx:
|
|
|
|
|
|
rolling_ctx = null
|
|
|
|
|
|
if my != _token:
|
|
|
|
|
|
# Another roll started while this one waited for an answer.
|
|
|
|
|
|
_store_decks()
|
|
|
|
|
|
if ctx.persistent_changed:
|
|
|
|
|
|
_store_variables()
|
|
|
|
|
|
return
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
lit_entries.clear()
|
|
|
|
|
|
lit_pipes.clear()
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
lit_texts.clear()
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_refresh_lit()
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
current = {"collection": data.id, "root": tid, "root_name": t.name, "time": Time.get_unix_time_from_system(),
|
|
|
|
|
|
"steps": [], "all": Roller.flatten(tree, []), "done": false, "chain_vars": ctx.chain_vars.duplicate()}
|
|
|
|
|
|
_store_roll(ctx)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if fast or (current["all"] as Array).size() > LONG_CHAIN:
|
2026-11-08 12:53:39 -06:00
|
|
|
|
_finish_fast_roll()
|
|
|
|
|
|
return
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
tray.render()
|
|
|
|
|
|
await _play_node(tree, my)
|
|
|
|
|
|
if my == _token:
|
|
|
|
|
|
current["steps"] = current["all"]
|
|
|
|
|
|
current["done"] = true
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
## Plays a result tree step by step. Iterative (an explicit stack), so long
|
|
|
|
|
|
## chains don't recurse.
|
|
|
|
|
|
func _play_node(root_node: Dictionary, my: int) -> void:
|
|
|
|
|
|
var stack: Array = [[root_node, 0, ""]] # node, depth, pipe key that led to it
|
|
|
|
|
|
while not stack.is_empty():
|
|
|
|
|
|
var top: Array = stack.pop_back()
|
|
|
|
|
|
var n: Dictionary = top[0]
|
|
|
|
|
|
if my != _token or n.is_empty():
|
|
|
|
|
|
return
|
|
|
|
|
|
var key: String = top[2]
|
|
|
|
|
|
if key != "":
|
|
|
|
|
|
lit_pipes[key] = true
|
|
|
|
|
|
await _pulse(key, my)
|
|
|
|
|
|
if my != _token:
|
|
|
|
|
|
return
|
|
|
|
|
|
await _play_one(n, my, int(top[1]))
|
|
|
|
|
|
if my != _token:
|
|
|
|
|
|
return
|
|
|
|
|
|
if n.has("stop"):
|
|
|
|
|
|
continue
|
|
|
|
|
|
var kids: Array = n["children"]
|
|
|
|
|
|
var eid := (n["entry"] as TableEntry).id
|
|
|
|
|
|
var tid := (n["table"] as RollTable).id
|
|
|
|
|
|
for k in range(kids.size() - 1, -1, -1):
|
|
|
|
|
|
var c: Dictionary = kids[k]
|
|
|
|
|
|
var ck := "" if (c.has("pass") or c.has("after")) else Roller.link_key(tid, eid, c)
|
|
|
|
|
|
stack.append([c, int(top[1]) + 1, ck])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Animates one node: the card tumbles (plain rolls only), then the result lights.
|
|
|
|
|
|
func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var t: RollTable = n["table"]
|
|
|
|
|
|
var stopped := n.has("stop")
|
|
|
|
|
|
var card := card_for(t.id)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var tumble: bool = not n.has("kind") or bool(n.get("random", false))
|
|
|
|
|
|
if not stopped and card and tumble:
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
card.set_rolling(true)
|
|
|
|
|
|
for k in 8:
|
|
|
|
|
|
card = card_for(t.id)
|
|
|
|
|
|
if card == null:
|
|
|
|
|
|
break
|
|
|
|
|
|
if t.collapsed:
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
card.set_more_text("Rolling… %s" % t.fmt(rng.randi_range(t.min_value(), maxi(t.min_value(), t.die_size()))))
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
else:
|
|
|
|
|
|
card.flick_random()
|
|
|
|
|
|
await get_tree().create_timer((40.0 + k * 16.0) / 1000.0).timeout
|
|
|
|
|
|
if my != _token:
|
|
|
|
|
|
return
|
|
|
|
|
|
card = card_for(t.id)
|
|
|
|
|
|
if card:
|
|
|
|
|
|
card.clear_flick()
|
|
|
|
|
|
card.set_rolling(false)
|
|
|
|
|
|
if not stopped:
|
|
|
|
|
|
var e: TableEntry = n["entry"]
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var ek := Roller.entry_key(t.id, e.id)
|
|
|
|
|
|
lit_entries[ek] = true
|
|
|
|
|
|
lit_texts[ek] = str(n.get("summary", e.text))
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_refresh_lit()
|
|
|
|
|
|
if card:
|
|
|
|
|
|
card.reveal(e.id)
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
(current["steps"] as Array).append(Roller.step_of(n, depth))
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-11-08 12:53:39 -06:00
|
|
|
|
## Shows the whole current roll at once: every result and pipe on its path lit,
|
|
|
|
|
|
## long lists scrolled to their result, and the full chain in the tray.
|
|
|
|
|
|
func _finish_fast_roll() -> void:
|
|
|
|
|
|
var all: Array = current["all"]
|
|
|
|
|
|
_light_steps(all)
|
|
|
|
|
|
_refresh_lit()
|
|
|
|
|
|
for s: Dictionary in all:
|
|
|
|
|
|
var card := card_for(str(s.get("table_id", "")))
|
|
|
|
|
|
if card and s.has("entry_id"):
|
|
|
|
|
|
card.reveal(str(s["entry_id"]))
|
|
|
|
|
|
current["steps"] = all
|
|
|
|
|
|
current["done"] = true
|
|
|
|
|
|
current["fast"] = true
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
func _pulse(key: String, my: int) -> void:
|
|
|
|
|
|
var length := board.pipes.path_length(key)
|
|
|
|
|
|
if length <= 0.0 or my != _token:
|
|
|
|
|
|
return
|
|
|
|
|
|
board.pipes.pulse_key = key
|
|
|
|
|
|
board.pipes.pulse_t = 0.0
|
|
|
|
|
|
_pulse_tween = create_tween().set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN_OUT)
|
|
|
|
|
|
_pulse_tween.tween_property(board.pipes, "pulse_t", 1.0, clampf(length * 0.8, 260.0, 650.0) / 1000.0)
|
|
|
|
|
|
await _pulse_tween.finished
|
|
|
|
|
|
if board.pipes.pulse_key == key:
|
|
|
|
|
|
board.pipes.pulse_key = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
## Moves the current roll to the Earlier list (it's already in the saved history).
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
func _archive_current() -> void:
|
|
|
|
|
|
if current.is_empty() or current.get("archived", false):
|
|
|
|
|
|
return
|
|
|
|
|
|
current["archived"] = true
|
|
|
|
|
|
var rec := current.duplicate()
|
|
|
|
|
|
rec["steps"] = current["all"]
|
|
|
|
|
|
history.push_front(rec)
|
|
|
|
|
|
if history.size() > HISTORY_SIZE:
|
|
|
|
|
|
history.resize(HISTORY_SIZE)
|
|
|
|
|
|
|
|
|
|
|
|
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
## Opens the session: the collection's saved history, decks and variables. With
|
|
|
|
|
|
## no saved history (a fresh start, or --sample / --screenshot), it seeds a game
|
|
|
|
|
|
## already under way: a couple of earlier rolls, saved variables for the
|
|
|
|
|
|
## Variables tab, and a current roll that runs through the d100 travel table
|
|
|
|
|
|
## into the collapsed trinket table.
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
func _seed_session() -> void:
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
load_local_state()
|
|
|
|
|
|
if not current.is_empty():
|
|
|
|
|
|
_light_steps(current.get("all", []))
|
|
|
|
|
|
_refresh_lit()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
return
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var now := Time.get_unix_time_from_system()
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
# Seeded rolls draw from scratch decks so they don't use up real cards.
|
|
|
|
|
|
var scratch := {}
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
for seed_roll in [["monsters", 9], ["loot", 4]]:
|
|
|
|
|
|
if data.get_table(seed_roll[0]):
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var tree := Roller.roll(data, seed_roll[0], rng, 0, scratch)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var steps := Roller.flatten(tree, [])
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
history.push_front({"collection": data.id, "root": seed_roll[0], "root_name": data.get_table(seed_roll[0]).name,
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
"time": now - seed_roll[1] * 60, "steps": steps, "all": steps, "archived": true})
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
# A quest-style chain earlier in the session saved who guides the party and
|
|
|
|
|
|
# the day's weather, so {@guide} and {@weather} have values.
|
|
|
|
|
|
if persistent_vars.is_empty():
|
|
|
|
|
|
var ctx := Roller.new_context(data, rng, persistent_vars, scratch)
|
|
|
|
|
|
for pair in [["@guide", "names"], ["@weather", "weather"]]:
|
|
|
|
|
|
if data.get_table(pair[1]):
|
|
|
|
|
|
var n := Roller.roll(data, pair[1], rng, 0, scratch, ctx)
|
|
|
|
|
|
if not n.is_empty() and not n.has("stop"):
|
|
|
|
|
|
ctx.save(pair[0], Formatter.to_export_bbcode(str(n["summary"])), pair[1])
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var start := "wilderness" if data.get_table("wilderness") else (data.tables[0].id if not data.tables.is_empty() else "")
|
|
|
|
|
|
if start == "":
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
return
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var best := Roller.roll(data, start, rng, 0, scratch)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
for i in 400:
|
|
|
|
|
|
if Roller.reaches(best, "trinkets"):
|
|
|
|
|
|
break
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
best = Roller.roll(data, start, rng, 0, scratch)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var all := Roller.flatten(best, [])
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
current = {"collection": data.id, "root": start, "root_name": data.get_table(start).name, "time": now - 60,
|
|
|
|
|
|
"steps": all, "all": all, "done": true, "chain_vars": {}}
|
|
|
|
|
|
Roller.collect_lit(best, lit_entries, lit_pipes, lit_texts)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
_refresh_lit()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Command line (used for screenshots and checks) ----------
|
|
|
|
|
|
# godot --path . -- --screenshot=/tmp/shot.png [--build] [--expand-all] [--collapse-all]
|
2026-11-08 12:53:39 -06:00
|
|
|
|
# [--roll=<table id>] [--fast] [--shot-delay=<seconds>]
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
# [--board=<collection.json>] (with --sample/--screenshot only: show that board instead)
|
|
|
|
|
|
# [--tray=variables] [--hover=<x>,<y>] [--details=<table id>] [--pipe=<pipe key>] [--edit-details=<table id>]
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
|
|
|
|
|
|
func _arg_value(args: PackedStringArray, name: String) -> String:
|
|
|
|
|
|
for a in args:
|
|
|
|
|
|
if a.begins_with(name + "="):
|
|
|
|
|
|
return a.substr(name.length() + 1)
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _run_cli(args: PackedStringArray) -> void:
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var board_file := _arg_value(args, "--board")
|
|
|
|
|
|
if board_file != "" and not _saving_enabled:
|
|
|
|
|
|
await _load_board_file(board_file)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
if args.has("--build"):
|
|
|
|
|
|
set_mode(Mode.BUILD)
|
|
|
|
|
|
if args.has("--expand-all"):
|
|
|
|
|
|
set_all_collapsed(false)
|
|
|
|
|
|
if args.has("--collapse-all"):
|
|
|
|
|
|
set_all_collapsed(true)
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_run_shell_cli(args)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var roll := _arg_value(args, "--roll")
|
|
|
|
|
|
if roll != "":
|
2026-11-08 12:53:39 -06:00
|
|
|
|
start_roll(roll, args.has("--fast"))
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
_run_cli_extras(args)
|
Build the pipe-board app in Godot
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>
2026-11-08 12:05:41 -06:00
|
|
|
|
var shot := _arg_value(args, "--screenshot")
|
|
|
|
|
|
if shot == "":
|
|
|
|
|
|
return
|
|
|
|
|
|
var delay := _arg_value(args, "--shot-delay")
|
|
|
|
|
|
await get_tree().create_timer(delay.to_float() if delay != "" else (2.5 if roll != "" else 0.8)).timeout
|
|
|
|
|
|
var img := get_viewport().get_texture().get_image()
|
|
|
|
|
|
img.save_png(shot)
|
|
|
|
|
|
print("Saved screenshot to ", shot)
|
|
|
|
|
|
get_tree().quit()
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- App shell: collections, import/export, table settings ----------
|
|
|
|
|
|
# (Added by the shell UI. Pure rules live in CollectionSwitcher, IoMenu and
|
|
|
|
|
|
# TableSettingsDialog.)
|
|
|
|
|
|
|
|
|
|
|
|
var _switcher: CollectionSwitcher
|
|
|
|
|
|
var _board_menu: IoMenu
|
|
|
|
|
|
var _endless_chip: PanelContainer
|
|
|
|
|
|
var _endless_label: Label
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## True when collections can be listed and saved (not --sample / --screenshot).
|
|
|
|
|
|
func collections_enabled() -> bool:
|
|
|
|
|
|
return _saving_enabled and library != null and state != null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _add_modal(d: ModalCard) -> void:
|
|
|
|
|
|
add_child(d)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Opens the settings dialog for a table (Build mode editor).
|
|
|
|
|
|
func open_table_settings(table_id: String) -> void:
|
|
|
|
|
|
var t := data.get_table(table_id)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var d := TableSettingsDialog.new(t)
|
|
|
|
|
|
var snap := _snapshot()
|
|
|
|
|
|
d.applied.connect(func(result: Dictionary) -> void:
|
|
|
|
|
|
if result.get("deck_reset", false) and state and data.id != "":
|
|
|
|
|
|
state.clear_deck(data.id, t.id)
|
|
|
|
|
|
var card := card_for(t.id)
|
|
|
|
|
|
if card:
|
|
|
|
|
|
card.rebuild()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
toast("Updated %s" % t.name, snap)
|
|
|
|
|
|
)
|
|
|
|
|
|
_add_modal(d)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Collections -----
|
|
|
|
|
|
|
|
|
|
|
|
func switch_collection(id: String) -> void:
|
|
|
|
|
|
if not collections_enabled() or id == data.id:
|
|
|
|
|
|
return
|
|
|
|
|
|
_save_timer.stop()
|
|
|
|
|
|
var b := CollectionSwitcher.switch_collection(library, data, id)
|
|
|
|
|
|
if b == null:
|
|
|
|
|
|
toast("Couldn't open that collection")
|
|
|
|
|
|
return
|
|
|
|
|
|
_show_collection(b)
|
|
|
|
|
|
|
|
|
|
|
|
|
Merge play-side UI; connect it to the collection switcher
Combines the play-side integration (refs and variables through the
roller, BBCode rendering, hover details, card decks, variables panel,
copy, reference pipes, pipe options, Build card editors) with the app
shell. Switching collections now loads that collection's decks,
variables and history and relights its last roll. Adds a Quest Hooks
and Towns table to the sample so references and variables show by
default, and updates the README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:45:34 -06:00
|
|
|
|
## Swaps the board to `b`: loads that collection's decks, variables and roll
|
|
|
|
|
|
## history (lighting its last roll), rebuilds the cards, fits the view and
|
|
|
|
|
|
## remembers it as the last collection.
|
2026-11-08 12:23:21 -06:00
|
|
|
|
func _show_collection(b: TowerBoard) -> void:
|
|
|
|
|
|
data = b
|
|
|
|
|
|
_token += 1
|
|
|
|
|
|
board.pipes.pulse_key = ""
|
Merge play-side UI; connect it to the collection switcher
Combines the play-side integration (refs and variables through the
roller, BBCode rendering, hover details, card decks, variables panel,
copy, reference pipes, pipe options, Build card editors) with the app
shell. Switching collections now loads that collection's decks,
variables and history and relights its last roll. Adds a Quest Hooks
and Towns table to the sample so references and variables show by
default, and updates the README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:45:34 -06:00
|
|
|
|
load_local_state()
|
|
|
|
|
|
if not current.is_empty():
|
|
|
|
|
|
_light_steps(current.get("all", []))
|
2026-11-08 12:23:21 -06:00
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.set_setting("last_collection", data.id)
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
_switcher.refresh()
|
|
|
|
|
|
_update_endless_chip()
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
board.fit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func new_collection() -> void:
|
|
|
|
|
|
if not collections_enabled():
|
|
|
|
|
|
return
|
|
|
|
|
|
_add_modal(ModalCard.ask_text("New collection", "Name", "", "Create", func(n: String) -> void:
|
|
|
|
|
|
_show_collection(CollectionSwitcher.create_collection(library, data, n))
|
|
|
|
|
|
toast("Created “%s”" % data.name)
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func rename_collection() -> void:
|
|
|
|
|
|
if not collections_enabled():
|
|
|
|
|
|
return
|
|
|
|
|
|
_add_modal(ModalCard.ask_text("Rename collection", "Name", data.name, "Rename", func(n: String) -> void:
|
|
|
|
|
|
if CollectionSwitcher.rename_collection(library, data, n):
|
|
|
|
|
|
_switcher.refresh()
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func duplicate_collection() -> void:
|
|
|
|
|
|
if not collections_enabled():
|
|
|
|
|
|
return
|
|
|
|
|
|
var copy := CollectionSwitcher.duplicate_collection(library, data, data.name + " copy")
|
|
|
|
|
|
if copy == null:
|
|
|
|
|
|
toast("Couldn't duplicate the collection")
|
|
|
|
|
|
return
|
|
|
|
|
|
_show_collection(copy)
|
|
|
|
|
|
toast("Duplicated as “%s”" % copy.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func delete_collection() -> void:
|
|
|
|
|
|
if not collections_enabled():
|
|
|
|
|
|
return
|
|
|
|
|
|
var msg := "Delete “%s” and its saved decks, variables and history? This can't be undone." % data.name
|
|
|
|
|
|
_add_modal(ModalCard.confirm("Delete collection", msg, "Delete", func() -> void:
|
|
|
|
|
|
var gone := data.name
|
|
|
|
|
|
var next := CollectionSwitcher.delete_collection(library, data)
|
|
|
|
|
|
if next:
|
|
|
|
|
|
_show_collection(next)
|
|
|
|
|
|
toast("Deleted “%s”" % gone)
|
|
|
|
|
|
, true))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Import and export -----
|
|
|
|
|
|
|
|
|
|
|
|
func export_collection(format: Dictionary) -> void:
|
|
|
|
|
|
var dlg := FileDialog.new()
|
|
|
|
|
|
dlg.use_native_dialog = true
|
|
|
|
|
|
dlg.access = FileDialog.ACCESS_FILESYSTEM
|
|
|
|
|
|
dlg.file_mode = FileDialog.FILE_MODE_SAVE_FILE
|
|
|
|
|
|
dlg.title = "Export as " + str(format["label"])
|
|
|
|
|
|
dlg.filters = PackedStringArray([format["filter"]])
|
|
|
|
|
|
dlg.current_file = IoMenu.default_file_name(data, format)
|
|
|
|
|
|
dlg.file_selected.connect(func(path: String) -> void:
|
|
|
|
|
|
var err := TowerBoard.write_text_atomic(path, IoMenu.export_text(str(format["key"]), data))
|
|
|
|
|
|
toast("Exported to %s" % path.get_file() if err == OK else "Couldn't write %s" % path.get_file())
|
|
|
|
|
|
)
|
|
|
|
|
|
dlg.visibility_changed.connect(func() -> void:
|
|
|
|
|
|
if not dlg.visible:
|
|
|
|
|
|
dlg.queue_free.call_deferred()
|
|
|
|
|
|
)
|
|
|
|
|
|
add_child(dlg)
|
|
|
|
|
|
dlg.popup_centered_ratio(0.6)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func import_collection() -> void:
|
|
|
|
|
|
if not collections_enabled():
|
|
|
|
|
|
return
|
|
|
|
|
|
var dlg := FileDialog.new()
|
|
|
|
|
|
dlg.use_native_dialog = true
|
|
|
|
|
|
dlg.access = FileDialog.ACCESS_FILESYSTEM
|
|
|
|
|
|
dlg.file_mode = FileDialog.FILE_MODE_OPEN_FILE
|
|
|
|
|
|
dlg.title = "Import as a new collection"
|
|
|
|
|
|
dlg.filters = PackedStringArray(IoMenu.IMPORT_FILTERS)
|
|
|
|
|
|
dlg.file_selected.connect(_import_file)
|
|
|
|
|
|
dlg.visibility_changed.connect(func() -> void:
|
|
|
|
|
|
if not dlg.visible:
|
|
|
|
|
|
dlg.queue_free.call_deferred()
|
|
|
|
|
|
)
|
|
|
|
|
|
add_child(dlg)
|
|
|
|
|
|
dlg.popup_centered_ratio(0.6)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _import_file(path: String) -> void:
|
|
|
|
|
|
if not FileAccess.file_exists(path):
|
|
|
|
|
|
toast("Couldn't read %s" % path.get_file())
|
|
|
|
|
|
return
|
|
|
|
|
|
_save_now()
|
|
|
|
|
|
var r := IoMenu.import_as_collection(library, FileAccess.get_file_as_string(path), path.get_file())
|
|
|
|
|
|
if r["ok"]:
|
|
|
|
|
|
_show_collection(r["board"])
|
|
|
|
|
|
var has_report: bool = not (r["errors"] as Array).is_empty() or not (r["warnings"] as Array).is_empty() \
|
|
|
|
|
|
or not (r["guesses"] as Array).is_empty()
|
|
|
|
|
|
if has_report or not r["ok"]:
|
|
|
|
|
|
_add_modal(IoMenu.report_dialog(
|
|
|
|
|
|
"Imported “%s”" % r["board"].name if r["ok"] else "Couldn't import %s" % path.get_file(), r))
|
|
|
|
|
|
elif r["ok"]:
|
|
|
|
|
|
toast("Imported “%s” as a new collection" % r["board"].name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Endless-loop warning -----
|
|
|
|
|
|
|
|
|
|
|
|
func _make_endless_chip() -> PanelContainer:
|
|
|
|
|
|
var chip := PanelContainer.new()
|
|
|
|
|
|
chip.add_theme_stylebox_override("panel", Style.box(Style.WARN_BG, 8, [10, 4, 10, 4]))
|
|
|
|
|
|
chip.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
|
_endless_label = Style.make_label("", Style.body_bold(), 14, Style.WARN_INK)
|
|
|
|
|
|
_endless_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
|
|
|
|
|
chip.add_child(_endless_label)
|
|
|
|
|
|
chip.custom_minimum_size.x = 0
|
|
|
|
|
|
chip.hide()
|
|
|
|
|
|
return chip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _update_endless_chip() -> void:
|
|
|
|
|
|
if _endless_chip == null or data == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
var ids := Roller.endless_cycles(data)
|
|
|
|
|
|
if mode != Mode.BUILD or ids.is_empty():
|
|
|
|
|
|
_endless_chip.hide()
|
|
|
|
|
|
return
|
|
|
|
|
|
var names := PackedStringArray()
|
|
|
|
|
|
for id in ids:
|
|
|
|
|
|
var t := data.get_table(id)
|
|
|
|
|
|
names.append(t.name if t else id)
|
|
|
|
|
|
var list := ", ".join(names)
|
|
|
|
|
|
_endless_label.text = "⚠ Endless loop: " + list
|
|
|
|
|
|
var w := Style.body_bold().get_string_size(_endless_label.text, HORIZONTAL_ALIGNMENT_LEFT, -1, 14).x
|
|
|
|
|
|
_endless_label.custom_minimum_size.x = clampf(w + 4.0, 120.0, 300.0)
|
|
|
|
|
|
_endless_chip.tooltip_text = "These tables can never finish rolling, because every result leads back into a loop:\n" + "\n".join(names)
|
|
|
|
|
|
_endless_chip.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Extra screenshot flags -----
|
|
|
|
|
|
# --open-settings=<table id> open the settings dialog
|
|
|
|
|
|
# --demo-import=<file> show the import report for a file (nothing is saved)
|
|
|
|
|
|
# --demo-endless pipe the first two tables into each other
|
|
|
|
|
|
# --menu=board|collections pop up a top-bar menu
|
|
|
|
|
|
|
|
|
|
|
|
func _run_shell_cli(args: PackedStringArray) -> void:
|
|
|
|
|
|
var tid := _arg_value(args, "--open-settings")
|
|
|
|
|
|
if tid != "":
|
|
|
|
|
|
open_table_settings(tid)
|
|
|
|
|
|
var file := _arg_value(args, "--demo-import")
|
|
|
|
|
|
if file != "":
|
|
|
|
|
|
var text := FileAccess.get_file_as_string(file)
|
|
|
|
|
|
var r := IoMenu.parse_import(text, IoMenu.detect_format(file, text))
|
|
|
|
|
|
_add_modal(IoMenu.report_dialog("Imported “%s”" % file.get_file().get_basename(), r))
|
|
|
|
|
|
if args.has("--demo-endless") and data.tables.size() >= 2:
|
|
|
|
|
|
var a := data.tables[0]
|
|
|
|
|
|
var b := data.tables[1]
|
|
|
|
|
|
for e in a.entries:
|
|
|
|
|
|
e.pipes = [b.id] as Array[String]
|
|
|
|
|
|
for e in b.entries:
|
|
|
|
|
|
e.pipes = [a.id] as Array[String]
|
|
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
mark_dirty()
|
|
|
|
|
|
var menu := _arg_value(args, "--menu")
|
|
|
|
|
|
if menu == "board":
|
|
|
|
|
|
_board_menu.show_popup()
|
|
|
|
|
|
elif menu == "collections":
|
|
|
|
|
|
_switcher.show_popup()
|
Merge play-side UI; connect it to the collection switcher
Combines the play-side integration (refs and variables through the
roller, BBCode rendering, hover details, card decks, variables panel,
copy, reference pipes, pipe options, Build card editors) with the app
shell. Switching collections now loads that collection's decks,
variables and history and relights its last roll. Adds a Quest Hooks
and Towns table to the sample so references and variables show by
default, and updates the README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:45:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
# ---------- Local state: decks, persistent variables, history ----------
|
|
|
|
|
|
# Everything here is keyed by the current collection id (data.id). With saving
|
|
|
|
|
|
# disabled (--sample / --screenshot) `state` is null and it all stays in memory.
|
|
|
|
|
|
|
|
|
|
|
|
## Loads the current collection's decks, persistent variables and roll history.
|
|
|
|
|
|
## Call it again after switching `data` to another collection (then rebuild the
|
|
|
|
|
|
## cards and call tray.render()).
|
|
|
|
|
|
func load_local_state() -> void:
|
|
|
|
|
|
decks = {}
|
|
|
|
|
|
persistent_vars = {}
|
|
|
|
|
|
history.clear()
|
|
|
|
|
|
current = {}
|
|
|
|
|
|
lit_entries.clear()
|
|
|
|
|
|
lit_pipes.clear()
|
|
|
|
|
|
lit_texts.clear()
|
|
|
|
|
|
_ref_cache.clear()
|
|
|
|
|
|
if state == null or data == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
persistent_vars = state.get_variables(data.id)
|
|
|
|
|
|
for t in data.tables:
|
|
|
|
|
|
var d := state.get_deck(data.id, t.id)
|
|
|
|
|
|
if not d.is_empty():
|
|
|
|
|
|
decks[t.id] = DeckState.from_dict(d)
|
|
|
|
|
|
var recs := state.get_history(data.id)
|
|
|
|
|
|
for i in recs.size():
|
|
|
|
|
|
var rec: Dictionary = recs[i]
|
|
|
|
|
|
if not (rec.get("steps") is Array):
|
|
|
|
|
|
continue
|
|
|
|
|
|
rec["all"] = rec["steps"]
|
|
|
|
|
|
rec["done"] = true
|
|
|
|
|
|
if current.is_empty():
|
|
|
|
|
|
current = rec
|
|
|
|
|
|
elif history.size() < HISTORY_SIZE:
|
|
|
|
|
|
rec["archived"] = true
|
|
|
|
|
|
history.append(rec)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Lights the entries and pipes of a roll from its saved steps.
|
|
|
|
|
|
func _light_steps(steps: Array) -> void:
|
|
|
|
|
|
var stack: Array = []
|
|
|
|
|
|
for s: Dictionary in steps:
|
|
|
|
|
|
var d := int(s.get("depth", 0))
|
|
|
|
|
|
stack.resize(d)
|
|
|
|
|
|
stack.append(s)
|
|
|
|
|
|
if s.get("stop", false) or not s.has("entry_id"):
|
|
|
|
|
|
continue
|
|
|
|
|
|
var tid := str(s.get("table_id", ""))
|
|
|
|
|
|
var ek := Roller.entry_key(tid, str(s["entry_id"]))
|
|
|
|
|
|
lit_entries[ek] = true
|
|
|
|
|
|
lit_texts[ek] = str(s.get("text", ""))
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if d > 0 and not (s.has("pass") or s.has("after")) and stack[d - 1] is Dictionary and (stack[d - 1] as Dictionary).has("entry_id"):
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
var p: Dictionary = stack[d - 1]
|
|
|
|
|
|
var ptid := str(p.get("table_id", ""))
|
|
|
|
|
|
var peid := str(p["entry_id"])
|
|
|
|
|
|
lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## After a roll: saves the decks, any changed persistent variables and the
|
|
|
|
|
|
## history record.
|
|
|
|
|
|
func _store_roll(ctx: RollContext) -> void:
|
|
|
|
|
|
if state == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
_store_decks()
|
|
|
|
|
|
if ctx.persistent_changed:
|
|
|
|
|
|
_store_variables()
|
|
|
|
|
|
state.add_history({"collection": data.id, "root": current["root"], "root_name": current["root_name"],
|
|
|
|
|
|
"time": current["time"], "steps": current["all"], "chain_vars": current.get("chain_vars", {})})
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _store_decks() -> void:
|
|
|
|
|
|
if state == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
for tid: String in decks:
|
|
|
|
|
|
state.set_deck(data.id, tid, (decks[tid] as DeckState).to_dict())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _store_variables() -> void:
|
|
|
|
|
|
if state == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
state.clear_variables(data.id)
|
|
|
|
|
|
for n: String in persistent_vars:
|
|
|
|
|
|
var v: Variant = persistent_vars[n]
|
|
|
|
|
|
if v is Dictionary:
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
state.set_variable(data.id, n, v.get("value", ""), str(v.get("source", "")))
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
else:
|
|
|
|
|
|
state.set_variable(data.id, n, str(v))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A deleted table's deck and the variables it set are forgotten.
|
|
|
|
|
|
func forget_table_state(tid: String) -> void:
|
|
|
|
|
|
decks.erase(tid)
|
|
|
|
|
|
for n in persistent_vars.keys():
|
|
|
|
|
|
var v: Variant = persistent_vars[n]
|
|
|
|
|
|
if v is Dictionary and str(v.get("source", "")) == tid:
|
|
|
|
|
|
persistent_vars.erase(n)
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.forget_table(data.id, tid)
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
if tray:
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Vector2i(cards left, total) for a card-mode table.
|
|
|
|
|
|
func cards_left(tid: String) -> Vector2i:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return Vector2i.ZERO
|
|
|
|
|
|
var deck: DeckState = decks.get(tid)
|
|
|
|
|
|
return deck.cards_left(t) if deck else DeckState.new().cards_left(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func reshuffle_table(tid: String) -> void:
|
|
|
|
|
|
var t := data.get_table(tid)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
return
|
|
|
|
|
|
decks.erase(tid)
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.clear_deck(data.id, tid)
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
var card := card_for(tid)
|
|
|
|
|
|
if card:
|
|
|
|
|
|
card.update_deck()
|
|
|
|
|
|
toast("Reshuffled %s" % Formatter.strip_tags(t.name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The expanded text an entry showed in the last roll, or "" if it isn't lit.
|
|
|
|
|
|
func lit_text(tid: String, eid: String) -> String:
|
|
|
|
|
|
return str(lit_texts.get(Roller.entry_key(tid, eid), ""))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Ids of the tables an entry's text references (cached until the next edit).
|
|
|
|
|
|
func ref_targets_for(e: TableEntry) -> Array[String]:
|
|
|
|
|
|
if not _ref_cache.has(e.text):
|
|
|
|
|
|
_ref_cache[e.text] = Roller.ref_targets(data, e.text)
|
|
|
|
|
|
return _ref_cache[e.text]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Variables ----------
|
|
|
|
|
|
|
|
|
|
|
|
func set_variable(name: String, value: String) -> void:
|
|
|
|
|
|
var old: Variant = persistent_vars.get(name)
|
|
|
|
|
|
var source := str(old.get("source", "")) if old is Dictionary else ""
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
# A number stays a number when the new text is one too.
|
|
|
|
|
|
var was: Variant = old.get("value") if old is Dictionary else null
|
|
|
|
|
|
var typed: Variant = Expr.to_value(value) if Expr.is_number(was) and Expr.is_number(value) else value
|
|
|
|
|
|
persistent_vars[name] = {"value": typed, "source": source}
|
Play-side UI: BBCode rendering, hover details, card decks, variables, copy, ref pipes
- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:43:01 -06:00
|
|
|
|
_store_variables()
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func clear_variable(name: String) -> void:
|
|
|
|
|
|
if not persistent_vars.erase(name):
|
|
|
|
|
|
return
|
|
|
|
|
|
_store_variables()
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
toast("Cleared {@%s}" % name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Rolls the variable's source table again and saves the new result.
|
|
|
|
|
|
func reroll_variable(name: String) -> void:
|
|
|
|
|
|
var v: Variant = persistent_vars.get(name)
|
|
|
|
|
|
var source := str(v.get("source", "")) if v is Dictionary else ""
|
|
|
|
|
|
var t := data.get_table(source)
|
|
|
|
|
|
if t == null:
|
|
|
|
|
|
toast("{@%s} has no table to re-roll from" % name)
|
|
|
|
|
|
return
|
|
|
|
|
|
var ctx := Roller.new_context(data, rng, persistent_vars, decks)
|
|
|
|
|
|
var n := Roller.roll(data, source, rng, 0, decks, ctx)
|
|
|
|
|
|
if n.is_empty() or n.has("stop"):
|
|
|
|
|
|
toast("Couldn't re-roll {@%s}: %s" % [name, Formatter.strip_tags(str(n.get("summary", "no result")))])
|
|
|
|
|
|
return
|
|
|
|
|
|
var value := Formatter.to_export_bbcode(str(n["summary"]))
|
|
|
|
|
|
persistent_vars[name] = {"value": value, "source": source}
|
|
|
|
|
|
_store_decks()
|
|
|
|
|
|
_store_variables()
|
|
|
|
|
|
if state:
|
|
|
|
|
|
state.save()
|
|
|
|
|
|
_refresh_lit()
|
|
|
|
|
|
tray.render()
|
|
|
|
|
|
toast("{@%s} is now %s" % [name, Formatter.strip_tags(value)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Copy ----------
|
|
|
|
|
|
|
|
|
|
|
|
## Copies the current result: ResultTray.COPY_TEXT, COPY_BBCODE or COPY_DETAILS.
|
|
|
|
|
|
func copy_current(kind: int) -> void:
|
|
|
|
|
|
if current.is_empty():
|
|
|
|
|
|
return
|
|
|
|
|
|
var text := result_text(current.get("all", []), kind)
|
|
|
|
|
|
DisplayServer.clipboard_set(text)
|
|
|
|
|
|
toast(["Copied as text", "Copied as BBCode", "Copied with details"][clampi(kind, 0, 2)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## One line per table rolled, indented by depth. Inline rolls are already part
|
|
|
|
|
|
## of their parent's text, so they don't get lines of their own.
|
|
|
|
|
|
func result_text(steps: Array, kind: int) -> String:
|
|
|
|
|
|
var lines := PackedStringArray()
|
|
|
|
|
|
for s: Dictionary in steps:
|
|
|
|
|
|
if s.get("inline", false):
|
|
|
|
|
|
continue
|
|
|
|
|
|
var indent := " ".repeat(int(s.get("depth", 0)))
|
|
|
|
|
|
var tname := str(s.get("table", ""))
|
|
|
|
|
|
var text := str(s.get("text", ""))
|
|
|
|
|
|
if kind == ResultTray.COPY_BBCODE:
|
|
|
|
|
|
lines.append(indent + "[b]%s:[/b] %s" % [Formatter.to_export_bbcode(tname), Formatter.to_export_bbcode(text)])
|
|
|
|
|
|
else:
|
|
|
|
|
|
lines.append(indent + "%s: %s" % [Formatter.strip_tags(tname), Formatter.strip_tags(text)])
|
|
|
|
|
|
if kind == ResultTray.COPY_DETAILS:
|
|
|
|
|
|
var t := data.get_table(str(s.get("table_id", "")))
|
|
|
|
|
|
var e := t.find_entry(str(s.get("entry_id", ""))) if t else null
|
|
|
|
|
|
if e and e.details.strip_edges() != "":
|
|
|
|
|
|
var pad := indent + " "
|
|
|
|
|
|
lines.append(pad + Formatter.strip_tags(e.details).strip_edges().replace("\n", "\n" + pad))
|
|
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Pop-ups ----------
|
|
|
|
|
|
|
|
|
|
|
|
## The shared hover pop-up for details.
|
|
|
|
|
|
func details() -> DetailsPopup:
|
|
|
|
|
|
if _details_popup == null:
|
|
|
|
|
|
_details_popup = DetailsPopup.new()
|
|
|
|
|
|
add_child(_details_popup)
|
|
|
|
|
|
_details_popup.setup(self)
|
|
|
|
|
|
return _details_popup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Build mode: the options for a clicked pipe (count, save as, remove).
|
|
|
|
|
|
func open_pipe_options(key: String, at: Vector2) -> void:
|
|
|
|
|
|
if _pipe_popover == null:
|
|
|
|
|
|
_pipe_popover = PipePopover.new()
|
|
|
|
|
|
add_child(_pipe_popover)
|
|
|
|
|
|
_pipe_popover.setup(self)
|
|
|
|
|
|
details().hide_for()
|
|
|
|
|
|
_pipe_popover.open(key, at)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The card's ⚙ button. Main.open_table_settings comes from the app-shell work;
|
|
|
|
|
|
## until it exists this only says so.
|
|
|
|
|
|
func request_table_settings(tid: String) -> void:
|
|
|
|
|
|
if has_method("open_table_settings"):
|
|
|
|
|
|
call("open_table_settings", tid)
|
|
|
|
|
|
else:
|
|
|
|
|
|
toast("Table settings aren't available yet")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Command line extras ----------
|
|
|
|
|
|
|
|
|
|
|
|
## Shows a collection file instead of the sample (screenshots only; nothing is saved).
|
|
|
|
|
|
func _load_board_file(path: String) -> void:
|
|
|
|
|
|
var text := FileAccess.get_file_as_string(path)
|
|
|
|
|
|
if text == "" or not data.load_json(text):
|
|
|
|
|
|
push_warning("Couldn't load board file %s" % path)
|
|
|
|
|
|
return
|
|
|
|
|
|
_rebuild_cards()
|
|
|
|
|
|
_seed_session()
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
board.fit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _run_cli_extras(args: PackedStringArray) -> void:
|
|
|
|
|
|
if _arg_value(args, "--tray") == "variables":
|
|
|
|
|
|
tray.set_side(ResultTray.Side.VARIABLES)
|
|
|
|
|
|
var edit := _arg_value(args, "--edit-details")
|
|
|
|
|
|
var ecard := card_for(edit)
|
|
|
|
|
|
if ecard:
|
|
|
|
|
|
ecard._table_details_open = true
|
|
|
|
|
|
if not ecard.table.entries.is_empty():
|
|
|
|
|
|
ecard._open_details[ecard.table.entries[0].id] = true
|
|
|
|
|
|
ecard.rebuild()
|
|
|
|
|
|
var pipe := _arg_value(args, "--pipe")
|
|
|
|
|
|
if pipe != "":
|
|
|
|
|
|
open_pipe_options(pipe, Vector2(size.x * 0.45, size.y * 0.3))
|
|
|
|
|
|
var hover := _arg_value(args, "--hover")
|
|
|
|
|
|
if hover.contains(","):
|
|
|
|
|
|
# Synthetic mouse move, to check hover pop-ups in screenshots.
|
|
|
|
|
|
await get_tree().create_timer(0.3).timeout
|
|
|
|
|
|
var ev := InputEventMouseMotion.new()
|
|
|
|
|
|
ev.position = Vector2(hover.get_slice(",", 0).to_float(), hover.get_slice(",", 1).to_float())
|
|
|
|
|
|
ev.global_position = ev.position
|
|
|
|
|
|
get_viewport().notification(NOTIFICATION_VP_MOUSE_ENTER)
|
|
|
|
|
|
get_viewport().push_input(ev)
|
|
|
|
|
|
var det := _arg_value(args, "--details")
|
|
|
|
|
|
var card := card_for(det)
|
|
|
|
|
|
if card:
|
|
|
|
|
|
await get_tree().process_frame
|
|
|
|
|
|
details().show_table(card, det)
|
|
|
|
|
|
details().pin(card.get_global_rect().position + Vector2(60, 46))
|