formatting

This commit is contained in:
evilchili 2024-09-21 16:00:17 -07:00
parent 1b9ff9b393
commit 9bece1550d
4 changed files with 13 additions and 14 deletions

View File

@ -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",

View File

@ -1,4 +1,5 @@
from enum import StrEnum, auto
from ttfrog.db.base import EnumField

View File

@ -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)

View File

@ -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