diff --git a/.gitignore b/.gitignore index b5993a7..93d2f8b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ app/__pycache__/ app/static/avatars/ +app/static/images/trophies/ ## Devlopement files diff --git a/app/__init__.py b/app/__init__.py index 8a53d17..01ca7d3 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 +) diff --git a/app/data/trophies.png b/app/data/trophies.png new file mode 100644 index 0000000..c4a7c17 Binary files /dev/null and b/app/data/trophies.png differ diff --git a/app/data/trophies.yaml b/app/data/trophies.yaml index c6b6857..54e5dca 100644 --- a/app/data/trophies.yaml +++ b/app/data/trophies.yaml @@ -2,6 +2,7 @@ # name Trophy name as displayed on the site. # is_title If True, the trophy can be worn as a title next to the avatar. # description Detailed description to be shown on profile page. +# hidden Not shown unless awarded (for unique titles). # Manually awarded - @@ -185,3 +186,8 @@ is_title: True description: Foudroyer les cœurs à 5 reprises ! hidden: False +- + name: Survivant de la v42 + is_title: False + description: A connu la v42 de Planète Casio. + hidden: True diff --git a/app/static/css/widgets.css b/app/static/css/widgets.css index 4b4ee68..8d06ef7 100644 --- a/app/static/css/widgets.css +++ b/app/static/css/widgets.css @@ -61,7 +61,7 @@ border-radius: 2px; } .trophy img { - height: 50px; margin-right: 5px; + height: 48px; margin-right: 8px; } .trophy div > * { display: block; diff --git a/app/templates/account/user.html b/app/templates/account/user.html index d2473bc..dc80ac9 100644 --- a/app/templates/account/user.html +++ b/app/templates/account/user.html @@ -46,7 +46,7 @@
{% for t in trophies if t in member.trophies or t.hidden == False %}
- +
{{ t.name }} {{ t.description }} diff --git a/master.py b/master.py index b19c2c3..5e617c8 100755 --- a/master.py +++ b/master.py @@ -10,6 +10,8 @@ import os import sys import yaml import readline +import slugify +from PIL import Image help_msg = """ This is the Planète Casio master shell. Type 'exit' or C-D to leave. @@ -37,7 +39,7 @@ the database. Type 'add-group #' to add a new member to a group. -Type 'create-trophies' to reset trophies and titles. +Type 'create-trophies' to reset trophies and titles and their icons. Type 'create-forums' to reset the forum tree. """ @@ -183,6 +185,29 @@ def create_trophies(): print(f"Created {len(tr)} trophies.") + # Create their icons in /app/static/images/trophies + names = [ slugify.slugify(t["name"]) for t in tr ] + src = os.path.join(app.root_path, "data", "trophies.png") + dst = os.path.join(app.root_path, "static", "images", "trophies") + + try: + os.mkdir(dst) + except FileExistsError: + pass + + img = Image.open(src) + + 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)) + # Skip blank squares in the source image + if len(icon.getcolors()) > 1: + yield icon.resize((48,48)) + + for (name, icon) in zip(names, trophy_iterator(img)): + icon.save(os.path.join(dst, f"{name}.png")) + def create_forums(): # Clean up forums forums("clear")