rename ClassAttribute ClassFeature
This commit is contained in:
parent
4dd72d47d0
commit
da1b4223ea
|
@ -5,7 +5,7 @@ from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
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, ClassAttribute
|
from ttfrog.db.schema.classes import CharacterClass, ClassFeature
|
||||||
from ttfrog.db.schema.constants import Conditions, DamageType, Defenses
|
from ttfrog.db.schema.constants import Conditions, DamageType, Defenses
|
||||||
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
|
||||||
|
@ -15,7 +15,7 @@ __all__ = [
|
||||||
"AncestryTrait",
|
"AncestryTrait",
|
||||||
"AncestryTraitMap",
|
"AncestryTraitMap",
|
||||||
"CharacterClassMap",
|
"CharacterClassMap",
|
||||||
"CharacterClassAttributeMap",
|
"CharacterClassFeatureMap",
|
||||||
"Character",
|
"Character",
|
||||||
"Modifier",
|
"Modifier",
|
||||||
]
|
]
|
||||||
|
@ -34,9 +34,9 @@ def skill_creator(fields):
|
||||||
|
|
||||||
|
|
||||||
def attr_map_creator(fields):
|
def attr_map_creator(fields):
|
||||||
if isinstance(fields, CharacterClassAttributeMap):
|
if isinstance(fields, CharacterClassFeatureMap):
|
||||||
return fields
|
return fields
|
||||||
return CharacterClassAttributeMap(**fields)
|
return CharacterClassFeatureMap(**fields)
|
||||||
|
|
||||||
|
|
||||||
class HitDie(BaseObject):
|
class HitDie(BaseObject):
|
||||||
|
@ -139,7 +139,7 @@ class CharacterClassMap(BaseObject):
|
||||||
level: Mapped[int] = mapped_column(nullable=False, info={"min": 1, "max": 20}, default=1)
|
level: Mapped[int] = mapped_column(nullable=False, info={"min": 1, "max": 20}, default=1)
|
||||||
|
|
||||||
|
|
||||||
class CharacterClassAttributeMap(BaseObject):
|
class CharacterClassFeatureMap(BaseObject):
|
||||||
__tablename__ = "character_class_attribute_map"
|
__tablename__ = "character_class_attribute_map"
|
||||||
__table_args__ = (UniqueConstraint("character_id", "class_attribute_id"),)
|
__table_args__ = (UniqueConstraint("character_id", "class_attribute_id"),)
|
||||||
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
||||||
|
@ -147,13 +147,13 @@ class CharacterClassAttributeMap(BaseObject):
|
||||||
class_attribute_id: Mapped[int] = mapped_column(ForeignKey("class_attribute.id"), nullable=False)
|
class_attribute_id: Mapped[int] = mapped_column(ForeignKey("class_attribute.id"), nullable=False)
|
||||||
option_id: Mapped[int] = mapped_column(ForeignKey("class_attribute_option.id"), nullable=False)
|
option_id: Mapped[int] = mapped_column(ForeignKey("class_attribute_option.id"), nullable=False)
|
||||||
|
|
||||||
class_attribute: Mapped["ClassAttribute"] = relationship(lazy="immediate")
|
class_attribute: Mapped["ClassFeature"] = relationship(lazy="immediate")
|
||||||
option = relationship("ClassAttributeOption", lazy="immediate")
|
option = relationship("ClassFeatureOption", lazy="immediate")
|
||||||
|
|
||||||
character_class = relationship(
|
character_class = relationship(
|
||||||
"CharacterClass",
|
"CharacterClass",
|
||||||
secondary="class_map",
|
secondary="class_map",
|
||||||
primaryjoin="CharacterClassAttributeMap.character_id == CharacterClassMap.character_id",
|
primaryjoin="CharacterClassFeatureMap.character_id == CharacterClassMap.character_id",
|
||||||
secondaryjoin="CharacterClass.id == CharacterClassMap.character_class_id",
|
secondaryjoin="CharacterClass.id == CharacterClassMap.character_class_id",
|
||||||
viewonly=True,
|
viewonly=True,
|
||||||
uselist=False,
|
uselist=False,
|
||||||
|
@ -203,7 +203,7 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
|
||||||
_skills = relationship("CharacterSkillMap", uselist=True, cascade="all,delete,delete-orphan", lazy="immediate")
|
_skills = relationship("CharacterSkillMap", uselist=True, cascade="all,delete,delete-orphan", lazy="immediate")
|
||||||
skills = association_proxy("_skills", "skill", creator=skill_creator)
|
skills = association_proxy("_skills", "skill", creator=skill_creator)
|
||||||
|
|
||||||
character_class_attribute_map = relationship("CharacterClassAttributeMap", cascade="all,delete,delete-orphan")
|
character_class_attribute_map = relationship("CharacterClassFeatureMap", cascade="all,delete,delete-orphan")
|
||||||
attribute_list = association_proxy("character_class_attribute_map", "id", creator=attr_map_creator)
|
attribute_list = association_proxy("character_class_attribute_map", "id", creator=attr_map_creator)
|
||||||
|
|
||||||
ancestry_id: Mapped[int] = mapped_column(ForeignKey("ancestry.id"), nullable=False, default="1")
|
ancestry_id: Mapped[int] = mapped_column(ForeignKey("ancestry.id"), nullable=False, default="1")
|
||||||
|
@ -399,7 +399,7 @@ class Character(BaseObject, SlugMixin, ModifierMixin):
|
||||||
if attribute not in mapping.character_class.attributes_at_level(mapping.level):
|
if attribute not in mapping.character_class.attributes_at_level(mapping.level):
|
||||||
return False
|
return False
|
||||||
self.attribute_list.append(
|
self.attribute_list.append(
|
||||||
CharacterClassAttributeMap(
|
CharacterClassFeatureMap(
|
||||||
character_id=self.id,
|
character_id=self.id,
|
||||||
class_attribute_id=attribute.id,
|
class_attribute_id=attribute.id,
|
||||||
option_id=option.id,
|
option_id=option.id,
|
||||||
|
|
|
@ -9,9 +9,9 @@ from ttfrog.db.base import BaseObject
|
||||||
from ttfrog.db.schema.skill import Skill
|
from ttfrog.db.schema.skill import Skill
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"ClassAttributeMap",
|
"ClassFeatureMap",
|
||||||
"ClassAttribute",
|
"ClassFeature",
|
||||||
"ClassAttributeOption",
|
"ClassFeatureOption",
|
||||||
"CharacterClass",
|
"CharacterClass",
|
||||||
"Skill",
|
"Skill",
|
||||||
"ClassSkillMap",
|
"ClassSkillMap",
|
||||||
|
@ -36,22 +36,22 @@ class ClassSkillMap(BaseObject):
|
||||||
skill = relationship("Skill", lazy="immediate")
|
skill = relationship("Skill", lazy="immediate")
|
||||||
|
|
||||||
|
|
||||||
class ClassAttributeMap(BaseObject):
|
class ClassFeatureMap(BaseObject):
|
||||||
__tablename__ = "class_attribute_map"
|
__tablename__ = "class_attribute_map"
|
||||||
class_attribute_id: Mapped[int] = mapped_column(ForeignKey("class_attribute.id"), primary_key=True)
|
class_attribute_id: Mapped[int] = mapped_column(ForeignKey("class_attribute.id"), primary_key=True)
|
||||||
character_class_id: Mapped[int] = mapped_column(ForeignKey("character_class.id"), primary_key=True)
|
character_class_id: Mapped[int] = mapped_column(ForeignKey("character_class.id"), primary_key=True)
|
||||||
level: Mapped[int] = mapped_column(nullable=False, info={"min": 1, "max": 20}, default=1)
|
level: Mapped[int] = mapped_column(nullable=False, info={"min": 1, "max": 20}, default=1)
|
||||||
attribute = relationship("ClassAttribute", uselist=False, viewonly=True, lazy="immediate")
|
attribute = relationship("ClassFeature", uselist=False, viewonly=True, lazy="immediate")
|
||||||
|
|
||||||
|
|
||||||
class ClassAttribute(BaseObject):
|
class ClassFeature(BaseObject):
|
||||||
__tablename__ = "class_attribute"
|
__tablename__ = "class_attribute"
|
||||||
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
||||||
name: Mapped[str] = mapped_column(nullable=False)
|
name: Mapped[str] = mapped_column(nullable=False)
|
||||||
options = relationship("ClassAttributeOption", cascade="all,delete,delete-orphan", lazy="immediate")
|
options = relationship("ClassFeatureOption", cascade="all,delete,delete-orphan", lazy="immediate")
|
||||||
|
|
||||||
def add_option(self, **kwargs):
|
def add_option(self, **kwargs):
|
||||||
option = ClassAttributeOption(attribute_id=self.id, **kwargs)
|
option = ClassFeatureOption(attribute_id=self.id, **kwargs)
|
||||||
if not self.options or option not in self.options:
|
if not self.options or option not in self.options:
|
||||||
option.attribute_id = self.id
|
option.attribute_id = self.id
|
||||||
if not self.options:
|
if not self.options:
|
||||||
|
@ -65,7 +65,7 @@ class ClassAttribute(BaseObject):
|
||||||
return f"{self.id}: {self.name}"
|
return f"{self.id}: {self.name}"
|
||||||
|
|
||||||
|
|
||||||
class ClassAttributeOption(BaseObject):
|
class ClassFeatureOption(BaseObject):
|
||||||
__tablename__ = "class_attribute_option"
|
__tablename__ = "class_attribute_option"
|
||||||
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True)
|
||||||
name: Mapped[str] = mapped_column(nullable=False)
|
name: Mapped[str] = mapped_column(nullable=False)
|
||||||
|
@ -80,7 +80,7 @@ class CharacterClass(BaseObject):
|
||||||
hit_die_stat_name: Mapped[str] = mapped_column(default="")
|
hit_die_stat_name: Mapped[str] = mapped_column(default="")
|
||||||
starting_skills: int = mapped_column(nullable=False, default=0)
|
starting_skills: int = mapped_column(nullable=False, default=0)
|
||||||
|
|
||||||
attributes = relationship("ClassAttributeMap", cascade="all,delete,delete-orphan", lazy="immediate")
|
attributes = relationship("ClassFeatureMap", cascade="all,delete,delete-orphan", lazy="immediate")
|
||||||
|
|
||||||
_skills = relationship("ClassSkillMap", cascade="all,delete,delete-orphan", lazy="immediate")
|
_skills = relationship("ClassSkillMap", cascade="all,delete,delete-orphan", lazy="immediate")
|
||||||
skills = association_proxy("_skills", "skill", creator=skill_creator)
|
skills = association_proxy("_skills", "skill", creator=skill_creator)
|
||||||
|
@ -96,7 +96,7 @@ class CharacterClass(BaseObject):
|
||||||
|
|
||||||
def add_attribute(self, attribute, level=1):
|
def add_attribute(self, attribute, level=1):
|
||||||
if not self.attributes or attribute not in self.attributes:
|
if not self.attributes or attribute not in self.attributes:
|
||||||
mapping = ClassAttributeMap(character_class_id=self.id, class_attribute_id=attribute.id, level=level)
|
mapping = ClassFeatureMap(character_class_id=self.id, class_attribute_id=attribute.id, level=level)
|
||||||
if not self.attributes:
|
if not self.attributes:
|
||||||
self.attributes = [mapping]
|
self.attributes = [mapping]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -73,7 +73,7 @@ def bootstrap(db):
|
||||||
db.add_or_update([acrobatics, athletics])
|
db.add_or_update([acrobatics, athletics])
|
||||||
|
|
||||||
# classes
|
# classes
|
||||||
fighting_style = schema.ClassAttribute("Fighting Style")
|
fighting_style = schema.ClassFeature("Fighting Style")
|
||||||
fighting_style.add_option(name="Archery")
|
fighting_style.add_option(name="Archery")
|
||||||
fighting_style.add_option(name="Defense")
|
fighting_style.add_option(name="Defense")
|
||||||
db.add_or_update(fighting_style)
|
db.add_or_update(fighting_style)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user