formatting
This commit is contained in:
parent
1b9ff9b393
commit
9bece1550d
|
@ -1,16 +1,16 @@
|
||||||
from dataclasses import dataclass
|
|
||||||
import itertools
|
import itertools
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from sqlalchemy import ForeignKey, String, Text, UniqueConstraint
|
from sqlalchemy import ForeignKey, String, Text, UniqueConstraint
|
||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
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.base import BaseObject, SlugMixin
|
||||||
from ttfrog.db.schema.classes import CharacterClass, ClassFeature
|
from ttfrog.db.schema.classes import CharacterClass, ClassFeature
|
||||||
from ttfrog.db.schema.constants import DamageType, Defenses, InventoryType
|
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.modifiers import Modifier, ModifierMixin, Stat
|
||||||
from ttfrog.db.schema.skill import Skill
|
from ttfrog.db.schema.skill import Skill
|
||||||
|
|
||||||
|
@ -283,7 +283,11 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
|
||||||
ancestry: Mapped["Ancestry"] = relationship(uselist=False, default=None)
|
ancestry: Mapped["Ancestry"] = relationship(uselist=False, default=None)
|
||||||
|
|
||||||
_equipment = relationship(
|
_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(
|
_spells = relationship(
|
||||||
"CharacterSpellInventory",
|
"CharacterSpellInventory",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from enum import StrEnum, auto
|
from enum import StrEnum, auto
|
||||||
|
|
||||||
from ttfrog.db.base import EnumField
|
from ttfrog.db.base import EnumField
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from sqlalchemy import ForeignKey
|
from sqlalchemy import ForeignKey
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
from sqlalchemy.orm import Mapped
|
from sqlalchemy.orm import Mapped
|
||||||
|
@ -115,7 +113,6 @@ class Inventory(BaseObject):
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InventoryItemMixin:
|
class InventoryItemMixin:
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def container(cls) -> Mapped["Inventory"]:
|
def container(cls) -> Mapped["Inventory"]:
|
||||||
return relationship(uselist=False, viewonly=True, init=False)
|
return relationship(uselist=False, viewonly=True, init=False)
|
||||||
|
@ -157,7 +154,7 @@ class InventoryMixin:
|
||||||
inventory_type=self.inventory_type,
|
inventory_type=self.inventory_type,
|
||||||
primary_table_name=self.__tablename__,
|
primary_table_name=self.__tablename__,
|
||||||
primary_table_id=self.id,
|
primary_table_id=self.id,
|
||||||
character_id=getattr(self, "character_id", None)
|
character_id=getattr(self, "character_id", None),
|
||||||
)
|
)
|
||||||
session.add(self)
|
session.add(self)
|
||||||
|
|
||||||
|
@ -306,7 +303,7 @@ class Item(BaseObject, InventoryMixin, InventoryItemMixin, ModifierMixin):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def move_to(self, target):
|
def move_to(self, target):
|
||||||
target_inventory = getattr(target, 'inventory', target)
|
target_inventory = getattr(target, "inventory", target)
|
||||||
if self.container == target_inventory:
|
if self.container == target_inventory:
|
||||||
return False
|
return False
|
||||||
self.container.contents.remove(self)
|
self.container.contents.remove(self)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from ttfrog.db.schema import prototypes
|
from ttfrog.db.schema import prototypes
|
||||||
from ttfrog.db.schema.inventory import InventoryType
|
from ttfrog.db.schema.inventory import InventoryType
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
def test_spell_inventory(db, carl):
|
def test_spell_inventory(db, carl):
|
||||||
with db.transaction():
|
with db.transaction():
|
||||||
|
@ -213,8 +212,6 @@ def test_containers(db, carl):
|
||||||
# one bag, one pole, one rope
|
# one bag, one pole, one rope
|
||||||
total_inventory_size = bag_inventory_size + equipment_size
|
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(bag.inventory.contents)) == bag_inventory_size
|
||||||
assert len(list(carl.equipment.contents)) == equipment_size
|
assert len(list(carl.equipment.contents)) == equipment_size
|
||||||
assert len(list(carl.equipment.all_contents)) == total_inventory_size
|
assert len(list(carl.equipment.all_contents)) == total_inventory_size
|
||||||
|
|
Loading…
Reference in New Issue
Block a user