diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html index 54eae64..712983d 100644 --- a/src/character/templates/character/view.html +++ b/src/character/templates/character/view.html @@ -60,7 +60,7 @@
- +
@@ -97,11 +97,45 @@ {{ character.attack_magic|modifier }} + + + + diff --git a/src/character/urls.py b/src/character/urls.py index f1944f0..d36c2b8 100644 --- a/src/character/urls.py +++ b/src/character/urls.py @@ -18,6 +18,12 @@ urlpatterns = [ name="luck_points_change", ), path("/notes_change", views.character_notes_change, name="notes_change"), + path("/get_defense", views.character_get_defense, name="get_defense"), + path( + "/defense_misc_change", + views.character_defense_misc_change, + name="defense_misc_change", + ), path( "/equipment_change", views.character_equipment_change, diff --git a/src/character/views.py b/src/character/views.py index 3ab4c6a..69c330d 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -2,6 +2,7 @@ from django.contrib.auth.decorators import login_required from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse from django.shortcuts import get_object_or_404, render +from django_htmx.http import trigger_client_event from character.models import Character @@ -56,6 +57,16 @@ def character_recovery_points_change(request: WSGIRequest, pk: int) -> HttpRespo return HttpResponse(value) +@login_required +def character_defense_misc_change(request: WSGIRequest, pk: int) -> HttpResponse: + character = get_object_or_404(Character.objects.only("defense_misc"), pk=pk) + value = get_updated_value(request, character.defense_misc, float("inf")) + character.defense_misc = value + character.save(update_fields=["defense_misc"]) + response = HttpResponse(value) + return trigger_client_event(response, "update_defense", {}) + + @login_required def character_luck_points_change(request: WSGIRequest, pk: int) -> HttpResponse: character = get_object_or_404( @@ -70,7 +81,7 @@ def character_luck_points_change(request: WSGIRequest, pk: int) -> HttpResponse: def get_updated_value( - request: WSGIRequest, remaining_value: int, max_value: int + request: WSGIRequest, remaining_value: int, max_value: int | float ) -> int: form_value = request.GET.get("value") if form_value == "ko": @@ -85,6 +96,15 @@ def get_updated_value( return remaining_value +@login_required +def character_get_defense(request: WSGIRequest, pk: int) -> HttpResponse: + character = get_object_or_404( + Character.objects.only("defense_misc", "armor", "shield", "value_dexterity"), + pk=pk, + ) + return HttpResponse(character.defense) + + @login_required def character_notes_change(request: WSGIRequest, pk: int) -> HttpResponse: return update_text_field(request, pk, "notes")
Combat
+ Divers défense +
+ + + + +
+
+ {{ character.defense_misc }} +
Défense + data-bs-title="10 + {{ character.armor }} (armure) + {{ character.shield }} (bouclier) + {{ character.modifier_dexterity }} (mod. DEX) + {{ character.defense_misc }} (divers)" + hx-get="{% url "character:get_defense" pk=character.pk %}" + hx-trigger="update_defense from:#fight-table"> {{ character.defense }}