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

563 standardize approach to distance across all v2 #567

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.1.1 on 2024-10-09 16:17

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='creatureactionattack',
name='distance_unit',
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
),
migrations.AlterField(
model_name='creatureaction',
name='legendary_cost',
field=models.SmallIntegerField(blank=True, default=None, help_text='null if not legendary, else, the number of legendary actions this costs.', null=True),
),
migrations.AlterField(
model_name='creatureactionattack',
name='long_range_ft',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='creatureactionattack',
name='range_ft',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='creatureactionattack',
name='reach_ft',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.1 on 2024-10-09 16:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0002_creatureactionattack_distance_unit_and_more'),
]

operations = [
migrations.RenameField(
model_name='creatureactionattack',
old_name='long_range_ft',
new_name='long_range',
),
migrations.RenameField(
model_name='creatureactionattack',
old_name='range_ft',
new_name='range',
),
migrations.RenameField(
model_name='creatureactionattack',
old_name='reach_ft',
new_name='reach',
),
]
19 changes: 19 additions & 0 deletions api_v2/migrations/0004_alter_size_space_diameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.1 on 2024-10-09 16:39

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0003_rename_long_range_ft_creatureactionattack_long_range_and_more'),
]

operations = [
migrations.AlterField(
model_name='size',
name='space_diameter',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]
18 changes: 18 additions & 0 deletions api_v2/migrations/0005_size_distance_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-10-09 16:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0004_alter_size_space_diameter'),
]

operations = [
migrations.AddField(
model_name='size',
name='distance_unit',
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.1.1 on 2024-10-09 16:48

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0005_size_distance_unit'),
]

operations = [
migrations.AlterField(
model_name='weapon',
name='range_long',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='weapon',
name='range_normal',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='weapon',
name='range_reach',
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.1 on 2024-10-09 16:49

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0006_alter_weapon_range_long_alter_weapon_range_normal_and_more'),
]

operations = [
migrations.RenameField(
model_name='weapon',
old_name='range_long',
new_name='long_range',
),
migrations.RenameField(
model_name='weapon',
old_name='range_normal',
new_name='range',
),
migrations.RenameField(
model_name='weapon',
old_name='range_reach',
new_name='reach',
),
]
18 changes: 18 additions & 0 deletions api_v2/migrations/0008_weapon_distance_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-10-09 16:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0007_rename_range_long_weapon_long_range_and_more'),
]

operations = [
migrations.AddField(
model_name='weapon',
name='distance_unit',
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
),
]
34 changes: 14 additions & 20 deletions api_v2/models/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .abstracts import HasDescription, HasName, Modification
from .abstracts import damage_die_count_field, damage_die_type_field
from .abstracts import damage_bonus_field, key_field
from .abstracts import distance_field, distance_unit_field
from .object import Object
from .condition import Condition
from .damagetype import DamageType
Expand Down Expand Up @@ -202,7 +203,7 @@ class CreatureAction(HasName, HasDescription):
blank=True,
null=True,
default=None,
help_text='0 if not legendary, else, the number of legendary actions this costs.'
help_text='null if not legendary, else, the number of legendary actions this costs.'
)


Expand All @@ -212,6 +213,9 @@ def as_text(self):

return text

def attacks(self):
return self.creatureactionattack_set


class CreatureActionAttack(HasName):
"""Describes an attack action used by a creature."""
Expand All @@ -234,26 +238,16 @@ class CreatureActionAttack(HasName):
help_text='Attack roll modifier.'
)

reach_ft = models.SmallIntegerField(
blank=True,
null=True,
validators=[MinValueValidator(0)],
help_text='Reach for melee attacks, in feet.'
)
reach = distance_field()
range = distance_field()
long_range = distance_field()
distance_unit = distance_unit_field()

range_ft = models.SmallIntegerField(
blank=True,
null=True,
validators=[MinValueValidator(0)],
help_text='Normal range for ranged attacks, in feet.'
)

long_range_ft = models.SmallIntegerField(
blank=True,
null=True,
validators=[MinValueValidator(0)],
help_text='Long range for ranged attacks, in feet.'
)
@property
def get_distance_unit(self):
if self.distance_unit is None:
return self.parent.parent.document.distance_unit
return self.distance_unit

target_creature_only = models.BooleanField(
help_text='If an attack can target creatures only and not objects.'
Expand Down
16 changes: 9 additions & 7 deletions api_v2/models/size.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.core.validators import MinValueValidator

from .abstracts import HasName
from .abstracts import distance_field, distance_unit_field
from .document import FromDocument

class Size(HasName, FromDocument):
Expand All @@ -16,9 +16,11 @@ class Size(HasName, FromDocument):
unique=True,
help_text='Ranking of the size, smallest has the lowest values.')

space_diameter = models.DecimalField(
default=0,
max_digits=10,
decimal_places=3,
validators=[MinValueValidator(0)],
help_text='Number representing the diameter of the space controlled by the object.')
space_diameter = distance_field()
distance_unit = distance_unit_field()

@property
def get_distance_unit(self):
if self.distance_unit is None:
return self.document.distance_unit
return self.distance_unit
30 changes: 13 additions & 17 deletions api_v2/models/weapon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.validators import MinValueValidator

from .abstracts import HasName
from .abstracts import distance_field, distance_unit_field
from .document import FromDocument


Expand Down Expand Up @@ -35,25 +36,20 @@ class Weapon(HasName, FromDocument):
help_text="""The damage dice when attacking using versatile.
A value of 0 means that the weapon does not have the versatile property.""")

range_reach = models.IntegerField(
null=False,
default=5,
validators=[MinValueValidator(0)],
help_text='The range of the weapon when making a melee attack.')
reach = distance_field()

range_normal = models.IntegerField(
null=False,
default=0,
validators=[MinValueValidator(0)],
help_text="""The normal range of a ranged weapon attack.
A value of 0 means that the weapon cannot be used for a ranged attack.""")
range = distance_field()

long_range = distance_field()

distance_unit = distance_unit_field()

@property
def get_distance_unit(self):
if self.distance_unit is None:
return self.document.distance_unit
return self.distance_unit

range_long = models.IntegerField(
null=False,
default=0,
validators=[MinValueValidator(0)],
help_text="""The long range of a ranged weapon attack.
A value of 0 means that the weapon cannot be used for a long ranged attack.""")

is_finesse = models.BooleanField(
null=False,
Expand Down
Loading
Loading