Skip to content

Commit ca45d63

Browse files
committed
Prepare for classy or classless systems
Changed makecharacter.py and all of the views and templates for accommodating either classy or classless systems.
1 parent 4943d1e commit ca45d63

File tree

6 files changed

+67
-26
lines changed

6 files changed

+67
-26
lines changed

CharacterCreator/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Character(models.Model):
8686
other_points = models.IntegerField(default=0)
8787

8888
def __str__(self):
89-
return self.role.name + ': ' + self.name
89+
return self.name
9090

9191

9292
class CharacterEventRoll(models.Model):

CharacterCreator/templates/CharacterCreator/character.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<h1>{{ character }}</h1>
22

3+
{% if character.role.name %}
4+
<li>Role: {{ character.role.name }}</li>
5+
<li>Role Skill Points: {{ character.role_points }}</li>
6+
{% endif %}
7+
38
<li>Statistic Points: {{ character.stat_points }}</li>
4-
<li>Role Skill Points: {{ character.role_points }}</li>
59
<li>Other Skill Points: {{ character.other_points }}</li>
610

711
<h2>Statistics</h2>

CharacterCreator/templates/CharacterCreator/index.html

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
{% if character_list %}
2-
<ul>
3-
{% for c in character_list %}
4-
<li><a href="{% url 'character' c.id %}">{{ c }}</a></li>
5-
{% if npc_list %}
2+
{% if role_list %}
3+
{% for r in role_list %}
4+
<li>{{ r }}</li>
65
<ul>
7-
{% for npc in npc_list %}
8-
{% for h in npc_history %}
9-
{% if h.npc == npc and h.character == c %}
10-
{% ifchanged npc %}
11-
<li><a href="{% url 'npc' npc.id %}">{{ npc }}</a></li>
12-
{% endifchanged %}
6+
{% for c in character_list %}
7+
{% if c.role == r %}
8+
<li><a href="{% url 'character' c.id %}">{{ c }}</a></li>
9+
{% if npc_list %}
10+
<ul>
11+
{% for npc in npc_list %}
12+
{% for h in npc_history %}
13+
{% if h.npc == npc and h.character == c %}
14+
{% ifchanged npc %}
15+
<li><a href="{% url 'npc' npc.id %}">{{ npc }}</a></li>
16+
{% endifchanged %}
17+
{% endif %}
18+
{% endfor %}
19+
{% endfor %}
20+
</ul>
1321
{% endif %}
14-
{% endfor %}
22+
{% endif %}
1523
{% endfor %}
1624
</ul>
17-
{% endif %}
18-
{% endfor %}
19-
</ul>
25+
{% endfor %}
26+
</ul>
27+
{% else %}
28+
{% for c in character_list %}
29+
<li><a href="{% url 'character' c.id %}">{{ c }}</a></li>
30+
{% if npc_list %}
31+
<ul>
32+
{% for npc in npc_list %}
33+
{% for h in npc_history %}
34+
{% if h.npc == npc and h.character == c %}
35+
{% ifchanged npc %}
36+
<li><a href="{% url 'npc' npc.id %}">{{ npc }}</a></li>
37+
{% endifchanged %}
38+
{% endif %}
39+
{% endfor %}
40+
{% endfor %}
41+
</ul>
42+
{% endif %}
43+
{% endfor %}
44+
</ul>
45+
{% endif %}
2046
{% else %}
2147
<p>No characters are available.</p>
2248
{% endif %}

CharacterCreator/templates/CharacterCreator/npc.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<h1>{{ character }}</h1>
22

3+
{% if character.role.name %}
4+
<li>Role: {{ character.role.name }}</li>
5+
<li>Role Skill Points: {{ character.role_points }}</li>
6+
{% endif %}
7+
38
<li>Statistic Points: {{ character.stat_points }}</li>
4-
<li>Role Skill Points: {{ character.role_points }}</li>
59
<li>Other Skill Points: {{ character.other_points }}</li>
610

711
<h2>Statistics</h2>

CharacterCreator/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def index(request):
99
npc_list = Character.objects.filter(name__contains='[NPC').order_by('role__name', 'name')
1010
npc_history_list = NPCEventRoll.objects.all()
1111
character_list = Character.objects.all().exclude(name__contains='[NPC').order_by('role__name', 'name')
12-
return render(request, 'CharacterCreator/index.html', {'character_list': character_list, 'npc_list': npc_list, 'npc_history': npc_history_list})
12+
role_list = Role.objects.all().order_by('name')
13+
return render(request, 'CharacterCreator/index.html', {'character_list': character_list, 'npc_list': npc_list, 'npc_history': npc_history_list, 'role_list': role_list})
1314

1415

1516
def character(request, character_id):

makecharacter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ def roll_skills(c):
5151
op = c.other_points
5252

5353
# initialize skills
54-
special_skills = c.role.special_skills.all()
55-
common_skills = c.role.common_skills.all()
56-
role_skills = (special_skills | common_skills).distinct()
57-
special_stat = Statistic.objects.get(name='SPECIAL')
58-
all_special_skills = Skill.objects.filter(statistic=special_stat)
59-
other_skills = Skill.objects.all().difference(all_special_skills, role_skills)
54+
if c.role:
55+
special_skills = c.role.special_skills.all()
56+
common_skills = c.role.common_skills.all()
57+
role_skills = (special_skills | common_skills).distinct()
58+
special_stat = Statistic.objects.get(name='SPECIAL')
59+
all_special_skills = Skill.objects.filter(statistic=special_stat)
60+
other_skills = Skill.objects.all().difference(all_special_skills, role_skills)
61+
else:
62+
special_skills = []
63+
common_skills = []
64+
role_skills = []
65+
other_skills = Skill.objects.all()
66+
6067
for skill in role_skills:
6168
cskill = CharacterSkill()
6269
cskill.character = c
@@ -81,8 +88,7 @@ def roll_skills(c):
8188
op -= skill.minimum
8289
cskill.save()
8390

84-
other_cskills = CharacterSkill.objects.filter(
85-
character=c).difference(role_cskills)
91+
other_cskills = CharacterSkill.objects.filter(character=c).difference(role_cskills)
8692
while op > 0:
8793
skill = random.choice(other_skills)
8894
cskill = CharacterSkill.objects.get(character=c, skill=skill)

0 commit comments

Comments
 (0)