trophies: add icons
|
@ -5,6 +5,7 @@ from flask_login import LoginManager
|
|||
from flask_mail import Mail
|
||||
from config import Config
|
||||
import time
|
||||
import slugify
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
@ -49,3 +50,8 @@ from app.routes.forum import index, topic
|
|||
from app.utils import pluralize # To use pluralize into the templates
|
||||
from app.utils import date
|
||||
from app.utils import is_title
|
||||
|
||||
# Add slugify into the available functions in every template
|
||||
app.jinja_env.globals.update(
|
||||
slugify=slugify.slugify
|
||||
)
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
border-radius: 2px;
|
||||
}
|
||||
.trophy img {
|
||||
height: 50px; margin-right: 5px;
|
||||
height: 48px; margin-right: 8px;
|
||||
}
|
||||
.trophy div > * {
|
||||
display: block;
|
||||
|
|
After Width: | Height: | Size: 397 B |
After Width: | Height: | Size: 563 B |
After Width: | Height: | Size: 490 B |
After Width: | Height: | Size: 558 B |
After Width: | Height: | Size: 529 B |
After Width: | Height: | Size: 581 B |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 602 B |
After Width: | Height: | Size: 574 B |
After Width: | Height: | Size: 424 B |
After Width: | Height: | Size: 490 B |
After Width: | Height: | Size: 509 B |
After Width: | Height: | Size: 604 B |
After Width: | Height: | Size: 519 B |
After Width: | Height: | Size: 643 B |
After Width: | Height: | Size: 541 B |
After Width: | Height: | Size: 528 B |
After Width: | Height: | Size: 524 B |
After Width: | Height: | Size: 788 B |
After Width: | Height: | Size: 575 B |
After Width: | Height: | Size: 564 B |
After Width: | Height: | Size: 727 B |
After Width: | Height: | Size: 519 B |
After Width: | Height: | Size: 646 B |
After Width: | Height: | Size: 547 B |
After Width: | Height: | Size: 460 B |
After Width: | Height: | Size: 443 B |
After Width: | Height: | Size: 490 B |
After Width: | Height: | Size: 666 B |
After Width: | Height: | Size: 526 B |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 401 B |
After Width: | Height: | Size: 516 B |
After Width: | Height: | Size: 572 B |
|
@ -46,7 +46,7 @@
|
|||
<div class="trophies">
|
||||
{% for t in trophies if t in member.trophies or t.hidden == False %}
|
||||
<div class="trophy {{ '' if t in member.trophies else 'disabled' }}">
|
||||
<img src="{{ url_for('static', filename='images/fa_124.png') }}">
|
||||
<img src="{{ url_for('static', filename='images/trophies/'+slugify(t.name))+'.png' }}">
|
||||
<div>
|
||||
<em>{{ t.name }}</em>
|
||||
<span>{{ t.description }}</span>
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#! /usr/bin/python3
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
import sys
|
||||
import slugify
|
||||
import yaml
|
||||
|
||||
if os.path.basename(os.getcwd()) != "assets":
|
||||
print("This script should be started from the /assets folder of PCv5.")
|
||||
sys.exit(1)
|
||||
|
||||
# Read the list of trophies from /app/data/trophies.yaml
|
||||
with open("../app/data/trophies.yaml") as fp:
|
||||
trophies = yaml.safe_load(fp.read())
|
||||
names = [ slugify.slugify(t["name"]) for t in trophies ]
|
||||
|
||||
# Write trophy images to /app/static/images/trophies
|
||||
try:
|
||||
os.mkdir("../app/static/images/trophies")
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
# Skip blank squares in the source image
|
||||
img = Image.open("trophies.png")
|
||||
|
||||
def trophy_iterator(img):
|
||||
for y in range(img.height // 26):
|
||||
for x in range(img.width // 26):
|
||||
icon = img.crop((26*x+1, 26*y+1, 26*x+25, 26*y+25))
|
||||
if len(icon.getcolors()) > 1:
|
||||
yield icon.resize((48,48))
|
||||
|
||||
for (name, icon) in zip(names, trophy_iterator(img)):
|
||||
icon.save(f"../app/static/images/trophies/{name}.png")
|
After Width: | Height: | Size: 9.6 KiB |