Skip to content

Commit

Permalink
exposing spell data.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjohnson committed Jun 21, 2024
1 parent 942e893 commit 8415636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api_v2/models/spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class Spell(HasName, HasDescription, FromDocument):
choices = SPELL_EFFECT_SHAPE_CHOICES,
help_text = 'The shape of the area of effect.')


shape_size = distance_field()
shape_size_unit = distance_unit_field()

Expand All @@ -129,7 +128,16 @@ class Spell(HasName, HasDescription, FromDocument):
def casting_options(self):
"""Options for casting the spell."""
return self.spellcastingoption_set


def get_shape_size_unit(self):
if self.shape_size_unit is None:
return self.document.distance_unit
return self.shape_size_unit

def get_range_unit(self):
if self.range_unit is None:
return self.document.distance_unit
return self.range_unit

class SpellCastingOption(models.Model):
"""An object representing an alternative way to cast a spell."""
Expand Down
10 changes: 10 additions & 0 deletions api_v2/serializers/spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class SpellSerializer(GameContentSerializer):
casting_options = SpellCastingOptionSerializer(many=True)
school = SpellSchoolSerializer()

range_unit = serializers.SerializerMethodField()
shape_size_unit = serializers.SerializerMethodField()

def get_range_unit(self, spell):
return spell.get_range_unit()

def get_shape_size_unit(self, spell):
return spell.get_shape_size_unit()


class Meta:
model = models.Spell
fields = '__all__'

0 comments on commit 8415636

Please sign in to comment.