Add luck points

This commit is contained in:
Gabriel Augendre 2022-10-30 22:02:21 +01:00
parent aa5fb92640
commit 991de5a5bb
3 changed files with 132 additions and 82 deletions

View file

@ -211,91 +211,123 @@
</div>
</th>
<td id="recovery-points-remaining">{{ character.recovery_points_remaining }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<div class="card">
<h5 class="card-header">{{ character.racial_capability.name }}</h5>
<div class="card-body">
<p class="card-text">{{ character.racial_capability.description|capfirst }}</p>
</div>
<tr>
<th scope="row">PC max</th>
<td>{{ character.luck_points_max }}</td>
</tr>
<tr>
<th scope="row"
data-bs-toggle="tooltip"
data-bs-placement="top"
data-bs-title="[1 dé de vie + {{ character.modifier_constitution|add:character.level }}] PV">
PC restants
<div class="btn-group btn-group-sm" role="group">
<button
hx-get="{% url "character:luck_points_change" pk=character.pk %}?value=-1"
hx-target="#luck-points-remaining"
hx-swap="innerHTML"
type="button"
class="btn btn-danger">-</button>
<button
hx-get="{% url "character:luck_points_change" pk=character.pk %}?value=1"
hx-target="#luck-points-remaining"
hx-swap="innerHTML"
type="button"
class="btn btn-success">+</button>
<button
hx-get="{% url "character:luck_points_change" pk=character.pk %}?value=max"
hx-target="#luck-points-remaining"
hx-swap="innerHTML"
type="button"
class="btn btn-outline-success">max</button>
</div>
</th>
<td id="luck-points-remaining">{{ character.luck_points_remaining }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-8">
<table class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Arme</th>
<th scope="col">Attaque</th>
<th scope="col">DM</th>
<th scope="col">Spécial</th>
</tr>
</thead>
<tbody class="table-group-divider">
{% for weapon in character.weapons.all %}
<tr>
<th scope="row">{{ weapon.name }}</th>
<td>1D20 +</td>
<td>{{ weapon.damage }}</td>
<td>{{ weapon.special }}</td>
</tr>
{% empty %}
<tr>
<td colspan="4">Aucune arme</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<h5 class="card-header">Équipement</h5>
<div class="card-body" id="equipment">
{% include "character/equipment_display.html" %}
</div>
<div class="card-footer">
{{ character.money_pp }} pp,
{{ character.money_po }} po,
{{ character.money_pa }} pa,
{{ character.money_pc }} pc
</div>
</div>
</div>
</div>
<h4 class="mt-3">Voies & Capacités</h4>
<div class="row gy-3">
{% for path, capabilities in character.get_capabilities_by_path.items %}
<div class="col-xl-3 col-md-6">
<div class="row">
<div class="col-md-4 mb-3">
<div class="card">
<h5 class="card-header">{{ path.display_name }}</h5>
{% if path.notes %}
<div class="card-body text-bg-light">{{ path.notes }}</div>
{% endif %}
<ul class="list-group list-group-flush">
{% for capability in capabilities %}
<li class="list-group-item">
<strong>
{{ capability.rank }}.
{{ capability.name }}
{% if capability.spell %}<i class="fa-solid fa-hand-sparkles"></i>{% endif %}
{% if capability.limited %}<i class="fa-solid fa-handcuffs"></i>{% endif %}
</strong><br>
{{ capability.description }}
</li>
{% endfor %}
</ul>
<h5 class="card-header">{{ character.racial_capability.name }}</h5>
<div class="card-body">
<p class="card-text">{{ character.racial_capability.description|capfirst }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
<h4 class="mt-3">Notes</h4>
<div class="row" id="notes">
{% include "character/notes_display.html" %}
</div>
<div class="col-md-8">
<table class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Arme</th>
<th scope="col">Attaque</th>
<th scope="col">DM</th>
<th scope="col">Spécial</th>
</tr>
</thead>
<tbody class="table-group-divider">
{% for weapon in character.weapons.all %}
<tr>
<th scope="row">{{ weapon.name }}</th>
<td>1D20 +</td>
<td>{{ weapon.damage }}</td>
<td>{{ weapon.special }}</td>
</tr>
{% empty %}
<tr>
<td colspan="4">Aucune arme</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<h5 class="card-header">Équipement</h5>
<div class="card-body" id="equipment">
{% include "character/equipment_display.html" %}
</div>
<div class="card-footer">
{{ character.money_pp }} pp,
{{ character.money_po }} po,
{{ character.money_pa }} pa,
{{ character.money_pc }} pc
</div>
</div>
</div>
</div>
<h4 class="mt-3">Voies & Capacités</h4>
<div class="row gy-3">
{% for path, capabilities in character.get_capabilities_by_path.items %}
<div class="col-xl-3 col-md-6">
<div class="card">
<h5 class="card-header">{{ path.display_name }}</h5>
{% if path.notes %}
<div class="card-body text-bg-light">{{ path.notes }}</div>
{% endif %}
<ul class="list-group list-group-flush">
{% for capability in capabilities %}
<li class="list-group-item">
<strong>
{{ capability.rank }}.
{{ capability.name }}
{% if capability.spell %}<i class="fa-solid fa-hand-sparkles"></i>{% endif %}
{% if capability.limited %}<i class="fa-solid fa-handcuffs"></i>{% endif %}
</strong><br>
{{ capability.description }}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
<h4 class="mt-3">Notes</h4>
<div class="row" id="notes">
{% include "character/notes_display.html" %}
</div>
{% endblock %}

View file

@ -12,6 +12,11 @@ urlpatterns = [
views.character_recovery_points_change,
name="recovery_points_change",
),
path(
"<int:pk>/luck_points_change",
views.character_luck_points_change,
name="luck_points_change",
),
path("<int:pk>/notes_change", views.character_notes_change, name="notes_change"),
path(
"<int:pk>/equipment_change",

View file

@ -53,6 +53,19 @@ def character_recovery_points_change(request: WSGIRequest, pk: int) -> HttpRespo
return HttpResponse(value)
@login_required
def character_luck_points_change(request: WSGIRequest, pk: int) -> HttpResponse:
character = get_object_or_404(
Character.objects.only("luck_points_remaining", "luck_points_max"), pk=pk
)
value = get_updated_value(
request, character.luck_points_remaining, character.luck_points_max
)
character.luck_points_remaining = value
character.save(update_fields=["luck_points_remaining"])
return HttpResponse(value)
def get_updated_value(
request: WSGIRequest, remaining_value: int, max_value: int
) -> int: