From f2c7dbddb602db06ec8e8a8c9a4134451acd52e9 Mon Sep 17 00:00:00 2001 From: Supremist Date: Tue, 28 Oct 2025 23:47:23 +0200 Subject: Move common data structs to game.py --- creature.py | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'creature.py') diff --git a/creature.py b/creature.py index aa2f7f4..e30f877 100644 --- a/creature.py +++ b/creature.py @@ -1,43 +1,6 @@ import csv -import re -from enum import Enum -from dataclasses import dataclass - -class Difficulty(Enum): - Terrible = -2 - Low = -1 - Moderate = 0 - High = 1 - Extreme = 2 - - @classmethod - def from_str(cls, name): - name = name.strip().lower() - for member in cls: - if member.name.lower() == name: - return member - raise ValueError(f"{name!r} is not a valid {cls.__name__}") - -@dataclass -class RollInfo: - die_size: int - dice_count: int = 1 - bonus: int = 0 - - @classmethod - def parse(cls, str_data): - # match strings like 2d6+8 (15) - match = re.fullmatch(r"^(\d+)d(\d+)\s*(\+\s*\d+)?\s*(\s*\(\s*\d+\s*\))?", - str_data) - if not match: - raise ValueError(f"{str_data!r} is not a valid RollInfo") - res = RollInfo(int(match.group(2).strip())) - res.dice_count = int(match.group(1).strip()) - bonus = match.group(3) - if bonus: - res.bonus = int(bonus.strip(" +")) - return res +from game import Difficulty, RollInfo def safe_item_level(creature_level: int): if creature_level <= 3: -- cgit v1.2.3