feat(combat): expose weapon reference in observation snapshot

This commit is contained in:
2026-09-06 13:46:12 +02:00
parent cd8051f2c4
commit f3d874790a
4 changed files with 284 additions and 2 deletions
+17
View File
@@ -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