Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region list is "done" #46

Merged
merged 2 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions web wiki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pygame
import hashlib
from flask import Flask, render_template, redirect, request
from collections import defaultdict

# ---
# to get this to work on my computer I acutal has to have this (I tested using both this current directory and the actual "main" directory
Expand Down Expand Up @@ -139,6 +140,31 @@ def regions():
# This is obviously not an actual faction nor region so I discard it from being visible.
regions.discard("All")

faction_data = game.faction_data.faction_list

region_no_leaders = defaultdict(int)
region_no_troop_types = defaultdict(int)

for leader in game.leader_data.leader_list.values():
for faction in leader["Faction"]:
region_no_leaders[faction_data[faction]["Type"]] += 1

for troop in game.troop_data.troop_list.values():
for faction in troop["Faction"]:
region_no_troop_types[faction_data[faction]["Type"]] += 1

regions = [
{
"id": region.lower().replace(" ", "-"), # there is not such thing as an region id (yet?) so we have
# to rely on the name (but make it more id-like)
"name": region,
"no-factions": len([1 for f in game.faction_data.faction_list.values() if f["Type"] == region]),
"no-leaders": region_no_leaders[region],
"no-troop-types": region_no_troop_types[region],
}
for region in sorted(regions)
]

return render_template("regions.j2", regions=regions)


Expand All @@ -157,6 +183,9 @@ def factions():
"favoured-troop": v["Favoured Troop"],
"region": v["Type"]}
factions.append(faction)

factions.sort(key=lambda a: a["name"])

return render_template("factions.j2", factions=factions)


Expand Down
33 changes: 19 additions & 14 deletions web wiki/templates/base.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,44 @@
<title>Web wiki</title>
<style>
* { font-family: Helvetica; color: #111 }
html, body { height: 100% }
body { background: #d7d0c4; padding: 0; margin: 0 }
th { background: #a3856c }
th { background: #788997 }
h1 { margin: 0; padding: 0; color: #222222; font-size: 42px }
h2 { margin: 20px 0 0 0; padding: 0; color: #71410a; font-size: 28px }
table { border-collapse: collapse; border-spacing: 0 }
table { border-collapse: collapse; border-spacing: 0; margin-top: 12px }
hr { margin: 6px 0 6px 0; height: 1px; border: 0; border-bottom: 1px solid #ccc; display: block; padding: 0 }
th { text-align: left; color: #fefefe; font-size: 12px; font-weight: normal; padding: 6px; border-bottom: 1px solid #604030; border-top: 1px solid #604030; margin-bottom: 28px }
#content { background: #fefefe; padding:70px; border-left: 1px solid #ccc; border-right: 1px solid #ccc; width: 1300px; margin: 0 auto 0 auto; padding-top: 40px }
#content { background: #fefefe; border-left: 1px solid #ccc; border-right: 1px solid #ccc; width: 1300px; margin: 0 auto 0 auto; height: 100% }
#inner-content { padding: 70px; padding-top: 40px }
a{ color: #a13c12 }
tr:nth-child(odd) td { background: #fef2e8 }
tr:nth-child(odd) td { background: #f2f3f4 }
td{ padding: 6px; font-size: 12px; vertical-align:top }
.inner td{ padding: 2px; background: 0 !important; border: 0; color: #000; padding-right: 14px }
ul{ display: block; padding: 0; margin: 0 }
li{ display: block; padding: 0; margin: 0 }
.inner th{ padding:2px; background: 0; border: 0; font-weight:bold; padding-right:0; color: #000 }
p{ font-size:14px; font-family: "DejaVu Sans"; line-height: 22.4px }
.r{text-align: right }
</style>
</head>

<body>
<div id="content">
<h1>Encyclopedia</h1>
<div id="inner-content">
<h1>Encyclopedia</h1>

<hr/>
<a href="/regions">Regions</a> |
<a href="/factions">Factions</a> |
<a href="/troop-classes">Troop Classes</a> |
<a href="/troops">Troops</a> |
<a href="/leaders">Leaders</a> |
<a href="/weapons">Weapons</a>
<hr/>
<hr/>
<a href="/regions">Regions</a> |
<a href="/factions">Factions</a> |
<a href="/troop-classes">Troop Classes</a> |
<a href="/troops">Troops</a> |
<a href="/leaders">Leaders</a> |
<a href="/weapons">Weapons</a>
<hr/>

{% block content %}{% endblock %}
{% block content %}{% endblock %}
</div>

</div>
</body>
Expand Down
21 changes: 16 additions & 5 deletions web wiki/templates/regions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@


{% block content %}

<style>
td{padding:8px}
</style>

<h2>Regions</h2>
<table>
<tr><th>Name</th><th>Number of factions</th><th>Number of troops</th></tr>
<table style="width:100%">
<tr>
<th>Name</th>
<th class="r" style="width:200px">Number of factions</th>
<th class="r" style="width:200px">Number of leaders</th>
<th class="r" style="width:200px">Number of troop types</th>
</tr>
{% for region in regions %}
<tr>
<td>{{region}}</td>
<td>TODO</td>
<td>TODO</td>
<td>{{region["name"]}}</td>
<td class="r"><a href="/factions?region={{region["id"]}}">{{region["no-factions"]}} factions</a></td>
<td class="r"><a href="/leaders?region={{region["id"]}}">{{region["no-leaders"]}} leaders</a></td>
<td class="r"><a href="/troops?region={{region["id"]}}">{{region["no-troop-types"]}} troop types</a></td>
</tr>
{% endfor %}
{% endblock %}
Expand Down