feat(combat): expose weapon reference in observation snapshot
This commit is contained in:
@@ -122,3 +122,20 @@ def parse_dice(text: str) -> DiceExpr:
|
||||
raise DiceParseError(text) from None
|
||||
|
||||
return DiceExpr.flat(n)
|
||||
|
||||
|
||||
def dice_to_str(expr: DiceExpr) -> str:
|
||||
"""Serialize a DiceExpr into canonical dice notation.
|
||||
|
||||
Inverse of `parse_dice`: flat expressions (count=0) render as the bare
|
||||
integer, dice expressions render as "NdS" with a signed bonus appended
|
||||
only when non-zero.
|
||||
"""
|
||||
if expr.count == 0:
|
||||
return str(expr.bonus)
|
||||
base = f"{expr.count}d{expr.sides}"
|
||||
if expr.bonus > 0:
|
||||
return f"{base}+{expr.bonus}"
|
||||
if expr.bonus < 0:
|
||||
return f"{base}{expr.bonus}"
|
||||
return base
|
||||
|
||||
Reference in New Issue
Block a user