diff --git a/src/ttfrog/db/schema/character.py b/src/ttfrog/db/schema/character.py index bab1fa6..4e47686 100644 --- a/src/ttfrog/db/schema/character.py +++ b/src/ttfrog/db/schema/character.py @@ -1,16 +1,16 @@ -from dataclasses import dataclass import itertools from collections import defaultdict +from dataclasses import dataclass from sqlalchemy import ForeignKey, String, Text, UniqueConstraint from sqlalchemy.ext.associationproxy import association_proxy -from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlalchemy.ext.declarative import declared_attr +from sqlalchemy.orm import Mapped, mapped_column, relationship from ttfrog.db.base import BaseObject, SlugMixin from ttfrog.db.schema.classes import CharacterClass, ClassFeature from ttfrog.db.schema.constants import DamageType, Defenses, InventoryType -from ttfrog.db.schema.inventory import Inventory, InventoryMixin +from ttfrog.db.schema.inventory import InventoryMixin from ttfrog.db.schema.modifiers import Modifier, ModifierMixin, Stat from ttfrog.db.schema.skill import Skill @@ -283,7 +283,11 @@ class Character(BaseObject, SlugMixin, ModifierMixin): ancestry: Mapped["Ancestry"] = relationship(uselist=False, default=None) _equipment = relationship( - "CharacterItemInventory", uselist=False, cascade="all,delete,delete-orphan", lazy="immediate", back_populates="character" + "CharacterItemInventory", + uselist=False, + cascade="all,delete,delete-orphan", + lazy="immediate", + back_populates="character", ) _spells = relationship( "CharacterSpellInventory", diff --git a/src/ttfrog/db/schema/constants.py b/src/ttfrog/db/schema/constants.py index 9960592..744b6fc 100644 --- a/src/ttfrog/db/schema/constants.py +++ b/src/ttfrog/db/schema/constants.py @@ -1,4 +1,5 @@ from enum import StrEnum, auto + from ttfrog.db.base import EnumField diff --git a/src/ttfrog/db/schema/inventory.py b/src/ttfrog/db/schema/inventory.py index 0bde68e..9eefd18 100644 --- a/src/ttfrog/db/schema/inventory.py +++ b/src/ttfrog/db/schema/inventory.py @@ -1,8 +1,6 @@ from dataclasses import dataclass from typing import List -from pprint import pprint - from sqlalchemy import ForeignKey from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import Mapped @@ -115,7 +113,6 @@ class Inventory(BaseObject): @dataclass class InventoryItemMixin: - @declared_attr def container(cls) -> Mapped["Inventory"]: return relationship(uselist=False, viewonly=True, init=False) @@ -157,7 +154,7 @@ class InventoryMixin: inventory_type=self.inventory_type, primary_table_name=self.__tablename__, primary_table_id=self.id, - character_id=getattr(self, "character_id", None) + character_id=getattr(self, "character_id", None), ) session.add(self) @@ -306,7 +303,7 @@ class Item(BaseObject, InventoryMixin, InventoryItemMixin, ModifierMixin): return True def move_to(self, target): - target_inventory = getattr(target, 'inventory', target) + target_inventory = getattr(target, "inventory", target) if self.container == target_inventory: return False self.container.contents.remove(self) diff --git a/test/test_inventories.py b/test/test_inventories.py index 01bc02d..0d5083d 100644 --- a/test/test_inventories.py +++ b/test/test_inventories.py @@ -1,7 +1,6 @@ from ttfrog.db.schema import prototypes from ttfrog.db.schema.inventory import InventoryType -from pprint import pprint def test_spell_inventory(db, carl): with db.transaction(): @@ -207,14 +206,12 @@ def test_containers(db, carl): assert pole_from_bag.prototype == ten_foot_pole assert pole_from_bag in bag - bag_inventory_size = 2 # one pole, one rope - equipment_size = 1 # one bag + bag_inventory_size = 2 # one pole, one rope + equipment_size = 1 # one bag # one bag, one pole, one rope total_inventory_size = bag_inventory_size + equipment_size - pprint(list(carl.equipment.all_contents)) - assert len(list(bag.inventory.contents)) == bag_inventory_size assert len(list(carl.equipment.contents)) == equipment_size assert len(list(carl.equipment.all_contents)) == total_inventory_size