- A Sheet card can show a sheet file (sheet, prefix): first-tab preview, Open sheet with a way back, the spread's Play/Build in the editor. - Rolls read and write "Use in tables" boxes as @name or @prefix_name; locked boxes and formulas/lists keep their values; changed boxes glow. - A roll reaching the card shows the sheet's text (SheetText) in the tray; text boxes also show spread values when on the spread. - Old template Sheet cards migrate to a sheet with one text box (not in Help demos). Card palette lists your sheets. - Sheet canvas: tiled grid (smooth panning); boxes no longer overlap (nearest free spot, drags stop short; Alt places freely). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.6 KiB
GDScript
88 lines
2.6 KiB
GDScript
class_name DemoMode
|
|
extends RefCounted
|
|
## A demo spread from Help (DemoSpreads): shown in place of your spread,
|
|
## never saved and never listed. A bar above the spread offers Keep a copy
|
|
## (saves it as a spread of your own) and Back to my spread.
|
|
|
|
var m: Main
|
|
var _return_id := ""
|
|
var _was_saving := false
|
|
var _bar: PanelContainer
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
m = p_main
|
|
|
|
|
|
func active() -> bool:
|
|
return _bar != null and is_instance_valid(_bar)
|
|
|
|
|
|
func open(key: String) -> void:
|
|
if not DemoSpreads.has(key):
|
|
return
|
|
if not active():
|
|
m._save_now()
|
|
_return_id = m.data.id
|
|
_was_saving = m._saving_enabled
|
|
m._saving_enabled = false
|
|
# The bar first: while it shows, the demo counts as open (old Sheet cards
|
|
# in a demo aren't migrated to sheet files, MainSheetLinks.migrate).
|
|
_show_bar(str(DemoSpreads.TITLES[key]))
|
|
m.collections._show_collection(DemoSpreads.build(key))
|
|
|
|
|
|
func back() -> void:
|
|
_close_bar()
|
|
m._saving_enabled = _was_saving
|
|
var b: TowerBoard = null
|
|
if m.library and _return_id != "":
|
|
b = m.library.load_collection(_return_id)
|
|
if b == null:
|
|
b = SampleBoard.create()
|
|
b.id = "fantasy-loot"
|
|
b.name = "Fantasy Loot"
|
|
m.collections._show_collection(b)
|
|
|
|
|
|
## Saves the demo as a new spread of your own and leaves demo mode on it.
|
|
func keep_copy() -> void:
|
|
_close_bar()
|
|
m._saving_enabled = _was_saving
|
|
if m.library == null:
|
|
m.toast("Spreads can't be saved in this session")
|
|
return
|
|
var copy := TowerBoard.new()
|
|
copy.load_dict(m.data.to_dict())
|
|
copy.name = str(m.data.name).trim_prefix("Demo: ").capitalize()
|
|
copy.id = m.library.unique_id(LibraryStore.slugify(copy.name))
|
|
if m.library.save(copy):
|
|
m.collections._show_collection(copy)
|
|
m.toast("Saved “%s” as your own spread" % copy.name)
|
|
|
|
|
|
func _show_bar(title: String) -> void:
|
|
_close_bar()
|
|
_bar = PanelContainer.new()
|
|
_bar.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.BG_DEEP, 10, [14, 8, 10, 8]), 1, Style.ACCENT))
|
|
var h := HBoxContainer.new()
|
|
h.add_theme_constant_override("separation", 10)
|
|
_bar.add_child(h)
|
|
var l := Style.make_label("%s · try it out; nothing here is saved" % title, Style.body_bold(), 15, Style.ON_BG)
|
|
l.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
h.add_child(l)
|
|
var keep := Style.bar_button("Keep a copy")
|
|
keep.pressed.connect(keep_copy)
|
|
h.add_child(keep)
|
|
var back_b := Style.bar_button("Back to my spread", true)
|
|
back_b.pressed.connect(back)
|
|
h.add_child(back_b)
|
|
m.board.add_child(_bar)
|
|
# Along the bottom of the spread, clear of the cards at the top.
|
|
_bar.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_LEFT, Control.PRESET_MODE_MINSIZE, 14)
|
|
|
|
|
|
func _close_bar() -> void:
|
|
if active():
|
|
_bar.queue_free()
|
|
_bar = null
|