Skip to content

Commit 8bffdc9

Browse files
Merge pull request open5e#567 from open5e/563-standardize-approach-to-distance-across-all-v2
563 standardize approach to distance across all v2
2 parents 0b151c9 + ada1563 commit 8bffdc9

31 files changed

+17690
-13218
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:17
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api_v2', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='creatureactionattack',
16+
name='distance_unit',
17+
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
18+
),
19+
migrations.AlterField(
20+
model_name='creatureaction',
21+
name='legendary_cost',
22+
field=models.SmallIntegerField(blank=True, default=None, help_text='null if not legendary, else, the number of legendary actions this costs.', null=True),
23+
),
24+
migrations.AlterField(
25+
model_name='creatureactionattack',
26+
name='long_range_ft',
27+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
28+
),
29+
migrations.AlterField(
30+
model_name='creatureactionattack',
31+
name='range_ft',
32+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
33+
),
34+
migrations.AlterField(
35+
model_name='creatureactionattack',
36+
name='reach_ft',
37+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
38+
),
39+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:18
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0002_creatureactionattack_distance_unit_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='creatureactionattack',
15+
old_name='long_range_ft',
16+
new_name='long_range',
17+
),
18+
migrations.RenameField(
19+
model_name='creatureactionattack',
20+
old_name='range_ft',
21+
new_name='range',
22+
),
23+
migrations.RenameField(
24+
model_name='creatureactionattack',
25+
old_name='reach_ft',
26+
new_name='reach',
27+
),
28+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:39
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api_v2', '0003_rename_long_range_ft_creatureactionattack_long_range_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='size',
16+
name='space_diameter',
17+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
18+
),
19+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:44
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0004_alter_size_space_diameter'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='size',
15+
name='distance_unit',
16+
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
17+
),
18+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:48
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('api_v2', '0005_size_distance_unit'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='weapon',
16+
name='range_long',
17+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
18+
),
19+
migrations.AlterField(
20+
model_name='weapon',
21+
name='range_normal',
22+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
23+
),
24+
migrations.AlterField(
25+
model_name='weapon',
26+
name='range_reach',
27+
field=models.FloatField(blank=True, help_text='Used to measure distance.', null=True, validators=[django.core.validators.MinValueValidator(0)]),
28+
),
29+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:49
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0006_alter_weapon_range_long_alter_weapon_range_normal_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='weapon',
15+
old_name='range_long',
16+
new_name='long_range',
17+
),
18+
migrations.RenameField(
19+
model_name='weapon',
20+
old_name='range_normal',
21+
new_name='range',
22+
),
23+
migrations.RenameField(
24+
model_name='weapon',
25+
old_name='range_reach',
26+
new_name='reach',
27+
),
28+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.1 on 2024-10-09 16:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0007_rename_range_long_weapon_long_range_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='weapon',
15+
name='distance_unit',
16+
field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True),
17+
),
18+
]

api_v2/models/creature.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .abstracts import HasDescription, HasName, Modification
99
from .abstracts import damage_die_count_field, damage_die_type_field
1010
from .abstracts import damage_bonus_field, key_field
11+
from .abstracts import distance_field, distance_unit_field
1112
from .object import Object
1213
from .condition import Condition
1314
from .damagetype import DamageType
@@ -202,7 +203,7 @@ class CreatureAction(HasName, HasDescription):
202203
blank=True,
203204
null=True,
204205
default=None,
205-
help_text='0 if not legendary, else, the number of legendary actions this costs.'
206+
help_text='null if not legendary, else, the number of legendary actions this costs.'
206207
)
207208

208209

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

213214
return text
214215

216+
def attacks(self):
217+
return self.creatureactionattack_set
218+
215219

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

237-
reach_ft = models.SmallIntegerField(
238-
blank=True,
239-
null=True,
240-
validators=[MinValueValidator(0)],
241-
help_text='Reach for melee attacks, in feet.'
242-
)
241+
reach = distance_field()
242+
range = distance_field()
243+
long_range = distance_field()
244+
distance_unit = distance_unit_field()
243245

244-
range_ft = models.SmallIntegerField(
245-
blank=True,
246-
null=True,
247-
validators=[MinValueValidator(0)],
248-
help_text='Normal range for ranged attacks, in feet.'
249-
)
250-
251-
long_range_ft = models.SmallIntegerField(
252-
blank=True,
253-
null=True,
254-
validators=[MinValueValidator(0)],
255-
help_text='Long range for ranged attacks, in feet.'
256-
)
246+
@property
247+
def get_distance_unit(self):
248+
if self.distance_unit is None:
249+
return self.parent.parent.document.distance_unit
250+
return self.distance_unit
257251

258252
target_creature_only = models.BooleanField(
259253
help_text='If an attack can target creatures only and not objects.'

api_v2/models/size.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.db import models
2-
from django.core.validators import MinValueValidator
32

43
from .abstracts import HasName
4+
from .abstracts import distance_field, distance_unit_field
55
from .document import FromDocument
66

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

19-
space_diameter = models.DecimalField(
20-
default=0,
21-
max_digits=10,
22-
decimal_places=3,
23-
validators=[MinValueValidator(0)],
24-
help_text='Number representing the diameter of the space controlled by the object.')
19+
space_diameter = distance_field()
20+
distance_unit = distance_unit_field()
21+
22+
@property
23+
def get_distance_unit(self):
24+
if self.distance_unit is None:
25+
return self.document.distance_unit
26+
return self.distance_unit

api_v2/models/weapon.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.validators import MinValueValidator
55

66
from .abstracts import HasName
7+
from .abstracts import distance_field, distance_unit_field
78
from .document import FromDocument
89

910

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

38-
range_reach = models.IntegerField(
39-
null=False,
40-
default=5,
41-
validators=[MinValueValidator(0)],
42-
help_text='The range of the weapon when making a melee attack.')
39+
reach = distance_field()
4340

44-
range_normal = models.IntegerField(
45-
null=False,
46-
default=0,
47-
validators=[MinValueValidator(0)],
48-
help_text="""The normal range of a ranged weapon attack.
49-
A value of 0 means that the weapon cannot be used for a ranged attack.""")
41+
range = distance_field()
42+
43+
long_range = distance_field()
44+
45+
distance_unit = distance_unit_field()
46+
47+
@property
48+
def get_distance_unit(self):
49+
if self.distance_unit is None:
50+
return self.document.distance_unit
51+
return self.distance_unit
5052

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

5854
is_finesse = models.BooleanField(
5955
null=False,

0 commit comments

Comments
 (0)