Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
class_name MainRolling
|
|
|
|
|
extends RefCounted
|
|
|
|
|
## Main's rolling: starting a roll, choice questions, playback on the board
|
|
|
|
|
## and in the tray, the session seed and copying results.
|
|
|
|
|
|
|
|
|
|
## Chains longer than this show at once instead of animating.
|
|
|
|
|
const LONG_CHAIN := 40
|
|
|
|
|
## Copy-as-text indents by depth up to this many levels.
|
|
|
|
|
const MAX_INDENT := 8
|
|
|
|
|
|
|
|
|
|
var m: Main
|
|
|
|
|
|
|
|
|
|
var _token := 0
|
|
|
|
|
var _pulse_tween: Tween
|
|
|
|
|
var _choice: ChoiceDialog
|
2026-11-10 19:10:11 -06:00
|
|
|
## Rolls waiting at a paused thread.
|
|
|
|
|
var pauses: RollPauses
|
2026-11-11 08:19:34 -06:00
|
|
|
## Deck-mode draws not shown yet in an animated roll.
|
|
|
|
|
var deck_reveal: DeckReveal
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
|
|
|
m = p_main
|
2026-11-10 19:10:11 -06:00
|
|
|
pauses = RollPauses.new(p_main)
|
2026-11-11 08:19:34 -06:00
|
|
|
deck_reveal = DeckReveal.new(self)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -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. Choice cards still ask (docs/LOGIC.md §8): before a
|
|
|
|
|
## question opens, the steps so far light up; after the last answer the rest
|
|
|
|
|
## of the roll shows at once. Starting a roll while a question is open cancels
|
|
|
|
|
## the old roll.
|
|
|
|
|
func start_roll(tid: String, fast: bool = false) -> void:
|
|
|
|
|
var t := m.data.get_table(tid)
|
|
|
|
|
if t == null or t.kind == RollTable.KIND_VARIABLE:
|
|
|
|
|
return
|
2026-11-10 18:40:53 -06:00
|
|
|
var back := RollRange.backwards(t)
|
|
|
|
|
if back != "":
|
|
|
|
|
m.toast("%s can't roll: its range %s runs backwards" % [Formatter.strip_tags(t.name), back])
|
|
|
|
|
return
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
# A minimized question keeps waiting; a new roll must not cancel it.
|
|
|
|
|
if _choice_waiting("Answer the waiting question first"):
|
|
|
|
|
return
|
|
|
|
|
fast = fast or Input.is_key_pressed(KEY_SHIFT)
|
|
|
|
|
_archive_current()
|
|
|
|
|
_token += 1
|
Theme tiers 1-2: theme folders, mascot recolour, background scene and tile, frame sets, picture threads, sounds; nine new built-in themes
- ThemeAssets loads a theme's files; FrameSet + GradientMap (3-stop) generalise the card frame;
ThreadStrip draws threads from a picture; BoardBackdrop draws scene and tile; MascotArt
recolours Morgan by role (logo SVG now uses the Keep File importer); SoundBoard plays
roll / card turn / thread / click / ambient with View > Sound levels.
- Vaporwave, Synthwave, Cozy Autumn, Rustic, Woodsy, Sky Blue, Frutiger Aero, Gothic, Terminal:
generated art (tools/theme_art), sounds (tools/theme_sounds), settings (tools/theme_defs).
- Ten OFL fonts; --theme=<id> flag; docs/THEMES.md format spec; test_theme_assets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:05:40 -06:00
|
|
|
if m.sound:
|
|
|
|
|
m.sound.play("roll")
|
2026-11-10 19:10:11 -06:00
|
|
|
# The roll's token lives in a holder, so a paused roll set aside can be
|
|
|
|
|
# made current again (RollPauses.answer).
|
|
|
|
|
var run := {"token": _token}
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
# A question left open by the previous roll answers Cancel; that roll then
|
|
|
|
|
# sees it has been replaced and stops quietly.
|
|
|
|
|
cancel_choice()
|
|
|
|
|
if _pulse_tween and _pulse_tween.is_valid():
|
|
|
|
|
_pulse_tween.kill()
|
|
|
|
|
m.board.pipes.pulse_key = ""
|
|
|
|
|
for c in m.cards.values():
|
|
|
|
|
(c as TableCard).set_rolling(false)
|
|
|
|
|
(c as TableCard).clear_flick()
|
|
|
|
|
var ctx := Roller.new_context(m.data, m.rng, m.persistent_vars, m.decks)
|
2026-11-10 19:10:11 -06:00
|
|
|
ctx.prompt = _prompt_for.bind(run)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m.rolling_ctx = ctx
|
|
|
|
|
m.current = {"collection": m.data.id, "root": tid, "root_name": t.name, "time": Time.get_unix_time_from_system(),
|
|
|
|
|
"steps": [], "all": [], "done": false, "pending": true}
|
|
|
|
|
var tree: Dictionary = await Roller.roll_async(m.data, tid, ctx)
|
|
|
|
|
if m.rolling_ctx == ctx:
|
|
|
|
|
m.rolling_ctx = null
|
2026-11-10 19:10:11 -06:00
|
|
|
var my := int(run["token"])
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
if my != _token or not m.is_inside_tree():
|
|
|
|
|
# Another roll started while this one waited for an answer.
|
|
|
|
|
m.local_state._store_decks()
|
|
|
|
|
if ctx.persistent_changed:
|
|
|
|
|
m.local_state._store_variables()
|
|
|
|
|
return
|
|
|
|
|
var prompted: bool = m.current.get("prompted", false)
|
|
|
|
|
m.lit_entries.clear()
|
|
|
|
|
m.lit_pipes.clear()
|
|
|
|
|
m.lit_texts.clear()
|
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
|
|
|
m.lit_columns.clear()
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m.current = {"collection": m.data.id, "root": tid, "root_name": t.name, "time": m.current.get("time", Time.get_unix_time_from_system()),
|
|
|
|
|
"steps": [], "all": Roller.flatten(tree, []), "done": false, "chain_vars": ctx.chain_vars.duplicate()}
|
|
|
|
|
if ctx.halted != "":
|
|
|
|
|
m.current["halted"] = ctx.halted
|
|
|
|
|
m.local_state._store_roll(ctx)
|
|
|
|
|
if fast or prompted or (m.current["all"] as Array).size() > LONG_CHAIN:
|
|
|
|
|
_finish_fast_roll()
|
|
|
|
|
return
|
2026-11-11 08:19:34 -06:00
|
|
|
deck_reveal.hold(m.current["all"], my)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m._refresh_lit()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
await _play_node(tree, my)
|
|
|
|
|
if my == _token:
|
2026-11-11 08:19:34 -06:00
|
|
|
deck_reveal.clear()
|
|
|
|
|
for c in m.cards.values():
|
|
|
|
|
(c as TableCard).update_deck()
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m.current["steps"] = m.current["all"]
|
|
|
|
|
m.current["done"] = true
|
|
|
|
|
m.tray.render()
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The roll's prompt hook: lights the steps so far, then asks through
|
|
|
|
|
## prompt_hook (the pop-up, or a test's script). A reply for a roll that has
|
|
|
|
|
## been replaced in the meantime is turned into Cancel.
|
2026-11-10 19:10:11 -06:00
|
|
|
func _prompt_for(req: Dictionary, run: Dictionary) -> Variant:
|
|
|
|
|
if int(run["token"]) != _token:
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
return null
|
|
|
|
|
m.current["prompted"] = true
|
|
|
|
|
m.current["asking"] = Formatter.strip_tags(str(req.get("title", "")))
|
|
|
|
|
show_progress()
|
2026-11-10 19:10:11 -06:00
|
|
|
var reply: Variant
|
|
|
|
|
if str(req.get("kind", "")) == "pause":
|
|
|
|
|
reply = await pauses.wait(req, run)
|
|
|
|
|
else:
|
|
|
|
|
reply = await m.prompt_hook.call(req)
|
|
|
|
|
if int(run["token"]) != _token:
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
return null
|
|
|
|
|
m.current.erase("asking")
|
|
|
|
|
return reply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Lights the steps of the running roll so far (Roller.progress) on the board
|
|
|
|
|
## and in the tray, all at once. Used just before a question opens.
|
|
|
|
|
func show_progress() -> void:
|
|
|
|
|
if m.rolling_ctx == null:
|
|
|
|
|
return
|
|
|
|
|
var steps := Roller.progress(m.rolling_ctx)
|
|
|
|
|
m.lit_entries.clear()
|
|
|
|
|
m.lit_pipes.clear()
|
|
|
|
|
m.lit_texts.clear()
|
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
|
|
|
m.lit_columns.clear()
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
_light_steps(steps)
|
|
|
|
|
m._refresh_lit()
|
|
|
|
|
_reveal_steps(steps)
|
|
|
|
|
m.current["steps"] = steps
|
|
|
|
|
m.current["all"] = steps
|
|
|
|
|
m.current["fast"] = true
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The real prompt hook: opens the choice pop-up and waits for its answer
|
|
|
|
|
## (an index or -1 for a pick, an int, a String, or null for Cancel).
|
|
|
|
|
func _ask_player(req: Dictionary) -> Variant:
|
|
|
|
|
cancel_choice()
|
|
|
|
|
var d := ChoiceDialog.new(req)
|
|
|
|
|
_choice = d
|
|
|
|
|
var waiter := d.reply
|
|
|
|
|
m._add_modal(d)
|
|
|
|
|
var v: Variant = await waiter.done
|
|
|
|
|
if _choice == d:
|
|
|
|
|
_choice = null
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## True (after a toast with a Show button) while a question is minimized.
|
|
|
|
|
func _choice_waiting(message: String) -> bool:
|
|
|
|
|
var d := pending_choice()
|
|
|
|
|
if d == null or not d.minimized:
|
|
|
|
|
return false
|
|
|
|
|
d.nudge(message)
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The open choice pop-up, or null.
|
|
|
|
|
func pending_choice() -> ChoiceDialog:
|
|
|
|
|
return _choice if is_instance_valid(_choice) else null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Closes an open choice pop-up as Cancel (its roll stops with "Cancelled").
|
|
|
|
|
func cancel_choice() -> void:
|
|
|
|
|
var d := pending_choice()
|
|
|
|
|
_choice = null
|
|
|
|
|
if d != null:
|
|
|
|
|
d.answer(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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 != "":
|
|
|
|
|
m.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:
|
|
|
|
|
var t: RollTable = n["table"]
|
|
|
|
|
var stopped := n.has("stop")
|
|
|
|
|
var card := m.card_for(t.id)
|
|
|
|
|
var tumble: bool = not n.has("kind") or bool(n.get("random", false))
|
|
|
|
|
# A table hidden in a collapsed group rolls on the group's card.
|
|
|
|
|
var gcard: GroupCard = m.hidden_groups().get(t.id)
|
|
|
|
|
if not stopped and gcard and tumble:
|
|
|
|
|
gcard.set_rolling(true)
|
|
|
|
|
await m.get_tree().create_timer(0.35).timeout
|
|
|
|
|
if my != _token:
|
|
|
|
|
return
|
|
|
|
|
gcard = m.hidden_groups().get(t.id)
|
|
|
|
|
if gcard:
|
|
|
|
|
gcard.set_rolling(false)
|
|
|
|
|
elif not stopped and card and tumble:
|
|
|
|
|
card.set_rolling(true)
|
|
|
|
|
for k in 8:
|
|
|
|
|
card = m.card_for(t.id)
|
|
|
|
|
if card == null:
|
|
|
|
|
break
|
|
|
|
|
if t.collapsed:
|
|
|
|
|
card.set_more_text("Rolling… %s" % t.fmt(m.rng.randi_range(t.min_value(), maxi(t.min_value(), t.die_size()))))
|
|
|
|
|
else:
|
|
|
|
|
card.flick_random()
|
|
|
|
|
await m.get_tree().create_timer((40.0 + k * 16.0) / 1000.0).timeout
|
|
|
|
|
if my != _token:
|
|
|
|
|
return
|
|
|
|
|
card = m.card_for(t.id)
|
|
|
|
|
if card:
|
|
|
|
|
card.clear_flick()
|
|
|
|
|
card.set_rolling(false)
|
|
|
|
|
if not stopped:
|
|
|
|
|
var e: TableEntry = n["entry"]
|
|
|
|
|
var ek := Roller.entry_key(t.id, e.id)
|
|
|
|
|
m.lit_entries[ek] = true
|
|
|
|
|
m.lit_texts[ek] = str(n.get("summary", e.text))
|
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
|
|
|
TableCardColumns.note_lit(m, ek, n)
|
2026-11-11 08:19:34 -06:00
|
|
|
deck_reveal.release(t.id, e.id)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m._refresh_lit()
|
|
|
|
|
if card:
|
|
|
|
|
card.reveal(e.id)
|
2026-11-10 18:26:02 -06:00
|
|
|
card.sparkle(e.id)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
(m.current["steps"] as Array).append(Roller.step_of(n, depth))
|
|
|
|
|
m.tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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 = m.current["all"]
|
2026-11-11 08:19:34 -06:00
|
|
|
deck_reveal.clear()
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
_light_steps(all)
|
|
|
|
|
m._refresh_lit()
|
|
|
|
|
_reveal_steps(all)
|
|
|
|
|
m.current["steps"] = all
|
|
|
|
|
m.current["done"] = true
|
|
|
|
|
m.current["fast"] = true
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Scrolls long cards to the last result each table gave in `steps` (one
|
|
|
|
|
## reveal per table, so thousands of steps cost one pass).
|
|
|
|
|
func _reveal_steps(steps: Array) -> void:
|
|
|
|
|
var last := {}
|
|
|
|
|
for s: Dictionary in steps:
|
|
|
|
|
if s.has("entry_id") and not s.get("stop", false):
|
|
|
|
|
last[str(s.get("table_id", ""))] = str(s["entry_id"])
|
|
|
|
|
for tid: String in last:
|
|
|
|
|
var card := m.card_for(tid)
|
|
|
|
|
if card:
|
|
|
|
|
card.reveal(last[tid])
|
Theme tiers 1-2: theme folders, mascot recolour, background scene and tile, frame sets, picture threads, sounds; nine new built-in themes
- ThemeAssets loads a theme's files; FrameSet + GradientMap (3-stop) generalise the card frame;
ThreadStrip draws threads from a picture; BoardBackdrop draws scene and tile; MascotArt
recolours Morgan by role (logo SVG now uses the Keep File importer); SoundBoard plays
roll / card turn / thread / click / ambient with View > Sound levels.
- Vaporwave, Synthwave, Cozy Autumn, Rustic, Woodsy, Sky Blue, Frutiger Aero, Gothic, Terminal:
generated art (tools/theme_art), sounds (tools/theme_sounds), settings (tools/theme_defs).
- Ten OFL fonts; --theme=<id> flag; docs/THEMES.md format spec; test_theme_assets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:05:40 -06:00
|
|
|
if card.table.card_mode and m.sound:
|
|
|
|
|
m.sound.play("card_turn")
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _pulse(key: String, my: int) -> void:
|
|
|
|
|
var length := m.board.pipes.path_length(key)
|
|
|
|
|
if length <= 0.0 or my != _token:
|
|
|
|
|
return
|
Theme tiers 1-2: theme folders, mascot recolour, background scene and tile, frame sets, picture threads, sounds; nine new built-in themes
- ThemeAssets loads a theme's files; FrameSet + GradientMap (3-stop) generalise the card frame;
ThreadStrip draws threads from a picture; BoardBackdrop draws scene and tile; MascotArt
recolours Morgan by role (logo SVG now uses the Keep File importer); SoundBoard plays
roll / card turn / thread / click / ambient with View > Sound levels.
- Vaporwave, Synthwave, Cozy Autumn, Rustic, Woodsy, Sky Blue, Frutiger Aero, Gothic, Terminal:
generated art (tools/theme_art), sounds (tools/theme_sounds), settings (tools/theme_defs).
- Ten OFL fonts; --theme=<id> flag; docs/THEMES.md format spec; test_theme_assets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:05:40 -06:00
|
|
|
if m.sound:
|
|
|
|
|
m.sound.play("thread")
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
|
|
|
m.board.pipes.pulse_key = key
|
|
|
|
|
m.board.pipes.pulse_t = 0.0
|
|
|
|
|
_pulse_tween = m.create_tween().set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN_OUT)
|
|
|
|
|
_pulse_tween.tween_property(m.board.pipes, "pulse_t", 1.0, clampf(length * 0.8, 260.0, 650.0) / 1000.0)
|
|
|
|
|
await _pulse_tween.finished
|
|
|
|
|
if m.board.pipes.pulse_key == key:
|
|
|
|
|
m.board.pipes.pulse_key = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Moves the current roll to the Earlier list (it's already in the saved history).
|
|
|
|
|
func _archive_current() -> void:
|
|
|
|
|
# A roll still waiting for an answer is cancelled, not kept.
|
|
|
|
|
if m.current.is_empty() or m.current.get("archived", false) or m.current.get("pending", false):
|
|
|
|
|
return
|
|
|
|
|
m.current["archived"] = true
|
|
|
|
|
var rec := m.current.duplicate()
|
|
|
|
|
rec["steps"] = m.current["all"]
|
|
|
|
|
m.history.push_front(rec)
|
|
|
|
|
if m.history.size() > Main.HISTORY_SIZE:
|
|
|
|
|
m.history.resize(Main.HISTORY_SIZE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
|
func _seed_session() -> void:
|
|
|
|
|
m.local_state.load_local_state()
|
|
|
|
|
if not m.current.is_empty():
|
|
|
|
|
_light_steps(m.current.get("all", []))
|
|
|
|
|
m._refresh_lit()
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
return
|
|
|
|
|
var now := Time.get_unix_time_from_system()
|
|
|
|
|
# Seeded rolls draw from scratch decks so they don't use up real cards.
|
|
|
|
|
var scratch := {}
|
|
|
|
|
for seed_roll in [["monsters", 9], ["loot", 4]]:
|
|
|
|
|
if m.data.get_table(seed_roll[0]):
|
|
|
|
|
var tree := Roller.roll(m.data, seed_roll[0], m.rng, 0, scratch)
|
|
|
|
|
var steps := Roller.flatten(tree, [])
|
|
|
|
|
m.history.push_front({"collection": m.data.id, "root": seed_roll[0], "root_name": m.data.get_table(seed_roll[0]).name,
|
|
|
|
|
"time": now - seed_roll[1] * 60, "steps": steps, "all": steps, "archived": true})
|
|
|
|
|
# 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 m.persistent_vars.is_empty():
|
|
|
|
|
var ctx := Roller.new_context(m.data, m.rng, m.persistent_vars, scratch)
|
|
|
|
|
for pair in [["@guide", "names"], ["@weather", "weather"]]:
|
|
|
|
|
if m.data.get_table(pair[1]):
|
|
|
|
|
var n := Roller.roll(m.data, pair[1], m.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])
|
|
|
|
|
var start := "wilderness" if m.data.get_table("wilderness") else _first_rollable()
|
|
|
|
|
if start == "":
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
return
|
|
|
|
|
var best: Dictionary
|
|
|
|
|
if m.data.get_table("trinkets"):
|
|
|
|
|
best = Roller.roll(m.data, start, m.rng, 0, scratch)
|
|
|
|
|
for i in 400:
|
|
|
|
|
if Roller.reaches(best, "trinkets"):
|
|
|
|
|
break
|
|
|
|
|
best = Roller.roll(m.data, start, m.rng, 0, scratch)
|
|
|
|
|
else:
|
|
|
|
|
# Any other board: one roll with the headless answers, through the real
|
|
|
|
|
# variables, so variable and sheet cards have values to show.
|
|
|
|
|
best = Roller.roll(m.data, start, m.rng, 0, scratch, Roller.new_context(m.data, m.rng, m.persistent_vars, scratch))
|
|
|
|
|
var all := Roller.flatten(best, [])
|
|
|
|
|
m.current = {"collection": m.data.id, "root": start, "root_name": m.data.get_table(start).name, "time": now - 60,
|
|
|
|
|
"steps": all, "all": all, "done": true, "chain_vars": {}}
|
|
|
|
|
Roller.collect_lit(best, m.lit_entries, m.lit_pipes, m.lit_texts)
|
|
|
|
|
m._refresh_lit()
|
|
|
|
|
m.refresh_live()
|
|
|
|
|
m.tray.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The first table that can start a roll (not a variable card), or "".
|
|
|
|
|
func _first_rollable() -> String:
|
|
|
|
|
for t in m.data.tables:
|
|
|
|
|
if t.kind != RollTable.KIND_VARIABLE:
|
|
|
|
|
return t.id
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 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"]))
|
|
|
|
|
m.lit_entries[ek] = true
|
|
|
|
|
m.lit_texts[ek] = str(s.get("text", ""))
|
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
|
|
|
TableCardColumns.note_lit(m, ek, s)
|
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -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"):
|
|
|
|
|
var p: Dictionary = stack[d - 1]
|
|
|
|
|
var ptid := str(p.get("table_id", ""))
|
|
|
|
|
var peid := str(p["entry_id"])
|
|
|
|
|
m.lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Copy -----
|
|
|
|
|
|
|
|
|
|
## Copies the current result: ResultTray.COPY_TEXT, COPY_BBCODE or COPY_DETAILS.
|
|
|
|
|
func copy_current(kind: int) -> void:
|
|
|
|
|
if m.current.is_empty():
|
|
|
|
|
return
|
|
|
|
|
var text := result_text(m.current.get("all", []), kind)
|
|
|
|
|
DisplayServer.clipboard_set(text)
|
|
|
|
|
m.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
|
|
|
|
|
# Long pipe chains nest thousands deep; cap the indent so the text stays usable.
|
|
|
|
|
var indent := " ".repeat(mini(int(s.get("depth", 0)), MAX_INDENT))
|
|
|
|
|
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 := m.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)
|