mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Add defense misc
This commit is contained in:
parent
5596c7beda
commit
a03cda1771
3 changed files with 63 additions and 3 deletions
|
@ -60,7 +60,7 @@
|
|||
</table>
|
||||
</div>
|
||||
<div class="col-sm-6 col-lg-6 col-xl">
|
||||
<table class="table table-hover table-sm">
|
||||
<table id="fight-table" class="table table-hover table-sm">
|
||||
<thead>
|
||||
<tr><th scope="col" colspan="2">Combat</th></tr>
|
||||
</thead>
|
||||
|
@ -97,11 +97,45 @@
|
|||
{{ character.attack_magic|modifier }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
Divers défense
|
||||
<div class="btn-group btn-group-sm float-end" role="group">
|
||||
<button
|
||||
hx-get="{% url "character:defense_misc_change" pk=character.pk %}?value=ko"
|
||||
hx-target="#defense-misc"
|
||||
hx-swap="innerHTML"
|
||||
type="button"
|
||||
class="btn btn-outline-danger"><i class="fa-solid fa-battery-empty"></i></button>
|
||||
<button
|
||||
hx-get="{% url "character:defense_misc_change" pk=character.pk %}?value=-1"
|
||||
hx-target="#defense-misc"
|
||||
hx-swap="innerHTML"
|
||||
type="button"
|
||||
class="btn btn-danger"><i class="fa-solid fa-minus"></i></button>
|
||||
<button
|
||||
hx-get="{% url "character:defense_misc_change" pk=character.pk %}?value=1"
|
||||
hx-target="#defense-misc"
|
||||
hx-swap="innerHTML"
|
||||
type="button"
|
||||
class="btn btn-success"><i class="fa-solid fa-plus"></i></button>
|
||||
<button
|
||||
type="button"
|
||||
disabled
|
||||
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||
</div>
|
||||
</th>
|
||||
<td id="defense-misc">
|
||||
{{ character.defense_misc }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Défense</th>
|
||||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="left"
|
||||
data-bs-title="10 + {{ character.armor }} (armure) + {{ character.shield }} (bouclier) + {{ character.modifier_dexterity }} (mod. DEX) + {{ character.defense_misc }} (divers)">
|
||||
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 }}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -18,6 +18,12 @@ urlpatterns = [
|
|||
name="luck_points_change",
|
||||
),
|
||||
path("<int:pk>/notes_change", views.character_notes_change, name="notes_change"),
|
||||
path("<int:pk>/get_defense", views.character_get_defense, name="get_defense"),
|
||||
path(
|
||||
"<int:pk>/defense_misc_change",
|
||||
views.character_defense_misc_change,
|
||||
name="defense_misc_change",
|
||||
),
|
||||
path(
|
||||
"<int:pk>/equipment_change",
|
||||
views.character_equipment_change,
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue