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

filter by faction on leader list. icon looks better #45

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 18 additions & 4 deletions web wiki/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import pygame
import hashlib
from flask import Flask, render_template, redirect
from flask import Flask, render_template, redirect, request

# ---
# 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 @@ -92,7 +92,7 @@ def change_ruleset(self):
leader_class = game.leader_data.leader_class


def get_subunit_icon(subunit_id, scale, icon_size):
def get_subunit_icon(subunit_id, scale, icon_size=None):
"""get a icon for a specific subunit"""

md5_input = "{0}${1}${2}".format(subunit_id, scale, icon_size)
Expand Down Expand Up @@ -149,6 +149,7 @@ def factions(): # TODO add faction coa as icon
for k, v in game.faction_data.faction_list.items():
if k != 0: # skip all faction
faction = {
"id": k,
"name": v["Name"],
"icon": make_faction_icon_and_return_web_path(k),
"troop": "TODO: get this to work?", # v["Troop"] <-- key not exist error
Expand Down Expand Up @@ -327,10 +328,23 @@ def leaders(leader_id=None):
image="/static/leader_{0}.png".format(leader_id),
)

faction = request.args.get("faction")
header = "Leaders"

if faction is None:
_filter = None
else:
_filter = {k for k, v in game.leader_data.leader_list.items() if int(faction) in v["Faction"]}
header = "Leaders of {0}".format(game.faction_data.faction_list[int(faction)]["Name"])

# list leaders view
leaders = list()
for k, v in game.leader_data.leader_list.items():

if _filter is not None:
if k not in _filter:
continue

leader = {
"id": k,
"name": v["Name"],
Expand Down Expand Up @@ -421,10 +435,10 @@ def leaders(leader_id=None):

leaders.append(leader)

subunit_icon = get_subunit_icon(k, 35, (36, 36))
subunit_icon = get_subunit_icon(k, 44)
leader['icon'] = [subunit_icon, k]

return render_template("leaders.j2", leaders=leaders)
return render_template("leaders.j2", leaders=leaders, header=header)


app.run(debug=True)
3 changes: 2 additions & 1 deletion web wiki/templates/factions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
{% block content %}
<h2>Factions</h2>
<table>
<tr><th></th><th>Name</th><th>Troop</th><th>Region</th></tr>
<tr><th></th><th>Name</th><th>Leaders</th><th>Troop</th><th>Region</th></tr>
{% for faction in factions %}
<tr>
<td><img src="{{faction["icon"]}}"></td>
<td>{{faction["name"]}}</td>
<td><a href="/leaders?faction={{faction["id"]}}">See leaders</a></td>
<td>{{faction["troop"]}}</td>
<td>{{faction["region"]}}</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions web wiki/templates/leaders.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.j2" %}

{% block content %}
<h2>Leaders</h2>
<h2>{{header}}</h2>

<style>
.attributes th{ color: #777; font-size: 10px; }
Expand All @@ -23,7 +23,7 @@
</tr>
{% for unit in leaders %}
<tr>
<td><img src="{{unit["icon"][0]}}" alt="{{unit["icon"][1]}}" title="{{unit["icon"][1]}}"></td>
<td style="text-align: center"><img src="{{unit["icon"][0]}}" alt="{{unit["icon"][1]}}" title="{{unit["icon"][1]}}"></td>
<td><a href="/leaders/{{unit["id"]}}">{{unit["name"]}}</a><br>{{unit["type"]}}<br>{{unit["faction"]}}</td>

<td>
Expand Down