diff --git a/src/character/templates/character/character_details.html b/src/character/templates/character/character_details.html index 67cfd41..5b2b099 100644 --- a/src/character/templates/character/character_details.html +++ b/src/character/templates/character/character_details.html @@ -269,48 +269,60 @@ {{ character.health_remaining }} / {{ character.health_max }} - - Points de mana - {% if character|managed_by:user %} -
- - - - -
- {% endif %} - - - {{ character.mana_remaining }} / {{ character.mana_max }} + + {% include "character/snippets/character_details/health_bar.html" %} + {% if character.mana_max > 0 %} + + + Points de mana + {% if character|managed_by:user %} +
+ + + + +
+ {% endif %} + + + {{ character.mana_remaining }} / {{ character.mana_max }} + + + + + {% include "character/snippets/character_details/mana_bar.html" %} + + + {% endif %} Points de récup. diff --git a/src/character/templates/character/snippets/character_details/health_bar.html b/src/character/templates/character/snippets/character_details/health_bar.html new file mode 100644 index 0000000..ed1b7e9 --- /dev/null +++ b/src/character/templates/character/snippets/character_details/health_bar.html @@ -0,0 +1,11 @@ +{% load character_extras %} +
+
+ PV : {{ character.health_remaining }}/{{ character.health_max }} +
+
diff --git a/src/character/templates/character/snippets/character_details/mana_bar.html b/src/character/templates/character/snippets/character_details/mana_bar.html new file mode 100644 index 0000000..64d32d5 --- /dev/null +++ b/src/character/templates/character/snippets/character_details/mana_bar.html @@ -0,0 +1,11 @@ +{% load character_extras %} +
+
+ PM : {{ character.mana_remaining }}/{{ character.mana_max }} +
+
diff --git a/src/character/templates/character/snippets/characters_list/character_card.html b/src/character/templates/character/snippets/characters_list/character_card.html index d7b565d..892f77b 100644 --- a/src/character/templates/character/snippets/characters_list/character_card.html +++ b/src/character/templates/character/snippets/characters_list/character_card.html @@ -9,16 +9,10 @@ {{ character.race.name }} {{ character.profile.name }} niv. {{ character.level }}
{{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg

-
-
- PV : {{ character.health_remaining }}/{{ character.health_max }} -
-
+ {% include "character/snippets/character_details/health_bar.html" %} {% if character.mana_max > 0 %} -
-
- PM : {{ character.mana_remaining }}/{{ character.mana_max }} -
+
+ {% include "character/snippets/character_details/mana_bar.html" %}
{% endif %}

diff --git a/src/character/urls.py b/src/character/urls.py index 05a80c6..e22cc7e 100644 --- a/src/character/urls.py +++ b/src/character/urls.py @@ -38,6 +38,16 @@ urlpatterns = [ views.character_armor_change, name="armor_change", ), + path( + "/get_health_bar/", + views.character_get_health_bar, + name="get_health_bar", + ), + path( + "/get_mana_bar/", + views.character_get_mana_bar, + name="get_mana_bar", + ), path( "/get_initiative/", views.character_get_initiative, diff --git a/src/character/views.py b/src/character/views.py index 4ecd665..af99733 100644 --- a/src/character/views.py +++ b/src/character/views.py @@ -80,7 +80,8 @@ def character_health_change(request, pk: int): value = get_updated_value(request, character.health_remaining, character.health_max) character.health_remaining = value character.save(update_fields=["health_remaining"]) - return HttpResponse(value) + response = HttpResponse(value) + return trigger_client_event(response, "refresh_health_bar", {}) @login_required @@ -94,7 +95,8 @@ def character_mana_change(request, pk: int): value = get_updated_value(request, character.mana_remaining, character.mana_max) character.mana_remaining = value character.save(update_fields=["mana_remaining"]) - return HttpResponse(value) + response = HttpResponse(value) + return trigger_client_event(response, "refresh_mana_bar", {}) @login_required @@ -200,6 +202,32 @@ def character_get_defense(request, pk: int): return HttpResponse(character.defense) +@login_required +def character_get_health_bar(request, pk: int): + character = get_object_or_404( + Character.objects.managed_by(request.user).only( + "health_max", "health_remaining" + ), + pk=pk, + ) + context = {"character": character} + return render( + request, "character/snippets/character_details/health_bar.html", context + ) + + +@login_required +def character_get_mana_bar(request, pk: int): + character = get_object_or_404( + Character.objects.managed_by(request.user).select_related("profile"), + pk=pk, + ) + context = {"character": character} + return render( + request, "character/snippets/character_details/mana_bar.html", context + ) + + @login_required def character_get_initiative(request, pk: int): character = get_object_or_404(