diff --git a/VERSION b/VERSION index 07feb82..14a8c24 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.17.0 \ No newline at end of file +0.17.1 \ No newline at end of file diff --git a/dungeonsheets/content_registry.py b/dungeonsheets/content_registry.py index 2f7879e..93a11da 100644 --- a/dungeonsheets/content_registry.py +++ b/dungeonsheets/content_registry.py @@ -136,13 +136,8 @@ class ContentRegistry: else: attr = found_attrs[0] # Apply weapon/etc. bonuses - if bonus > 0: - if ( - issubclass(attr, weapons.Weapon) - or issubclass(attr, armor.Shield) - or issubclass(attr, armor.Armor) - ): - attr = attr.improved_version(bonus) + if bonus > 0 and hasattr(attr, 'improved_version'): + attr = attr.improved_version(bonus) return attr diff --git a/dungeonsheets/make_sheets.py b/dungeonsheets/make_sheets.py index 639bf49..b7e7115 100644 --- a/dungeonsheets/make_sheets.py +++ b/dungeonsheets/make_sheets.py @@ -113,7 +113,6 @@ def create_random_tables_content( ) -> str: template = jinja_env.get_template(f"random_tables_template.{suffix}") return template.render( - conjure_animals=True, tables=tables, use_dnd_decorations=use_dnd_decorations, ) diff --git a/tests/test_content_registry.py b/tests/test_content_registry.py index 7aa628e..d6a4a17 100644 --- a/tests/test_content_registry.py +++ b/tests/test_content_registry.py @@ -2,7 +2,7 @@ from unittest import TestCase from dungeonsheets.content_registry import ContentRegistry -from dungeonsheets import monsters +from dungeonsheets import monsters, weapons class TestContentRegistry(TestCase): @@ -62,3 +62,20 @@ class TestContentRegistry(TestCase): # Direct access self.assertEqual(creg.findattr("my_attr", valid_classes=[int]), test_module.my_attr) + def test_findattr_magic_weapon(self): + creg = ContentRegistry() + creg.add_module(weapons) + # First test with a non-magical weapon + shortsword = creg.findattr("shortsword") + self.assertIs(shortsword, weapons.Shortsword) + # Now test with a magical weapon + magic_shortsword = creg.findattr("shortsword + 1") + self.assertTrue(issubclass(magic_shortsword, weapons.Shortsword), + "Improved version is not subclass of base.") + self.assertEqual(magic_shortsword.attack_bonus, 1) + self.assertEqual(magic_shortsword.damage_bonus, 1) + # Make sure some other item that can't be "improved" still works + creg = ContentRegistry() + creg.add_module(monsters) + lich = creg.findattr("lich+1") + self.assertIs(lich, monsters.Lich) diff --git a/tests/test_make_sheets.py b/tests/test_make_sheets.py index c8091b8..5d914df 100644 --- a/tests/test_make_sheets.py +++ b/tests/test_make_sheets.py @@ -2,7 +2,7 @@ import unittest import os from pathlib import Path -from dungeonsheets import make_sheets, character, monsters +from dungeonsheets import make_sheets, character, monsters, random_tables EG_DIR = Path(__file__).parent.parent.resolve() / "examples" @@ -283,7 +283,7 @@ class TexCreatorTestCase(unittest.TestCase): def test_random_tables_tex(self): tex = make_sheets.create_random_tables_content( + tables=[random_tables.ConjureAnimals], suffix="tex", - conjure_animals=True, ) self.assertIn(r"\subsection*{Conjure Animals}", tex)