Thread dice must roll dice: Dice.roll_problem shared by the field and the board check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-10 21:19:36 -06:00
parent df03168382
commit 8bbc7002a0
4 changed files with 22 additions and 3 deletions

View file

@ -43,6 +43,21 @@ static func is_valid_text(text: String) -> bool:
return parse(text).valid
## "" when `text` is something to roll instead of a card's dice: plain dice
## ("3d10+70"), or a rule that rolls at least one die ("2d6 + @luck").
## Otherwise a plain-words reason.
static func roll_problem(text: String) -> String:
var s := text.strip_edges()
if s == "" or parse(s).valid:
return ""
var err := Expr.check(s)
if err != "":
return err
if RegEx.create_from_string("(?i)(^|[^a-z0-9_@])\\d*d\\d*([^a-z0-9_]|$)").search(s) == null:
return "it doesn't roll any dice"
return ""
func min_value() -> int:
return count + bonus if valid else 0

View file

@ -16,8 +16,8 @@ static func lint(board: TowerBoard, t: RollTable) -> Array[Dictionary]:
if dice != "":
if not to.is_ranged() or to.kind != RollTable.KIND_ROLL:
out.append(_item(t, e.id, "The thread to %s rolls with %s, but only a card with numbered ranges can use other dice." % [_n(to), dice], "hint"))
elif not Dice.parse(dice).valid and Expr.check(dice) != "":
out.append(_item(t, e.id, "The thread to %s rolls with %s: %s" % [_n(to), dice, Expr.check(dice)], "error"))
elif Dice.roll_problem(dice) != "":
out.append(_item(t, e.id, "The thread to %s rolls with %s: %s" % [_n(to), dice, Dice.roll_problem(dice)], "error"))
var again := e.reroll_for(p)
if not again.is_empty():
var left := 0

View file

@ -224,3 +224,7 @@ func _test_lint() -> void:
b.tables.append(s)
msgs = Roller.lint_pipes(b).map(func(i: Dictionary) -> String: return str(i["message"]))
_check(msgs.any(func(m: String) -> bool: return m.contains("two steps")), "lint: a one-step scale")
_eq(Dice.roll_problem("3d10+70"), "", "plain dice roll")
_eq(Dice.roll_problem("2d6 + @luck"), "", "a rule with dice rolls")
_eq(Dice.roll_problem("bogus"), "it doesn't roll any dice", "a word isn't dice")
_check(Dice.roll_problem("@luck + 2") != "", "a rule with no dice isn't dice")

View file

@ -14,7 +14,7 @@ const OPEN_META := "reroll_open"
## "" when `s` is dice the thread can roll with (empty = the card's own).
static func dice_error(s: String) -> String:
var d := s.strip_edges()
if d == "" or Dice.parse(d).valid or Expr.check(d) == "":
if Dice.roll_problem(d) == "":
return ""
return "That isn't something the app can roll. Try dice such as 3d10+70."