Roll again and combine can apply to chosen columns only
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3aeb98c2fd
commit
9d550408d8
5 changed files with 66 additions and 3 deletions
|
|
@ -11,7 +11,8 @@ extends RefCounted
|
|||
## happen as usual.
|
||||
##
|
||||
## A "roll twice and combine" row (TableEntry.repeat) that comes up in a
|
||||
## column rolls that column again `count` times and combines the texts with
|
||||
## column it applies to (repeat "columns": indices; none listed = every
|
||||
## column) rolls that column again `count` times and combines the texts with
|
||||
## REPEAT_JOIN ("Ash & Black"); a repeat row that comes up on those rolls adds
|
||||
## its own count (so "roll twice" again means one more), up to MAX_REPEATS.
|
||||
##
|
||||
|
|
@ -59,7 +60,7 @@ static func fill(node: Dictionary, f: Dictionary, ctx: RollContext, depth: int)
|
|||
row["index"] = int(pick["index"])
|
||||
row["value"] = pick.get("value")
|
||||
var e: TableEntry = pick["entry"]
|
||||
if not e.repeat.is_empty():
|
||||
if repeats_in(e, k):
|
||||
text = await _repeat(node, t, k, e, f, ctx, depth, why)
|
||||
elif k == 0:
|
||||
text = str(node["summary"])
|
||||
|
|
@ -110,7 +111,7 @@ static func _repeat(node: Dictionary, t: RollTable, k: int, e: TableEntry, f: Di
|
|||
got.append(str(p["summary"]))
|
||||
continue
|
||||
var pe: TableEntry = p["entry"]
|
||||
if not pe.repeat.is_empty():
|
||||
if repeats_in(pe, k):
|
||||
for _n in int(pe.repeat.get("count", 2)):
|
||||
queue.append(pe.repeat.get("reroll", []))
|
||||
continue
|
||||
|
|
@ -121,6 +122,14 @@ static func _repeat(node: Dictionary, t: RollTable, k: int, e: TableEntry, f: Di
|
|||
return REPEAT_JOIN.join(got)
|
||||
|
||||
|
||||
## True when entry `e`'s "roll again and combine" applies in column `k`.
|
||||
static func repeats_in(e: TableEntry, k: int) -> bool:
|
||||
if e.repeat.is_empty():
|
||||
return false
|
||||
var only: Variant = e.repeat.get("columns")
|
||||
return not (only is Array) or (only as Array).is_empty() or (only as Array).has(k)
|
||||
|
||||
|
||||
static func _add_why(why: Array, pick: Dictionary, column: String) -> void:
|
||||
if pick.has("why"):
|
||||
for fact: Dictionary in pick["why"]:
|
||||
|
|
|
|||
|
|
@ -98,6 +98,15 @@ static func clean_repeat(value: Variant) -> Dictionary:
|
|||
ids.append(str(item))
|
||||
if not ids.is_empty():
|
||||
out["reroll"] = ids
|
||||
var columns: Array[int] = []
|
||||
if (value as Dictionary).get("columns") is Array:
|
||||
for item: Variant in value["columns"]:
|
||||
var index := int(JsonIO._num(item, -1))
|
||||
if index >= 0 and not columns.has(index):
|
||||
columns.append(index)
|
||||
if not columns.is_empty():
|
||||
columns.sort()
|
||||
out["columns"] = columns
|
||||
return out
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ A card can give each result more than one part, like a row of a printed table wi
|
|||
- [b]Roll each column separately[/b] rolls again for every column, for rules like "roll 1d10 for each of Resources, Water, Atmosphere and Life". After the roll, the part each column landed on is lit.
|
||||
- [b]Save as[/b] keeps a column's text as a value, so later text and rules can use it.
|
||||
- [b]Only roll this column if[/b] skips a column unless a condition is true, such as "only roll Life if the Atmosphere is at least Thin". Columns are rolled left to right, so a condition can use what an earlier column saved.
|
||||
- A result can [b]roll that column again and combine[/b] ("roll twice and combine"). With columns rolled separately, tick [b]Only in[/b] to choose which columns it applies to; by default it applies to every column.
|
||||
- Remove a column with its ×: its text goes from every result.
|
||||
|
||||
# Threads
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extends TestBase
|
|||
func _init() -> void:
|
||||
await _test_join_and_repeat()
|
||||
await _test_repeat_reroll()
|
||||
await _test_repeat_one_column()
|
||||
await _test_list_save()
|
||||
await _test_only_option()
|
||||
_test_save_load()
|
||||
|
|
@ -88,6 +89,24 @@ func _test_repeat_reroll() -> void:
|
|||
_check(str(col["text"]).count(" & ") <= 1, "rolling again on the repeat row keeps it to two: %s" % col["text"])
|
||||
|
||||
|
||||
## A combine row set to the 1st column only: the 2nd column just shows its
|
||||
## own cell when the row comes up there.
|
||||
func _test_repeat_one_column() -> void:
|
||||
var b := _surface_board()
|
||||
var r := b.get_table("surface").find_entry("r")
|
||||
r.repeat = TableEntry.clean_repeat({"count": 2, "reroll": ["r"], "columns": [0]})
|
||||
_eq(r.repeat.get("columns"), [0], "the columns list is kept")
|
||||
var plain_second := false
|
||||
for s in 60:
|
||||
var tree := await Roller.roll_async(b, "start", _ctx(b, s))
|
||||
for kid: Dictionary in tree["children"]:
|
||||
var second: Dictionary = kid["columns"][1]
|
||||
_check(not str(second["text"]).contains(" & "), "the 2nd column doesn't roll again: %s" % second["text"])
|
||||
plain_second = plain_second or str(second["text"]) == "Roll twice and combine"
|
||||
_check(plain_second, "it shows the row's own cell there instead")
|
||||
_check(RollColumns.repeats_in(r, 0) and not RollColumns.repeats_in(r, 1), "repeats_in follows the list")
|
||||
|
||||
|
||||
func _test_list_save() -> void:
|
||||
var b := TowerBoard.new()
|
||||
var res := RollTable.new("res", "Resource")
|
||||
|
|
|
|||
|
|
@ -213,9 +213,34 @@ static func _repeat_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control
|
|||
insp.wrote(t))
|
||||
v.add_child(skip)
|
||||
v.add_child(InspectorKit.note("Otherwise it adds another roll each time it comes up.", Style.MUTED, 12))
|
||||
if t.columns.size() > 1 and t.column_rolls == RollTable.COLUMNS_EACH:
|
||||
v.add_child(_repeat_columns(insp, t, e))
|
||||
return v
|
||||
|
||||
|
||||
## "In these columns": one tick box per column. All ticked (the default) saves
|
||||
## no list, so the row rolls again in every column it comes up in.
|
||||
static func _repeat_columns(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||
var row := InspectorKit.flow()
|
||||
row.add_child(InspectorKit.word("Only in"))
|
||||
for index in t.columns.size():
|
||||
var column_name := str(t.columns[index].get("name", "Column %d" % (index + 1)))
|
||||
var tick := InspectorKit.check_box(column_name, RollColumns.repeats_in(e, index))
|
||||
InspectorKit.tag(tick, "res.repeat.column.%d" % index)
|
||||
tick.toggled.connect(func(on: bool) -> void:
|
||||
var chosen: Array[int] = []
|
||||
for other in t.columns.size():
|
||||
if (other == index and on) or (other != index and RollColumns.repeats_in(e, other)):
|
||||
chosen.append(other)
|
||||
if chosen.is_empty() or chosen.size() == t.columns.size():
|
||||
e.repeat.erase("columns")
|
||||
else:
|
||||
e.repeat["columns"] = chosen
|
||||
insp.wrote(t))
|
||||
row.add_child(tick)
|
||||
return row
|
||||
|
||||
|
||||
# ---------- Editing (keeps every result's cells in step) ----------
|
||||
|
||||
## Turns columns on: "Result" (the results' own text) plus one more.
|
||||
|
|
|
|||
Loading…
Reference in a new issue