From ec9912b22a626be42df498feef49ffd272e61dd1 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 6 Nov 2022 16:09:41 +0100 Subject: [PATCH] Add progress bars to display health and mana in list --- src/character/models/character.py | 12 ++++++++++++ .../characters_list/character_card.html | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/character/models/character.py b/src/character/models/character.py index bbf4110..9892d14 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -306,6 +306,18 @@ class Character(models.Model): def luck_points_max(self) -> int: return 3 + self.modifier_charisma + @property + def health_remaining_percent(self) -> float: + if self.health_max == 0: + return 0 + return self.health_remaining / self.health_max * 100 + + @property + def mana_remaining_percent(self) -> float: + if self.mana_max == 0: + return 0 + return self.mana_remaining / self.mana_max * 100 + def get_modifier_for_weapon(self, weapon: Weapon) -> int: modifier_map = { Weapon.Category.RANGE: self.modifier_dexterity, 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 5290895..d7b565d 100644 --- a/src/character/templates/character/snippets/characters_list/character_card.html +++ b/src/character/templates/character/snippets/characters_list/character_card.html @@ -7,8 +7,21 @@

{{ 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 }}, PM {{ character.mana_remaining }}/{{ character.mana_max }}
+ {{ character.get_gender_display }}, {{ character.age }} ans, {{ character.height_m }}m, {{ character.weight }}kg +

+
+
+ PV : {{ character.health_remaining }}/{{ character.health_max }} +
+
+ {% if character.mana_max > 0 %} +
+
+ PM : {{ character.mana_remaining }}/{{ character.mana_max }} +
+
+ {% endif %} +

{% with character.states.all as character_states %} {% for state in all_states %}