diff --git a/core/dice.gd b/core/dice.gd index a0efad4..bd84db3 100644 --- a/core/dice.gd +++ b/core/dice.gd @@ -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 diff --git a/core/roll_lint_book.gd b/core/roll_lint_book.gd index 60c07ae..e7a9773 100644 --- a/core/roll_lint_book.gd +++ b/core/roll_lint_book.gd @@ -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 diff --git a/tests/test_book_tables.gd b/tests/test_book_tables.gd index ce98e4d..411e53d 100644 --- a/tests/test_book_tables.gd +++ b/tests/test_book_tables.gd @@ -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") diff --git a/ui/inspector_thread_rolls.gd b/ui/inspector_thread_rolls.gd index d6787a7..e2ae563 100644 --- a/ui/inspector_thread_rolls.gd +++ b/ui/inspector_thread_rolls.gd @@ -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."