Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creatureaction exposed #547

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api_v2/models/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ def experience_points(self):
return None


@property
def actions(self):
"""Returns the set of actions that are related to this creature."""
return self.creatureaction_set


class CreatureAction(HasName, HasDescription):
"""Describes an action available to a creature."""
key = key_field()
Expand Down
27 changes: 19 additions & 8 deletions api_v2/serializers/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def make_attack_obj(attack):

def make_action_obj(action):
'''Structures an object in a way that can be consistently referenced.'''
return action
obj = { 'name': action.name, 'desc': action.desc }

match action.uses_type:
Expand All @@ -97,6 +98,14 @@ def make_action_obj(action):
return obj


class CreatureActionSerializer(serializers.ModelSerializer):
key = serializers.ReadOnlyField()

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


class CreatureTypeSerializer(GameContentSerializer):
'''Serializer for the Creature Type object'''
key = serializers.ReadOnlyField()
Expand All @@ -117,7 +126,7 @@ class CreatureSerializer(GameContentSerializer):
saving_throws_all = serializers.SerializerMethodField()
skill_bonuses = serializers.SerializerMethodField()
skill_bonuses_all = serializers.SerializerMethodField()
actions = serializers.SerializerMethodField()
actions = CreatureActionSerializer(many=True, context={'request': {}})
speed = serializers.SerializerMethodField()
speed_all = serializers.SerializerMethodField()
challenge_rating_text = serializers.SerializerMethodField()
Expand Down Expand Up @@ -225,13 +234,13 @@ def get_speed_all(self, creature):
'''Implicit speed helper method.'''
return creature.get_speed_all()

def get_actions(self, creature):
'''Actions helper method.'''
result = []
for action in creature.creatureaction_set.all():
action_obj = make_action_obj(action)
result.append(action_obj)
return result
# def get_actions(self, creature):
# '''Actions helper method.'''
# result = []
# for action in creature.creatureaction_set.all():
# action_obj = make_action_obj(action)
# result.append(action_obj)
# return result

def get_challenge_rating_text(self, creature):
return creature.challenge_rating_text
Expand All @@ -249,3 +258,5 @@ class Meta:
'''Meta options for serializer.'''
model = models.CreatureSet
fields = '__all__'


14 changes: 14 additions & 0 deletions data/v2/en-publishing/mmenag/CreatureAction.json
Original file line number Diff line number Diff line change
Expand Up @@ -32759,6 +32759,20 @@
"legendary_cost": 1
}
},
{
"model": "api_v2.creatureaction",
"pk": "mmenag_titanic-dragon-turtle_legendary-tail",
"fields": {
"name": "Tail",
"desc": "The dragon turtle makes a tail attack.",
"parent": "mmenag_titanic-dragon-turtle",
"uses_type": null,
"uses_param": null,
"action_type": "LEGENDARY_ACTION",
"form_condition": null,
"legendary_cost": 2
}
},
{
"model": "api_v2.creatureaction",
"pk": "mmenag_titanic-dragon-turtle_lightning-storm",
Expand Down
Loading
Loading