Skip to content

feat(combat): inject optional allowed-set into clean_damage_types/combatant_defenses (0.26.0)#8

Open
sligara7 wants to merge 1 commit into
mainfrom
l3-allowed-param
Open

feat(combat): inject optional allowed-set into clean_damage_types/combatant_defenses (0.26.0)#8
sligara7 wants to merge 1 commit into
mainfrom
l3-allowed-param

Conversation

@sligara7

Copy link
Copy Markdown
Owner

What

Adds a keyword-only allowed: frozenset[str] = DAMAGE_TYPES parameter to clean_damage_types() and combatant_defenses() in combat/combat.py.

  • Default unchanged — intersects with the SRD-13 DAMAGE_TYPES exactly as before (backward-compatible; all existing call sites compile + behave identically).
  • A caller that governs its own damage-type vocabulary passes a wider set (SRD-13 ∪ custom) so registered types survive the filter at component assembly, the computed-stats read, and live combat damage application.
  • dndwright stays domain-agnostic (it accepts a set; it doesn't know where allowed comes from). Members must be lower-cased (caller owns canonicalisation).
  • Public API (__all__) unchanged.

Why

Downstream StoryFlow v1.1.0 adds a per-universe damage-type registry. The hardcoded SRD-13 frozenset was the single chokepoint that silently dropped any custom type — and it is applied by two consumers (the character-sheet compute path AND the live-combat combatant_defenses call). Dependency-injecting the allowed-set is the single-source-of-truth fix that avoids a split-brain (registry honored on the sheet but not in combat) and avoids duplicating the filter across consumers.

Tests

  • New real-path tests in tests/test_defenses_and_serialization.py: widened-vocab survival, default-unchanged back-compat, per-channel threading, and a registered type actually halving damage in apply_damage (governed at the point damage is applied, not just on the sheet).
  • Full suite: 1655 passed, ruff clean, api-contract green (__all__ unchanged).

Minor bump 0.25.2 → 0.26.0 + CHANGELOG. Release/PyPI publish (gh release create v0.26.0) is a separate gated step.

…batant_defenses

Add a keyword-only allowed: frozenset[str] = DAMAGE_TYPES to clean_damage_types
and combatant_defenses. Default preserves SRD-13 behavior (backward-compatible);
a caller governing its own damage-type vocabulary passes SRD-13 ∪ custom so
registered types survive the filter at assembly, computed-stats read, AND live
combat damage application — no split-brain. dndwright stays domain-agnostic.
Bump 0.25.2 -> 0.26.0. Public API (__all__) unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JXPSRe6rg8jtdAAvqZrxvf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant