Batch rolls join the Earlier list with one sound; longer history
Batches saved to the history file but never reached the tray's Earlier list, and played no sound. Now each roll shows there as "Name (2 of 5)" and the batch plays one roll sound. Earlier keeps 30 rolls (was 6) and the saved history 200 (was 50). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
22d3613364
commit
6a460d17eb
6 changed files with 35 additions and 6 deletions
|
|
@ -9,7 +9,7 @@ extends RefCounted
|
|||
## Decks are opaque Dictionaries (whatever DeckState.to_dict() produces).
|
||||
|
||||
const FORMAT_VERSION := 1
|
||||
const HISTORY_CAP := 50
|
||||
const HISTORY_CAP := 200
|
||||
|
||||
## Folder that contains state/. Default user://.
|
||||
var root: String
|
||||
|
|
|
|||
|
|
@ -40,9 +40,22 @@ func _init() -> void:
|
|||
_check(main.current.get("done", false) and main.current.get("fast", false), "the interrupted roll doesn't overwrite the fast result")
|
||||
|
||||
await _test_deck_waits()
|
||||
await _test_batch_history()
|
||||
finish()
|
||||
|
||||
|
||||
## A batch of rolls goes into the tray's Earlier list, newest first.
|
||||
func _test_batch_history() -> void:
|
||||
var before := main.history.size()
|
||||
var texts: Array[String] = await BatchRoll.run(main, "names", 3)
|
||||
_eq(texts.size(), 3, "a batch rolls the asked number of times")
|
||||
_eq(main.history.size(), mini(before + 4, Main.HISTORY_SIZE), "each batch roll joins Earlier (after the roll on screen)")
|
||||
_eq(str(main.history[0].get("batch", "")), "3 of 3", "the newest is the batch's last roll")
|
||||
for node in main.get_children():
|
||||
if node is ModalCard:
|
||||
(node as ModalCard).close()
|
||||
|
||||
|
||||
## Deck mode: an animated roll fades the drawn result only once it lights;
|
||||
## a fast roll fades it at once.
|
||||
func _test_deck_waits() -> void:
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func _test_state() -> void:
|
|||
st.set_variable("c1", "weapon", "Dagger", "t1")
|
||||
st.set_variable("c1", "armor", "Plate", "t2")
|
||||
st.set_setting("last_collection", "c1")
|
||||
for i in 60:
|
||||
for i in StateStore.HISTORY_CAP + 10:
|
||||
st.add_history({"collection": "c1", "n": i})
|
||||
_check(st.is_dirty(), "mutation sets dirty")
|
||||
_check(st.save() and not st.is_dirty(), "save clears dirty")
|
||||
|
|
@ -165,8 +165,9 @@ func _test_state() -> void:
|
|||
_check(st2.get_variables("c1")["weapon"] == {"value": "Dagger", "source": "t1"}, "variable round trip")
|
||||
_check(st2.get_setting("last_collection") == "c1" and st2.get_setting("none", "d") == "d", "settings round trip")
|
||||
var h := st2.get_history()
|
||||
_check(h.size() == StateStore.HISTORY_CAP, "history capped at 50 (got %d)" % h.size())
|
||||
_check(h[0]["n"] == 59.0 and h[49]["n"] == 10.0, "history is most recent first")
|
||||
_check(h.size() == StateStore.HISTORY_CAP, "history capped at HISTORY_CAP (got %d)" % h.size())
|
||||
var last := StateStore.HISTORY_CAP - 1
|
||||
_check(h[0]["n"] == float(last + 10) and h[last]["n"] == 10.0, "history is most recent first")
|
||||
|
||||
st2.clear_variable("c1", "weapon")
|
||||
_check(not st2.get_variables("c1").has("weapon") and st2.get_variables("c1").has("armor"), "clear one variable")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ extends RefCounted
|
|||
## Batches: roll a card's whole chain several times ("5 NPCs") and get every
|
||||
## result at the end, in one window with Copy all. Questions on the way are
|
||||
## asked each time. Values and decks change as they would for single rolls.
|
||||
## Each roll goes into the tray's Earlier list (and the saved history), and
|
||||
## the batch plays one roll sound.
|
||||
|
||||
const MAX := 100
|
||||
|
||||
|
|
@ -24,6 +26,9 @@ static func ask(m: Main, tid: String) -> void:
|
|||
static func run(m: Main, tid: String, n: int) -> Array[String]:
|
||||
var t := m.data.get_table(tid)
|
||||
var texts: Array[String] = []
|
||||
if m.sound:
|
||||
m.sound.play("roll")
|
||||
m.rolling._archive_current()
|
||||
for i in n:
|
||||
var ctx := Roller.new_context(m.data, m.rng, m.persistent_vars, m.decks)
|
||||
ctx.prompt = m.prompt_hook
|
||||
|
|
@ -32,6 +37,11 @@ static func run(m: Main, tid: String, n: int) -> Array[String]:
|
|||
break
|
||||
var steps := Roller.flatten(tree, [])
|
||||
texts.append(m.rolling.result_text(steps, ResultTray.COPY_TEXT))
|
||||
var rec := {"collection": m.data.id, "root": tid, "root_name": t.name, "time": Time.get_unix_time_from_system(),
|
||||
"steps": steps, "all": steps, "done": true, "archived": true, "batch": "%d of %d" % [i + 1, n]}
|
||||
m.history.push_front(rec)
|
||||
if m.history.size() > Main.HISTORY_SIZE:
|
||||
m.history.resize(Main.HISTORY_SIZE)
|
||||
if m.state:
|
||||
m.local_state._store_decks()
|
||||
if ctx.persistent_changed:
|
||||
|
|
@ -41,6 +51,7 @@ static func run(m: Main, tid: String, n: int) -> Array[String]:
|
|||
if m.state:
|
||||
m.state.save()
|
||||
m.refresh_live()
|
||||
m.tray.render()
|
||||
if not texts.is_empty():
|
||||
m._add_modal(dialog(t, texts))
|
||||
return texts
|
||||
|
|
|
|||
|
|
@ -83,7 +83,10 @@ static func earlier_line(rec: Dictionary) -> String:
|
|||
continue
|
||||
texts.insert(0, RichText.decorate(TrayText.one_line(str(s["text"])), true))
|
||||
shown += 1
|
||||
var lead := "[color=#%s]%s:[/color] " % [Style.ON_BG_MUTED.to_html(false), RichText.plain(Formatter.strip_tags(str(rec.get("root_name", ""))))]
|
||||
var root := RichText.plain(Formatter.strip_tags(str(rec.get("root_name", ""))))
|
||||
if str(rec.get("batch", "")) != "":
|
||||
root += " (%s)" % rec["batch"]
|
||||
var lead := "[color=#%s]%s:[/color] " % [Style.ON_BG_MUTED.to_html(false), root]
|
||||
if skipped > 0:
|
||||
lead += "[color=#%s]… %d earlier →[/color] " % [Style.ON_BG_MUTED.to_html(false), skipped]
|
||||
return lead + " → ".join(texts)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ enum Mode { PLAY, BUILD }
|
|||
## The rules view changed ("plain" or "text"; see set_rules_view).
|
||||
signal rules_view_changed(view: String)
|
||||
|
||||
const HISTORY_SIZE := 6
|
||||
## Earlier rolls kept in the tray (a batch of rolls fills several).
|
||||
const HISTORY_SIZE := 30
|
||||
const SAVE_DELAY := 0.6
|
||||
const HINTS := {
|
||||
Mode.PLAY: "Click a die to roll. Shift-click skips straight to the result.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue