rulebook package
Submodules
rulebook.entity_importer module
- class core.rulebook.entity_importer.EntityImporter(api=None, base_path='core/data/rulebook_json')
Bases:
BaseImporter
Imports and parses monster entities from a local SRD JSON dataset.
- Inherits:
BaseImporter: Provides API setup and slugified endpoint access.
- Parameters:
api (object) – Optional API handler instance (LocalAPIHandler or similar)
- get_by_name(name: str) RulebookEntity
Retrieve a monster by name and parse it into a RulebookEntity.
- Parameters:
name (str) – The monster’s name (e.g., “Goblin”).
- Returns:
A RulebookEntity instance if found, otherwise None.
- Return type:
RulebookEntity or None
- list_all()
Retrieve the full list of monster definitions.
- Returns:
A list of all monster entries.
- Return type:
list[dict]
- parse(raw: dict) RulebookEntity
Parse raw monster data into a RulebookEntity.
- Parameters:
raw (dict) – The raw monster dictionary.
- Returns:
A RulebookEntity instance.
- Return type:
rulebook.import_manager module
- class core.rulebook.import_manager.RulebookImporter(base_path='core/data/rulebook_json')
Bases:
object
Handles importing monsters and spells from local SRD JSON files.
- import_monster(name: str) GameEntity
Imports a monster by name and converts it to a GameEntity.
- Parameters:
name (str) – The name of the monster to import.
- Returns:
The imported monster as a GameEntity, or None on error.
- Return type:
GameEntity or None
- import_spell(name: str) Spell
Imports a spell by name and converts it to a Spell object.
- Parameters:
name (str) – The name of the spell to import.
- Returns:
The imported spell as a Spell object, or None on error.
- Return type:
Spell or None
- search_monsters()
Retrieves a list of all monster names from the local SRD.
- Returns:
A list of monster names.
- Return type:
list[str]
- search_spells()
Retrieves a list of all spell names from the local SRD.
- Returns:
A list of spell names.
- Return type:
list[str]
rulebook.importer_base module
- class core.rulebook.importer_base.BaseImporter(api=None, base_path='core/data/rulebook_json')
Bases:
object
BaseImporter provides basic functionality for importing data from a local SRD JSON dataset.
- api
An instance used to access SRD data from disk.
- Type:
- get_raw(category: str, name: str) dict
Retrieves a single entry by category and name using a slug-based lookup.
- Parameters:
category (str) – Category name (e.g. “monsters”, “spells”).
name (str) – Display name (e.g. “Goblin”).
- Returns:
The matching JSON entry, or None if not found.
- Return type:
dict
- slugify(name: str) str
Converts a string into a slug suitable for SRD matching.
rulebook.rulebook_entity module
- class core.rulebook.rulebook_entity.RulebookEntity(name, entity_type, stats=None, abilities=None, source='monster', raw_data=None)
Bases:
object
Represents a generic entity from a rulebook, such as a monster, NPC, spell, or item.
- Parameters:
name (str) – The name of the entity.
entity_type (str) – The type/category of the entity (e.g., “monster”, “npc”, “spell”, “item”).
stats (dict, optional) – A dictionary containing the entity’s statistics (e.g., HP, AC, abilities).
abilities (list, optional) – A list of the entity’s abilities or actions.
source (str, optional) – The source type of the entity (e.g., “monster”, “spell”).
raw_data (dict, optional) – The raw data dictionary from which the entity was created.
- Variables:
name – The name of the entity.
entity_type – The type/category of the entity.
stats – The entity’s statistics.
abilities – The entity’s abilities or actions.
source – The source type of the entity.
raw – The raw data dictionary.
- classmethod from_api(data: dict)
Creates a RulebookEntity from API data (alias for from_monster).
- Parameters:
data (dict) – The API data dictionary.
- Returns:
A RulebookEntity instance.
- Return type:
- classmethod from_monster(data: dict)
Create a RulebookEntity from a monster data dictionary, with heuristics for categorization.
- Parameters:
data (dict) – The monster data dictionary.
- Returns:
A RulebookEntity instance.
- Return type:
- to_game_entity()
Converts this RulebookEntity into a GameEntity for use in the game system.
- Returns:
A GameEntity instance.
- Return type:
rulebook.rulebook_spell module
- class core.rulebook.rulebook_spell.RulebookSpell(name, level, school, casting_time, duration, range_, damage=None, description='', dc=None, classes=None, area=None, concentration=False, higher_level=None, material=None, components=None, raw_data=None)
Bases:
object
Represents a spell as defined in the rulebook, with all relevant properties.
- Parameters:
name (str) – Name of the spell.
level (int) – Spell level.
school (str) – School of magic.
casting_time (str) – Time required to cast the spell.
duration (str) – Duration of the spell’s effect.
range (str) – Range of the spell.
damage (dict, optional) – Damage mapping by slot level, e.g. {1: “1d8”}.
description (str, optional) – Description of the spell.
dc (dict, optional) – Dictionary with DC info, e.g. {“ability”: “WIS”, “success”: “half”}.
classes (list, optional) – List of classes that can cast the spell.
area (dict, optional) – Area of effect, e.g. {“type”: “sphere”, “size”: 20}.
concentration (bool, optional) – Whether the spell requires concentration.
higher_level (list, optional) – List of effects when cast at higher levels.
material (str, optional) – Material components required.
components (list, optional) – List of components (V, S, M).
raw_data (dict, optional) – Raw data from the API or source.
- classmethod from_api(data)
Create a RulebookSpell instance from API data.
- Parameters:
data (dict) – Dictionary containing spell data from the API.
- Returns:
RulebookSpell instance populated with API data.
- Return type:
- to_spell()
Convert this RulebookSpell to a Spell instance from the models module.
- Returns:
Spell instance with mapped properties.
- Return type:
Spell
rulebook.spell_importer module
- class core.rulebook.spell_importer.SpellImporter(api=None, base_path='core/data/rulebook_json')
Bases:
BaseImporter
Imports and parses spells from a local SRD JSON dataset.
- Inherits:
BaseImporter: Provides API setup and slugified endpoint access.
- Parameters:
api (object) – Optional API handler instance (LocalAPIHandler or similar)
- get_by_name(name: str) RulebookSpell
Retrieves a spell by its name.
- Parameters:
name (str) – The name of the spell to retrieve.
- Returns:
A RulebookSpell instance if found, otherwise None.
- Return type:
RulebookSpell or None
- list_all()
Retrieves a list of all spells from the API.
- Returns:
A list of all spells from the API.
- Return type:
list
- parse(raw)
Parses raw spell data from the API into a RulebookSpell object.
- Parameters:
raw (dict) – The raw spell data from the API.
- Returns:
A RulebookSpell instance created from the raw data.
- Return type: