mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Display whole paths at first rank
This commit is contained in:
parent
467c582a83
commit
7b4d379f43
4 changed files with 36 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
import collections
|
import collections
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -105,6 +106,12 @@ DEFAULT_NOTES = """
|
||||||
""".lstrip()
|
""".lstrip()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CharacterCapability:
|
||||||
|
capability: Capability
|
||||||
|
known: bool = False
|
||||||
|
|
||||||
|
|
||||||
class Character(models.Model):
|
class Character(models.Model):
|
||||||
class Gender(models.TextChoices):
|
class Gender(models.TextChoices):
|
||||||
MALE = "M", "Mâle"
|
MALE = "M", "Mâle"
|
||||||
|
@ -333,15 +340,22 @@ class Character(models.Model):
|
||||||
}
|
}
|
||||||
return modifier_map.get(Weapon.Category(weapon.category), 0) + self.level
|
return modifier_map.get(Weapon.Category(weapon.category), 0) + self.level
|
||||||
|
|
||||||
def get_capabilities_by_path(self) -> dict[Path, list[Capability]]:
|
def get_capabilities_by_path(self) -> dict[Path, list[CharacterCapability]]:
|
||||||
capabilities_by_path = collections.defaultdict(list)
|
capabilities_by_path = collections.defaultdict(list)
|
||||||
for capability in self.capabilities.all():
|
character_capabilities = self.capabilities.all()
|
||||||
capabilities_by_path[capability.path].append(capability)
|
character_paths = {capability.path for capability in character_capabilities}
|
||||||
|
for path in character_paths:
|
||||||
|
for capability in path.capabilities.all():
|
||||||
|
capabilities_by_path[capability.path].append(
|
||||||
|
CharacterCapability(
|
||||||
|
capability, known=capability in character_capabilities
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
sorted(
|
sorted(
|
||||||
(
|
(
|
||||||
(path, sorted(capabilities, key=lambda x: x.rank))
|
(path, sorted(capabilities, key=lambda x: x.capability.rank))
|
||||||
for path, capabilities in capabilities_by_path.items()
|
for path, capabilities in capabilities_by_path.items()
|
||||||
),
|
),
|
||||||
key=lambda x: x[0].name,
|
key=lambda x: x[0].name,
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
<div class="accordion-item">
|
{% with character_capability.capability as capability %}
|
||||||
<h2 class="accordion-header">
|
<div class="accordion-item">
|
||||||
<button class="accordion-button collapsed" type="button"
|
<h2 class="accordion-header">
|
||||||
data-bs-toggle="collapse" data-bs-target="#cap-{{ capability.pk }}">
|
<button class="accordion-button collapsed {% if not character_capability.known %}text-bg-light{% endif %}" type="button"
|
||||||
{{ capability.rank }}.
|
data-bs-toggle="collapse" data-bs-target="#cap-{{ capability.pk }}">
|
||||||
{{ capability.name }}
|
{{ capability.rank }}.
|
||||||
{% if capability.spell %} <i class="fa-solid fa-hand-sparkles"></i>{% endif %}
|
{{ capability.name }}
|
||||||
{% if capability.limited %} <i class="fa-solid fa-handcuffs"></i>{% endif %}
|
{% if capability.spell %} <i class="fa-solid fa-hand-sparkles"></i>{% endif %}
|
||||||
</button>
|
{% if capability.limited %} <i class="fa-solid fa-handcuffs"></i>{% endif %}
|
||||||
</h2>
|
</button>
|
||||||
<div id="cap-{{ capability.pk }}" class="accordion-collapse collapse">
|
</h2>
|
||||||
<div class="accordion-body">
|
<div id="cap-{{ capability.pk }}" class="accordion-collapse collapse">
|
||||||
{{ capability.description }}
|
<div class="accordion-body">
|
||||||
|
{{ capability.description }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endwith %}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<div class="alert alert-primary">{{ path.notes }}</div>
|
<div class="alert alert-primary">{{ path.notes }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="accordion capabilities">
|
<div class="accordion capabilities">
|
||||||
{% for capability in capabilities %}
|
{% for character_capability in character_capabilities %}
|
||||||
{% include "character/snippets/character_details/capability.html" %}
|
{% include "character/snippets/character_details/capability.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row mt-2 gy-3">
|
<div class="row mt-2 gy-3">
|
||||||
{% for path, capabilities in character.get_capabilities_by_path.items %}
|
{% for path, character_capabilities in character.get_capabilities_by_path.items %}
|
||||||
{% include "character/snippets/character_details/path.html" %}
|
{% include "character/snippets/character_details/path.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue