Cards can cost to roll; pauses animate up to themselves and pop up
- Costs to roll on any card: its roll button greys out (with the reason) when there isn't enough, and pressing it pays. A thread that reaches it asks first (Pay / Don't pay), reusing the pause question. - A pause now plays the roll so far (dice, lights, threads), then pops up Continue / Stop here / Later (the tray strip stays). After Continue the rest animates instead of showing at once. Shift-click still skips it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3f13bc181c
commit
983d2bd839
13 changed files with 211 additions and 45 deletions
|
|
@ -1,30 +1,31 @@
|
||||||
class_name RollCosts
|
class_name RollCosts
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## Costs on choice options: an option can cost an amount of a value
|
## Costs: a choice option (TableEntry) or a whole card (RollTable) can cost an
|
||||||
## (TableEntry.cost_value, cost_amount). It's offered greyed out, with the
|
## amount of a value (cost_value, cost_amount). An option is offered greyed
|
||||||
## reason, when the value is too low; picking it takes the amount away.
|
## out, with the reason, when the value is too low; picking it takes the
|
||||||
## A "Reroll?" option that pipes back to a card and costs a point makes a
|
## amount away. A "Reroll?" option that pipes back to a card and costs a point
|
||||||
## spend-a-point-to-reroll table.
|
## makes a spend-a-point-to-reroll table. A card with a cost can't be rolled
|
||||||
|
## without it; a thread that reaches it asks first (card_gate).
|
||||||
|
|
||||||
|
|
||||||
## "" when the option can be afforded now, else why not (shown to the player).
|
## "" when the option can be afforded now, else why not (shown to the player).
|
||||||
static func blocked(e: TableEntry, ctx: RollContext, board: TowerBoard = null) -> String:
|
static func blocked(e: Object, ctx: RollContext, board: TowerBoard = null) -> String:
|
||||||
if not has_cost(e):
|
if not has_cost(e):
|
||||||
return ""
|
return ""
|
||||||
var have := _number(Expr.evaluate(var_ref(e), ctx))
|
var have := _number(Expr.evaluate(var_ref(e), ctx))
|
||||||
var need := _number(Expr.evaluate(e.cost_amount, ctx))
|
var need := _number(Expr.evaluate(str(e.get("cost_amount")), ctx))
|
||||||
if have >= need:
|
if have >= need:
|
||||||
return ""
|
return ""
|
||||||
return "Needs %s %s (you have %s)" % [Expr.format_value(need), label(e, board), Expr.format_value(have)]
|
return "Needs %s %s (you have %s)" % [Expr.format_value(need), label(e, board), Expr.format_value(have)]
|
||||||
|
|
||||||
|
|
||||||
static func has_cost(e: TableEntry) -> bool:
|
static func has_cost(e: Object) -> bool:
|
||||||
return e.cost_value.strip_edges() != "" and e.cost_amount.strip_edges() != ""
|
return str(e.get("cost_value")).strip_edges() != "" and str(e.get("cost_amount")).strip_edges() != ""
|
||||||
|
|
||||||
|
|
||||||
## "Costs 1 Luck".
|
## "Costs 1 Luck".
|
||||||
static func describe(e: TableEntry, board: TowerBoard = null) -> String:
|
static func describe(e: Object, board: TowerBoard = null) -> String:
|
||||||
return "Costs %s %s" % [e.cost_amount.strip_edges(), label(e, board)] if has_cost(e) else ""
|
return "Costs %s %s" % [str(e.get("cost_amount")).strip_edges(), label(e, board)] if has_cost(e) else ""
|
||||||
|
|
||||||
|
|
||||||
## Takes the cost away (an ordinary change, so it shows in the result's
|
## Takes the cost away (an ordinary change, so it shows in the result's
|
||||||
|
|
@ -37,12 +38,47 @@ static func pay(e: TableEntry, ctx: RollContext, t: RollTable, node: Dictionary)
|
||||||
Roller._why(node, facts)
|
Roller._why(node, facts)
|
||||||
|
|
||||||
|
|
||||||
static func var_ref(e: TableEntry) -> String:
|
## A card's cost before it rolls. A roll that starts on the card (its
|
||||||
var v := e.cost_value.strip_edges()
|
## button) pays when it can, else stops with the reason. A thread that reaches
|
||||||
return v if v.begins_with("@") else "@" + v
|
## it asks the player first (a "pause" question: Continue pays). Returns false
|
||||||
|
## when the card doesn't roll; then a stop node says why. Payment shows as a
|
||||||
|
## change on the card's result (frame "pre_why").
|
||||||
|
static func card_gate(board: TowerBoard, t: RollTable, f: Dictionary, ctx: RollContext) -> bool:
|
||||||
|
if not has_cost(t):
|
||||||
|
return true
|
||||||
|
var reason := blocked(t, ctx, board)
|
||||||
|
var cost := describe(t, board).to_lower()
|
||||||
|
if not f.get("top", false):
|
||||||
|
if reason != "":
|
||||||
|
Roller._attach(f, Roller._stop(t, "Not rolled: %s" % reason.to_lower()), ctx)
|
||||||
|
return false
|
||||||
|
var request := {"kind": "pause", "table_id": t.id, "title": t.name, "cost": cost,
|
||||||
|
"prompt": "Pay %s to roll %s?" % [cost.trim_prefix("costs "), Formatter.strip_tags(t.name)],
|
||||||
|
"from": Formatter.strip_tags(t.name)}
|
||||||
|
var reply: Variant = await RollChoice.ask(ctx, request)
|
||||||
|
if reply != true:
|
||||||
|
Roller._attach(f, Roller._stop(t, "Not rolled: you didn't pay"), ctx)
|
||||||
|
return false
|
||||||
|
elif reason != "":
|
||||||
|
Roller._attach(f, Roller._stop(t, "Can't roll: %s" % reason.to_lower()), ctx)
|
||||||
|
return false
|
||||||
|
var facts: Array = []
|
||||||
|
var lines := Effects.run("%s -= %s" % [var_ref(t), t.cost_amount.strip_edges()], ctx, t.id, facts)
|
||||||
|
var pre_why: Array = f.get("pre_why", [])
|
||||||
|
pre_why.append_array(facts)
|
||||||
|
f["pre_why"] = pre_why
|
||||||
|
var pre_log: Array = f.get("pre_log", [])
|
||||||
|
pre_log.append_array(lines)
|
||||||
|
f["pre_log"] = pre_log
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
static func label(e: TableEntry, board: TowerBoard) -> String:
|
static func var_ref(e: Object) -> String:
|
||||||
|
var value_name := str(e.get("cost_value")).strip_edges()
|
||||||
|
return value_name if value_name.begins_with("@") else "@" + value_name
|
||||||
|
|
||||||
|
|
||||||
|
static func label(e: Object, board: TowerBoard) -> String:
|
||||||
return Describe.label(var_ref(e).trim_prefix("@"), board) if board else var_ref(e).trim_prefix("@")
|
return Describe.label(var_ref(e).trim_prefix("@"), board) if board else var_ref(e).trim_prefix("@")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@ static func attach(frame: Dictionary, node: Dictionary, ctx: RollContext) -> voi
|
||||||
node["save_as"] = frame["save"]
|
node["save_as"] = frame["save"]
|
||||||
if frame.has("inputs"):
|
if frame.has("inputs"):
|
||||||
node["inputs"] = frame["inputs"]
|
node["inputs"] = frame["inputs"]
|
||||||
var facts: Array = frame["pre_why"]
|
# Facts from before the pick (inputs, a paid cost) come first.
|
||||||
|
if frame.has("pre_why"):
|
||||||
|
var facts: Array = (frame["pre_why"] as Array).duplicate()
|
||||||
if node.has("why"):
|
if node.has("why"):
|
||||||
facts.append_array(node["why"])
|
facts.append_array(node["why"])
|
||||||
node["why"] = facts
|
node["why"] = facts
|
||||||
add_log(node, frame["pre_log"])
|
add_log(node, frame.get("pre_log", []))
|
||||||
(frame["parent"]["children"] as Array).append(node)
|
(frame["parent"]["children"] as Array).append(node)
|
||||||
if frame.get("top", false):
|
if frame.get("top", false):
|
||||||
ctx.root = node
|
ctx.root = node
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,10 @@ var var_type: String = "number"
|
||||||
var initial: String = ""
|
var initial: String = ""
|
||||||
## Scale variables: the ordered steps, lowest first.
|
## Scale variables: the ordered steps, lowest first.
|
||||||
var steps: Array[String] = []
|
var steps: Array[String] = []
|
||||||
|
## A cost to roll this card (RollCosts): the value ("@luck") and the amount
|
||||||
|
## taken away each time. Empty = free.
|
||||||
|
var cost_value: String = ""
|
||||||
|
var cost_amount: String = ""
|
||||||
## List cards: true when the list keeps repeats (an item added every time, in
|
## List cards: true when the list keeps repeats (an item added every time, in
|
||||||
## order); false adds an item only if it isn't there yet.
|
## order); false adds an item only if it isn't there yet.
|
||||||
var list_repeats := false
|
var list_repeats := false
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ static func to_dict(t: RollTable) -> Dictionary:
|
||||||
d["tags"] = t.tags.duplicate()
|
d["tags"] = t.tags.duplicate()
|
||||||
if t.color != "":
|
if t.color != "":
|
||||||
d["color"] = t.color
|
d["color"] = t.color
|
||||||
|
if t.cost_value.strip_edges() != "" and t.cost_amount.strip_edges() != "":
|
||||||
|
d["cost"] = {"value": t.cost_value.strip_edges(), "amount": t.cost_amount.strip_edges()}
|
||||||
if t.roll_floor.strip_edges() != "":
|
if t.roll_floor.strip_edges() != "":
|
||||||
d["roll_floor"] = t.roll_floor.strip_edges()
|
d["roll_floor"] = t.roll_floor.strip_edges()
|
||||||
if t.roll_ceiling.strip_edges() != "":
|
if t.roll_ceiling.strip_edges() != "":
|
||||||
|
|
@ -141,6 +143,10 @@ static func from_dict(d: Dictionary) -> RollTable:
|
||||||
t.steps = Scales.clean(d.get("steps", []))
|
t.steps = Scales.clean(d.get("steps", []))
|
||||||
t.members = LedgerMembers.clean(d.get("members", []))
|
t.members = LedgerMembers.clean(d.get("members", []))
|
||||||
t.list_repeats = bool(d.get("repeats", false))
|
t.list_repeats = bool(d.get("repeats", false))
|
||||||
|
var cost: Variant = d.get("cost")
|
||||||
|
if cost is Dictionary:
|
||||||
|
t.cost_value = str(cost.get("value", ""))
|
||||||
|
t.cost_amount = str(cost.get("amount", ""))
|
||||||
t.check_dice = RollTable.expr_text(d.get("check_dice", RollTable.CHECK_DEFAULT_DICE), RollTable.CHECK_DEFAULT_DICE).strip_edges()
|
t.check_dice = RollTable.expr_text(d.get("check_dice", RollTable.CHECK_DEFAULT_DICE), RollTable.CHECK_DEFAULT_DICE).strip_edges()
|
||||||
if t.check_dice == "":
|
if t.check_dice == "":
|
||||||
t.check_dice = RollTable.CHECK_DEFAULT_DICE
|
t.check_dice = RollTable.CHECK_DEFAULT_DICE
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,8 @@ static func _do_roll(board: TowerBoard, f: Dictionary, ctx: RollContext, stack:
|
||||||
if not _take_action(f, t, ctx):
|
if not _take_action(f, t, ctx):
|
||||||
return
|
return
|
||||||
RollPipes.bind_inputs(t, f, ctx, stack)
|
RollPipes.bind_inputs(t, f, ctx, stack)
|
||||||
|
if not await RollCosts.card_gate(board, t, f, ctx):
|
||||||
|
return
|
||||||
if t.entries.is_empty():
|
if t.entries.is_empty():
|
||||||
_attach(f, _stop(t, "This table has no results"), ctx)
|
_attach(f, _stop(t, "This table has no results"), ctx)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -233,11 +233,12 @@ The [b]Book[/b] holds [b]Pages[/b]: results you want to use on more than one tab
|
||||||
[demo]repeats[/demo]
|
[demo]repeats[/demo]
|
||||||
|
|
||||||
# Pausing a roll
|
# Pausing a roll
|
||||||
Tick [b]Wait for me first[/b] on a thread and the roll stops there, with [b]Continue ▸[/b] and [b]Stop here[/b] in the tray. Use it to reveal something a piece at a time. If you roll something else meanwhile, the paused roll waits in the tray until you continue it.
|
Tick [b]Wait for me first[/b] on a thread and the roll stops there. The roll so far plays out first, then a pop-up asks [b]Continue ▸[/b], [b]Stop here[/b] or [b]Later[/b] (the same buttons wait in the tray). After Continue the rest of the roll plays out too. Use it to reveal something a piece at a time. If you roll something else meanwhile, the paused roll waits in the tray until you continue it.
|
||||||
[demo]pause[/demo]
|
[demo]pause[/demo]
|
||||||
|
|
||||||
# Options that cost
|
# Options that cost
|
||||||
An option on a [b]Which option[/b] card can cost something: in its inspector, [b]Costs [1] of [Points][/b]. Picking it takes that away; when there isn't enough, the option is greyed out and says why. An option such as [b]Reroll[/b] that threads back to the loot card and costs a point gives players a spend-a-point reroll.
|
An option on a [b]Which option[/b] card can cost something: in its inspector, [b]Costs [1] of [Points][/b]. Picking it takes that away; when there isn't enough, the option is greyed out and says why. An option such as [b]Reroll[/b] that threads back to the loot card and costs a point gives players a spend-a-point reroll.
|
||||||
|
- A whole card can cost something too: [b]Costs to roll[/b] in the card's inspector. Its roll button is greyed out when there isn't enough, and pressing it pays. When a thread reaches the card, the roll asks first: [b]Pay ▸[/b] rolls it, [b]Don't pay[/b] skips it.
|
||||||
[demo]costs[/demo]
|
[demo]costs[/demo]
|
||||||
|
|
||||||
# One table adjusting another
|
# One table adjusting another
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ func _init() -> void:
|
||||||
await _test_choose()
|
await _test_choose()
|
||||||
await _test_pause()
|
await _test_pause()
|
||||||
await _test_costs()
|
await _test_costs()
|
||||||
|
await _test_card_costs()
|
||||||
_test_limits()
|
_test_limits()
|
||||||
finish()
|
finish()
|
||||||
|
|
||||||
|
|
@ -136,6 +137,34 @@ func _test_pause() -> void:
|
||||||
_check(back.pipe_pause.has("gold"), "the pause is saved")
|
_check(back.pipe_pause.has("gold"), "the pause is saved")
|
||||||
|
|
||||||
|
|
||||||
|
## A card that costs 1 point to roll: its own roll pays or stops; a thread
|
||||||
|
## that reaches it asks first (Continue pays, Stop skips it).
|
||||||
|
func _test_card_costs() -> void:
|
||||||
|
var b := _board("all")
|
||||||
|
var gold := b.get_table("gold")
|
||||||
|
gold.cost_value = "@points"
|
||||||
|
gold.cost_amount = "1"
|
||||||
|
var ctx := Roller.new_context(b, RandomNumberGenerator.new(), {"points": {"value": 2}})
|
||||||
|
var tree: Dictionary = await Roller.roll_async(b, "gold", ctx)
|
||||||
|
_check(not tree.has("stop") and int(ctx.lookup("@points")) == 1, "rolling the card itself pays its cost")
|
||||||
|
_check((tree.get("why", []) as Array).any(func(f: Dictionary) -> bool: return f.get("type") == "effect"), "the payment shows in Why this?")
|
||||||
|
ctx = Roller.new_context(b, RandomNumberGenerator.new(), {"points": {"value": 0}})
|
||||||
|
tree = await Roller.roll_async(b, "gold", ctx)
|
||||||
|
_check(str(tree.get("stop", "")).begins_with("Can't roll"), "with nothing to pay it doesn't roll: %s" % tree.get("stop", ""))
|
||||||
|
var asked: Array = []
|
||||||
|
ctx = Roller.new_context(b, RandomNumberGenerator.new(), {"points": {"value": 5}})
|
||||||
|
ctx.prompt = func(req: Dictionary) -> Variant:
|
||||||
|
asked.append(req)
|
||||||
|
return asked.size() == 1
|
||||||
|
tree = await Roller.roll_async(b, "start", ctx)
|
||||||
|
_check(asked.size() == 3 and str(asked[0].get("cost", "")) != "", "a thread into it asks before each roll")
|
||||||
|
var golds := _kids(tree, "gold")
|
||||||
|
_check(golds.size() == 3 and not golds[0].has("stop") and golds[1].has("stop"), "Continue pays and rolls; not paying skips it")
|
||||||
|
_check(int(ctx.lookup("@points")) == 4, "only the paid roll took a point")
|
||||||
|
var back := RollTable.from_dict(gold.to_dict())
|
||||||
|
_check(back.cost_value == "@points" and back.cost_amount == "1", "the card's cost is saved")
|
||||||
|
|
||||||
|
|
||||||
## A pick card whose "Reroll" option costs 1 point.
|
## A pick card whose "Reroll" option costs 1 point.
|
||||||
func _test_costs() -> void:
|
func _test_costs() -> void:
|
||||||
var b := TowerBoard.new()
|
var b := TowerBoard.new()
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
|
||||||
insp.wrote(t))))
|
insp.wrote(t))))
|
||||||
|
|
||||||
if t.kind != RollTable.KIND_VARIABLE:
|
if t.kind != RollTable.KIND_VARIABLE:
|
||||||
|
box.add_child(InspectorKit.field("Costs to roll", InspectorResult.cost_row(insp, t, t,
|
||||||
|
"Its roll button is greyed out when there isn't enough; a thread that reaches it asks first.")))
|
||||||
box.add_child(_inputs(insp, t))
|
box.add_child(_inputs(insp, t))
|
||||||
InspectorThreads.build(insp, box, t)
|
InspectorThreads.build(insp, box, t)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,27 +28,29 @@ static func book_line(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||||
|
|
||||||
|
|
||||||
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
|
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
|
||||||
static func cost_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
## "Costs [1] of [value]": for a choice option (`holder` a TableEntry) or a
|
||||||
|
## whole card (`holder` the RollTable). `note` sits under it.
|
||||||
|
static func cost_row(insp: Inspector, t: RollTable, holder: Object, note: String = "Greyed out in the pop-up when there isn't enough.") -> Control:
|
||||||
var row := InspectorKit.flow()
|
var row := InspectorKit.flow()
|
||||||
var amount := InspectorKit.amount(e.cost_amount, "0")
|
var amount := InspectorKit.amount(str(holder.get("cost_amount")), "0")
|
||||||
amount.tooltip_text = "How much picking this takes away (0 or empty: free)"
|
amount.tooltip_text = "How much it takes away (0 or empty: free)"
|
||||||
row.add_child(amount)
|
row.add_child(amount)
|
||||||
row.add_child(InspectorKit.word("of"))
|
row.add_child(InspectorKit.word("of"))
|
||||||
var picker := ValuePicker.new(insp.main, e.cost_value.trim_prefix("@"))
|
var picker := ValuePicker.new(insp.main, str(holder.get("cost_value")).trim_prefix("@"))
|
||||||
row.add_child(picker)
|
row.add_child(picker)
|
||||||
var apply := func() -> void:
|
var apply := func() -> void:
|
||||||
var a := amount.text.strip_edges()
|
var typed := amount.text.strip_edges()
|
||||||
e.cost_amount = "" if a == "" or a == "0" else a
|
holder.set("cost_amount", "" if typed == "" or typed == "0" else typed)
|
||||||
if e.cost_amount == "":
|
if str(holder.get("cost_amount")) == "":
|
||||||
e.cost_value = ""
|
holder.set("cost_value", "")
|
||||||
insp.wrote(t)
|
insp.wrote(t)
|
||||||
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
||||||
picker.value_chosen.connect(func(n: String) -> void:
|
picker.value_chosen.connect(func(n: String) -> void:
|
||||||
e.cost_value = "@" + n.trim_prefix("@")
|
holder.set("cost_value", "@" + n.trim_prefix("@"))
|
||||||
if amount.text.strip_edges() == "":
|
if amount.text.strip_edges() == "":
|
||||||
amount.text = "1"
|
amount.text = "1"
|
||||||
apply.call())
|
apply.call())
|
||||||
row.add_child(InspectorKit.note("Greyed out in the pop-up when there isn't enough.", Style.MUTED, 12))
|
row.add_child(InspectorKit.note(note, Style.MUTED, 12))
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ var m: Main
|
||||||
|
|
||||||
var _token := 0
|
var _token := 0
|
||||||
var _pulse_tween: Tween
|
var _pulse_tween: Tween
|
||||||
|
## True when _play_one lit nodes again (after a pause) without redrawing yet.
|
||||||
|
var _relit := false
|
||||||
var _choice: ChoiceDialog
|
var _choice: ChoiceDialog
|
||||||
## Rolls waiting at a paused thread.
|
## Rolls waiting at a paused thread.
|
||||||
var pauses: RollPauses
|
var pauses: RollPauses
|
||||||
|
|
@ -51,7 +53,7 @@ func start_roll(tid: String, fast: bool = false) -> void:
|
||||||
m.sound.play("roll")
|
m.sound.play("roll")
|
||||||
# The roll's token lives in a holder, so a paused roll set aside can be
|
# The roll's token lives in a holder, so a paused roll set aside can be
|
||||||
# made current again (RollPauses.answer).
|
# made current again (RollPauses.answer).
|
||||||
var run := {"token": _token}
|
var run := {"token": _token, "fast": fast}
|
||||||
# A question left open by the previous roll answers Cancel; that roll then
|
# A question left open by the previous roll answers Cancel; that roll then
|
||||||
# sees it has been replaced and stops quietly.
|
# sees it has been replaced and stops quietly.
|
||||||
cancel_choice()
|
cancel_choice()
|
||||||
|
|
@ -76,7 +78,9 @@ func start_roll(tid: String, fast: bool = false) -> void:
|
||||||
if ctx.persistent_changed:
|
if ctx.persistent_changed:
|
||||||
m.local_state._store_variables()
|
m.local_state._store_variables()
|
||||||
return
|
return
|
||||||
var prompted: bool = m.current.get("prompted", false)
|
# Questions light the roll so far at once, so the rest shows at once too;
|
||||||
|
# a pause (or a cost) animates up to itself and the rest animates after.
|
||||||
|
var prompted: bool = run.get("other_prompt", false)
|
||||||
m.lit_entries.clear()
|
m.lit_entries.clear()
|
||||||
m.lit_pipes.clear()
|
m.lit_pipes.clear()
|
||||||
m.lit_texts.clear()
|
m.lit_texts.clear()
|
||||||
|
|
@ -111,11 +115,27 @@ func _prompt_for(req: Dictionary, run: Dictionary) -> Variant:
|
||||||
return null
|
return null
|
||||||
m.current["prompted"] = true
|
m.current["prompted"] = true
|
||||||
m.current["asking"] = Formatter.strip_tags(str(req.get("title", "")))
|
m.current["asking"] = Formatter.strip_tags(str(req.get("title", "")))
|
||||||
show_progress()
|
|
||||||
var reply: Variant
|
var reply: Variant
|
||||||
if str(req.get("kind", "")) == "pause":
|
if str(req.get("kind", "")) == "pause":
|
||||||
|
if run.get("fast", false) or m.rolling_ctx == null:
|
||||||
|
show_progress()
|
||||||
|
else:
|
||||||
|
# The roll so far animates (dice, lights, threads), then it waits.
|
||||||
|
# Steps shown before an earlier pause are listed again as they replay,
|
||||||
|
# and the previous roll's lights go out first.
|
||||||
|
m.current["steps"] = []
|
||||||
|
m.lit_entries.clear()
|
||||||
|
m.lit_pipes.clear()
|
||||||
|
m.lit_texts.clear()
|
||||||
|
m.lit_columns.clear()
|
||||||
|
m._refresh_lit()
|
||||||
|
await _play_node(m.rolling_ctx.root, int(run["token"]))
|
||||||
|
if int(run["token"]) != _token:
|
||||||
|
return null
|
||||||
reply = await pauses.wait(req, run)
|
reply = await pauses.wait(req, run)
|
||||||
else:
|
else:
|
||||||
|
run["other_prompt"] = true
|
||||||
|
show_progress()
|
||||||
reply = await m.prompt_hook.call(req)
|
reply = await m.prompt_hook.call(req)
|
||||||
if int(run["token"]) != _token:
|
if int(run["token"]) != _token:
|
||||||
return null
|
return null
|
||||||
|
|
@ -189,8 +209,15 @@ func _play_node(root_node: Dictionary, my: int) -> void:
|
||||||
if my != _token or n.is_empty():
|
if my != _token or n.is_empty():
|
||||||
return
|
return
|
||||||
var key: String = top[2]
|
var key: String = top[2]
|
||||||
|
var replay: bool = n.get("animated", false)
|
||||||
|
if not replay and _relit:
|
||||||
|
# Nodes shown before a pause were lit without redrawing; do it once.
|
||||||
|
_relit = false
|
||||||
|
m._refresh_lit()
|
||||||
|
m.tray.render()
|
||||||
if key != "":
|
if key != "":
|
||||||
m.lit_pipes[key] = true
|
m.lit_pipes[key] = true
|
||||||
|
if not replay:
|
||||||
await _pulse(key, my)
|
await _pulse(key, my)
|
||||||
if my != _token:
|
if my != _token:
|
||||||
return
|
return
|
||||||
|
|
@ -206,14 +233,21 @@ func _play_node(root_node: Dictionary, my: int) -> void:
|
||||||
var c: Dictionary = kids[k]
|
var c: Dictionary = kids[k]
|
||||||
var ck := "" if (c.has("pass") or c.has("after")) else Roller.link_key(tid, eid, c)
|
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])
|
stack.append([c, int(top[1]) + 1, ck])
|
||||||
|
if _relit:
|
||||||
|
_relit = false
|
||||||
|
m._refresh_lit()
|
||||||
|
m.tray.render()
|
||||||
|
|
||||||
|
|
||||||
## Animates one node: the card tumbles (plain rolls only), then the result lights.
|
## Animates one node: the card tumbles (plain rolls only), then the result
|
||||||
|
## lights. A node already animated (before a pause) only lights again, at once.
|
||||||
func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
||||||
var t: RollTable = n["table"]
|
var t: RollTable = n["table"]
|
||||||
var stopped := n.has("stop")
|
var stopped := n.has("stop")
|
||||||
var card := m.card_for(t.id)
|
var card := m.card_for(t.id)
|
||||||
var tumble: bool = not n.has("kind") or bool(n.get("random", false))
|
var replay: bool = n.get("animated", false)
|
||||||
|
n["animated"] = true
|
||||||
|
var tumble: bool = (not n.has("kind") or bool(n.get("random", false))) and not replay
|
||||||
# A table hidden in a collapsed group rolls on the group's card.
|
# A table hidden in a collapsed group rolls on the group's card.
|
||||||
var gcard: GroupCard = m.hidden_groups().get(t.id)
|
var gcard: GroupCard = m.hidden_groups().get(t.id)
|
||||||
if not stopped and gcard and tumble:
|
if not stopped and gcard and tumble:
|
||||||
|
|
@ -248,11 +282,15 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
||||||
m.lit_texts[ek] = str(n.get("summary", e.text))
|
m.lit_texts[ek] = str(n.get("summary", e.text))
|
||||||
TableCardColumns.note_lit(m, ek, n)
|
TableCardColumns.note_lit(m, ek, n)
|
||||||
deck_reveal.release(t.id, e.id)
|
deck_reveal.release(t.id, e.id)
|
||||||
|
if replay:
|
||||||
|
_relit = true
|
||||||
|
else:
|
||||||
m._refresh_lit()
|
m._refresh_lit()
|
||||||
if card:
|
if card and not replay:
|
||||||
card.reveal(e.id)
|
card.reveal(e.id)
|
||||||
card.sparkle(e.id)
|
card.sparkle(e.id)
|
||||||
(m.current["steps"] as Array).append(Roller.step_of(n, depth))
|
(m.current["steps"] as Array).append(Roller.step_of(n, depth))
|
||||||
|
if not replay:
|
||||||
m.tray.render()
|
m.tray.render()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,43 @@ func _init(p_main: Main) -> void:
|
||||||
## The prompt hook's answer to a "pause" request for roll `run`.
|
## The prompt hook's answer to a "pause" request for roll `run`.
|
||||||
func wait(req: Dictionary, run: Dictionary) -> Variant:
|
func wait(req: Dictionary, run: Dictionary) -> Variant:
|
||||||
var w := Waiter.new()
|
var w := Waiter.new()
|
||||||
|
var cost := str(req.get("cost", ""))
|
||||||
var label := "%s: before %s" % [Formatter.strip_tags(str(m.current.get("root_name", ""))), Formatter.strip_tags(str(req.get("title", "")))]
|
var label := "%s: before %s" % [Formatter.strip_tags(str(m.current.get("root_name", ""))), Formatter.strip_tags(str(req.get("title", "")))]
|
||||||
waiting.append({"run": run, "waiter": w, "label": label, "current": m.current, "ctx": m.rolling_ctx})
|
if cost != "":
|
||||||
|
label = str(req.get("prompt", label))
|
||||||
|
var item := {"run": run, "waiter": w, "label": label, "current": m.current, "ctx": m.rolling_ctx, "cost": cost != ""}
|
||||||
|
waiting.append(item)
|
||||||
m.tray.render()
|
m.tray.render()
|
||||||
|
item["dialog"] = _popup(item)
|
||||||
var reply: Variant = await w.done
|
var reply: Variant = await w.done
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
|
|
||||||
|
## The pop-up for a waiting roll: Continue / Stop here (Pay / Don't pay for a
|
||||||
|
## cost), or Later, which leaves it waiting in the tray's strip.
|
||||||
|
func _popup(item: Dictionary) -> ModalCard:
|
||||||
|
var dialog := ModalCard.new("Pay to roll?" if item["cost"] else "Paused", 420.0)
|
||||||
|
dialog.body.add_child(ModalCard.note(str(item["label"]) if item["cost"] else "The roll is waiting %s." % str(item["label"]).get_slice(": ", 1), Style.INK))
|
||||||
|
var reply := func(go_on: bool) -> void:
|
||||||
|
var at := waiting.find(item)
|
||||||
|
if at >= 0:
|
||||||
|
answer(at, go_on)
|
||||||
|
dialog.add_button("Later", "plain", dialog.close)
|
||||||
|
dialog.add_button("Don't pay" if item["cost"] else "Stop here", "plain", reply.bind(false))
|
||||||
|
dialog.add_button("Pay ▸" if item["cost"] else "Continue ▸", "primary", reply.bind(true))
|
||||||
|
m._add_modal(dialog)
|
||||||
|
return dialog
|
||||||
|
|
||||||
|
|
||||||
## Continue (true) or Stop here (false) for the paused roll at `i`.
|
## Continue (true) or Stop here (false) for the paused roll at `i`.
|
||||||
func answer(i: int, go_on: bool) -> void:
|
func answer(i: int, go_on: bool) -> void:
|
||||||
if i < 0 or i >= waiting.size():
|
if i < 0 or i >= waiting.size():
|
||||||
return
|
return
|
||||||
var it: Dictionary = waiting[i]
|
var it: Dictionary = waiting[i]
|
||||||
waiting.remove_at(i)
|
waiting.remove_at(i)
|
||||||
|
var dialog: ModalCard = it.get("dialog")
|
||||||
|
if dialog and is_instance_valid(dialog) and dialog.is_inside_tree():
|
||||||
|
dialog.close()
|
||||||
var run: Dictionary = it["run"]
|
var run: Dictionary = it["run"]
|
||||||
if int(run["token"]) != m.rolling._token:
|
if int(run["token"]) != m.rolling._token:
|
||||||
# A set-aside roll: it becomes the current roll again.
|
# A set-aside roll: it becomes the current roll again.
|
||||||
|
|
@ -62,11 +86,12 @@ func make_strip() -> Control:
|
||||||
var l := Style.make_label("⏸ " + str(waiting[i]["label"]), Style.body_bold(), 14, Style.ACCENT)
|
var l := Style.make_label("⏸ " + str(waiting[i]["label"]), Style.body_bold(), 14, Style.ACCENT)
|
||||||
l.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
l.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||||
row.add_child(l)
|
row.add_child(l)
|
||||||
var go := Style.bar_button("Continue ▸", true)
|
var is_cost: bool = waiting[i].get("cost", false)
|
||||||
|
var go := Style.bar_button("Pay ▸" if is_cost else "Continue ▸", true)
|
||||||
go.pressed.connect(answer.bind(i, true))
|
go.pressed.connect(answer.bind(i, true))
|
||||||
row.add_child(go)
|
row.add_child(go)
|
||||||
var stop := Style.bar_button("Stop here")
|
var stop := Style.bar_button("Don't pay" if is_cost else "Stop here")
|
||||||
stop.tooltip_text = "End this roll here; what it rolled so far stays"
|
stop.tooltip_text = "Skip this card; what the roll gave so far stays" if is_cost else "End this roll here; what it rolled so far stays"
|
||||||
stop.pressed.connect(answer.bind(i, false))
|
stop.pressed.connect(answer.bind(i, false))
|
||||||
row.add_child(stop)
|
row.add_child(stop)
|
||||||
v.add_child(row)
|
v.add_child(row)
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,29 @@ func _make_kind_header(_build: bool) -> Control:
|
||||||
|
|
||||||
## Re-renders the header's live labels: a dynamic pick's available count and a
|
## Re-renders the header's live labels: a dynamic pick's available count and a
|
||||||
## choice's question.
|
## choice's question.
|
||||||
|
## Greys out the roll button while the card can't roll: a range runs
|
||||||
|
## backwards, or it costs more than the value has (the tooltip says why).
|
||||||
|
func sync_roll_button() -> void:
|
||||||
|
if not is_instance_valid(roll_button):
|
||||||
|
return
|
||||||
|
var table := card.table
|
||||||
|
var reason := "a range runs backwards" if RollRange.backwards(table) != "" else ""
|
||||||
|
if reason == "" and RollCosts.has_cost(table):
|
||||||
|
reason = RollCosts.blocked(table, Roller.live_context(card.main.data, card.main.persistent_vars), card.main.data)
|
||||||
|
roll_button.disabled = reason != ""
|
||||||
|
roll_button.modulate.a = 0.4 if reason != "" else 1.0
|
||||||
|
if not roll_button.has_meta("base_tip"):
|
||||||
|
roll_button.set_meta("base_tip", roll_button.tooltip_text)
|
||||||
|
var tip := str(roll_button.get_meta("base_tip"))
|
||||||
|
if RollCosts.has_cost(table):
|
||||||
|
tip += "\n" + RollCosts.describe(table, card.main.data)
|
||||||
|
if reason != "":
|
||||||
|
tip += "\nCan't roll: " + reason
|
||||||
|
roll_button.tooltip_text = tip
|
||||||
|
|
||||||
|
|
||||||
func refresh_live() -> void:
|
func refresh_live() -> void:
|
||||||
|
sync_roll_button()
|
||||||
var table := card.table
|
var table := card.table
|
||||||
var main := card.main
|
var main := card.main
|
||||||
if is_instance_valid(options_label):
|
if is_instance_valid(options_label):
|
||||||
|
|
|
||||||
|
|
@ -67,10 +67,7 @@ func update_warning() -> void:
|
||||||
problems = ("%s\n" % problems if problems != "" else "") + "\n".join(lines)
|
problems = ("%s\n" % problems if problems != "" else "") + "\n".join(lines)
|
||||||
card._warn_label.text = problems
|
card._warn_label.text = problems
|
||||||
card._warn_panel.visible = problems != ""
|
card._warn_panel.visible = problems != ""
|
||||||
if is_instance_valid(card.header_ui.roll_button):
|
card.header_ui.sync_roll_button()
|
||||||
var back := RollRange.backwards(card.table) != ""
|
|
||||||
card.header_ui.roll_button.disabled = back
|
|
||||||
card.header_ui.roll_button.modulate.a = 0.4 if back else 1.0
|
|
||||||
|
|
||||||
|
|
||||||
func skin_scrollbar(bar: VScrollBar) -> void:
|
func skin_scrollbar(bar: VScrollBar) -> void:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue