diff --git a/src/character/admin.py b/src/character/admin.py index 99fab80..2cbcf10 100644 --- a/src/character/admin.py +++ b/src/character/admin.py @@ -106,7 +106,7 @@ class CharacterAdmin(admin.ModelAdmin): "Combat", {"fields": ["initiative", "attack_melee", "attack_range", "attack_magic"]}, ), - ("Vitalité", {"fields": ["health_max", "health_remaining"]}), + ("Vitalité", {"fields": [("health_max", "health_remaining")]}), ("Défense", {"fields": ["armor", "shield", "defense_misc", "defense"]}), ( "Armes & équipement", @@ -120,8 +120,12 @@ class CharacterAdmin(admin.ModelAdmin): ), ("Race", {"fields": ["racial_capability"]}), ("Capacités", {"fields": ["capabilities"]}), - ("Chance", {"fields": ["luck_points_max", "luck_points_remaining"]}), - ("Mana", {"fields": ["mana_max", "mana_remaining"]}), + ("Chance", {"fields": [("luck_points_max", "luck_points_remaining")]}), + ("Mana", {"fields": [("mana_max", "mana_remaining")]}), + ( + "Récupération", + {"fields": [("recovery_points_max", "recovery_points_remaining")]}, + ), ("Notes", {"fields": ["notes"]}), ] readonly_fields = [ @@ -137,7 +141,7 @@ class CharacterAdmin(admin.ModelAdmin): "attack_magic", "defense", "mana_max", - "mana_remaining", + "recovery_points_max", ] filter_horizontal = [ "capabilities", diff --git a/src/character/migrations/0015_character_recovery_points_remaining.py b/src/character/migrations/0015_character_recovery_points_remaining.py new file mode 100644 index 0000000..c9f08fb --- /dev/null +++ b/src/character/migrations/0015_character_recovery_points_remaining.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.2 on 2022-10-30 20:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0014_remove_character_mana_consumed_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="character", + name="recovery_points_remaining", + field=models.PositiveSmallIntegerField( + default=5, verbose_name="points de récupération restants" + ), + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index 2c6ec14..43cdd14 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0014_remove_character_mana_consumed_and_more +0015_character_recovery_points_remaining diff --git a/src/character/models/character.py b/src/character/models/character.py index 8aba072..2b71650 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -138,6 +138,10 @@ class Character(models.Model): money_pa = models.PositiveSmallIntegerField(default=0, verbose_name="PA") money_pc = models.PositiveSmallIntegerField(default=0, verbose_name="PC") + recovery_points_remaining = models.PositiveSmallIntegerField( + default=5, verbose_name="points de récupération restants" + ) + notes = models.TextField(blank=True, verbose_name="notes") objects = CharacterManager() @@ -227,6 +231,10 @@ class Character(models.Model): def imc(self) -> float: return self.weight / (self.height_m**2) + @property + def recovery_points_max(self) -> int: + return 5 + def get_capabilities_by_path(self) -> dict[Path, list[Capability]]: capabilities_by_path = collections.defaultdict(list) for capability in self.capabilities.all(): diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html index ece3020..9456cf2 100644 --- a/src/character/templates/character/view.html +++ b/src/character/templates/character/view.html @@ -185,91 +185,114 @@ {{ character.mana_remaining }} - - - - - -
-
-
-
{{ character.racial_capability.name }}
-
-

{{ character.racial_capability.description|capfirst }}

-
+ + PR max + {{ character.recovery_points_max }} + + + + PR restants +
+ + +
+ + {{ character.recovery_points_remaining }} + + +
-
- - - - - - - - - - - {% for weapon in character.weapons.all %} - - - - - - - {% empty %} - - - - {% endfor %} - -
ArmeAttaqueDMSpécial
{{ weapon.name }}1D20 +{{ weapon.damage }}{{ weapon.special }}
Aucune arme
-
-
-
-
-
-
Équipement
-
- {% include "character/equipment_display.html" %} -
- -
-
-
-

Voies & Capacités

-
- {% for path, capabilities in character.get_capabilities_by_path.items %} -
+
+
-
{{ path.display_name }}
- {% if path.notes %} -
{{ path.notes }}
- {% endif %} -
    - {% for capability in capabilities %} -
  • - - {{ capability.rank }}. - {{ capability.name }} - {% if capability.spell %}{% endif %} - {% if capability.limited %}{% endif %} -
    - {{ capability.description }} -
  • - {% endfor %} -
+
{{ character.racial_capability.name }}
+
+

{{ character.racial_capability.description|capfirst }}

+
- {% endfor %} -
-

Notes

-
- {% include "character/notes_display.html" %} -
+
+ + + + + + + + + + + {% for weapon in character.weapons.all %} + + + + + + + {% empty %} + + + + {% endfor %} + +
ArmeAttaqueDMSpécial
{{ weapon.name }}1D20 +{{ weapon.damage }}{{ weapon.special }}
Aucune arme
+
+
+
+
+
+
Équipement
+
+ {% include "character/equipment_display.html" %} +
+ +
+
+
+

Voies & Capacités

+
+ {% for path, capabilities in character.get_capabilities_by_path.items %} +
+
+
{{ path.display_name }}
+ {% if path.notes %} +
{{ path.notes }}
+ {% endif %} +
    + {% for capability in capabilities %} +
  • + + {{ capability.rank }}. + {{ capability.name }} + {% if capability.spell %}{% endif %} + {% if capability.limited %}{% endif %} +
    + {{ capability.description }} +
  • + {% endfor %} +
+
+
+ {% endfor %} +
+

Notes

+
+ {% include "character/notes_display.html" %} +
{% endblock %} diff --git a/src/character/urls.py b/src/character/urls.py index aaca627..c35f445 100644 --- a/src/character/urls.py +++ b/src/character/urls.py @@ -7,6 +7,11 @@ urlpatterns = [ path("/", views.character_view, name="view"), path("/health_change", views.character_health_change, name="health_change"), path("/mana_change", views.character_mana_change, name="mana_change"), + path( + "/recovery_points_change", + views.character_recovery_points_change, + name="recovery_points_change", + ), path("/notes_change", views.character_notes_change, name="notes_change"), path( "/equipment_change", diff --git a/src/character/views.py b/src/character/views.py index 876ad50..e5e110d 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -40,6 +40,19 @@ def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse: return HttpResponse(value) +@login_required +def character_recovery_points_change(request: WSGIRequest, pk: int) -> HttpResponse: + character = get_object_or_404( + Character.objects.only("recovery_points_remaining"), pk=pk + ) + value = get_updated_value( + request, character.recovery_points_remaining, character.recovery_points_max + ) + character.recovery_points_remaining = value + character.save(update_fields=["recovery_points_remaining"]) + return HttpResponse(value) + + def get_updated_value( request: WSGIRequest, remaining_value: int, max_value: int ) -> int: