mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Update mana
This commit is contained in:
parent
237cfbe141
commit
1a8dd70847
6 changed files with 75 additions and 9 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 4.1.2 on 2022-10-30 16:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("character", "0013_character_money_pa_character_money_pc_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name="character",
|
||||||
|
name="mana_consumed",
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="character",
|
||||||
|
name="mana_remaining",
|
||||||
|
field=models.PositiveSmallIntegerField(
|
||||||
|
default=0, verbose_name="mana restant"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
0013_character_money_pa_character_money_pc_and_more
|
0014_remove_character_mana_consumed_and_more
|
||||||
|
|
|
@ -129,8 +129,8 @@ class Character(models.Model):
|
||||||
verbose_name="points de chance restants"
|
verbose_name="points de chance restants"
|
||||||
)
|
)
|
||||||
|
|
||||||
mana_consumed = models.PositiveSmallIntegerField(
|
mana_remaining = models.PositiveSmallIntegerField(
|
||||||
default=0, verbose_name="mana utilisé"
|
default=0, verbose_name="mana restant"
|
||||||
)
|
)
|
||||||
|
|
||||||
money_pp = models.PositiveSmallIntegerField(default=0, verbose_name="PP")
|
money_pp = models.PositiveSmallIntegerField(default=0, verbose_name="PP")
|
||||||
|
@ -219,10 +219,6 @@ class Character(models.Model):
|
||||||
def mana_max(self) -> int:
|
def mana_max(self) -> int:
|
||||||
return 2 * self.level + self.modifier_intelligence
|
return 2 * self.level + self.modifier_intelligence
|
||||||
|
|
||||||
@property
|
|
||||||
def mana_remaining(self) -> int:
|
|
||||||
return self.mana_max - self.mana_consumed
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def height_m(self) -> float:
|
def height_m(self) -> float:
|
||||||
return round(self.height / 100, 2)
|
return round(self.height / 100, 2)
|
||||||
|
|
|
@ -135,8 +135,36 @@
|
||||||
<td>{{ character.mana_max }}</td>
|
<td>{{ character.mana_max }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">PM restants</th>
|
<th scope="row">
|
||||||
<td>{{ character.mana_remaining }}</td>
|
PM restants
|
||||||
|
<div class="btn-group btn-group-sm" role="group">
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:mana_change" pk=character.pk %}?value=ko"
|
||||||
|
hx-target="#mana-remaining"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-outline-danger">0</button>
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:mana_change" pk=character.pk %}?value=-1"
|
||||||
|
hx-target="#mana-remaining"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-danger">-</button>
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:mana_change" pk=character.pk %}?value=1"
|
||||||
|
hx-target="#mana-remaining"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-success">+</button>
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:mana_change" pk=character.pk %}?value=max"
|
||||||
|
hx-target="#mana-remaining"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-outline-success">max</button>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
<td id="mana-remaining">{{ character.mana_remaining }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -6,4 +6,5 @@ app_name = "character"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("<int:pk>/", views.character_view, name="view"),
|
path("<int:pk>/", views.character_view, name="view"),
|
||||||
path("<int:pk>/health_change", views.character_health_change, name="health_change"),
|
path("<int:pk>/health_change", views.character_health_change, name="health_change"),
|
||||||
|
path("<int:pk>/mana_change", views.character_mana_change, name="mana_change"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -30,3 +30,20 @@ def character_health_change(request: WSGIRequest, pk: int) -> HttpResponse:
|
||||||
character.health_remaining = max([0, character.health_remaining])
|
character.health_remaining = max([0, character.health_remaining])
|
||||||
character.save(update_fields=["health_remaining"])
|
character.save(update_fields=["health_remaining"])
|
||||||
return HttpResponse(character.health_remaining)
|
return HttpResponse(character.health_remaining)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def character_mana_change(request: WSGIRequest, pk: int) -> HttpResponse:
|
||||||
|
character = get_object_or_404(Character, pk=pk)
|
||||||
|
value = request.GET.get("value")
|
||||||
|
if value == "ko":
|
||||||
|
character.mana_remaining = 0
|
||||||
|
elif value == "max":
|
||||||
|
character.mana_remaining = character.mana_max
|
||||||
|
else:
|
||||||
|
value = int(value)
|
||||||
|
character.mana_remaining += value
|
||||||
|
character.mana_remaining = min([character.mana_max, character.mana_remaining])
|
||||||
|
character.mana_remaining = max([0, character.mana_remaining])
|
||||||
|
character.save(update_fields=["mana_remaining"])
|
||||||
|
return HttpResponse(character.mana_remaining)
|
||||||
|
|
Loading…
Reference in a new issue