trophies: generate icons dynamically in the master script
DATABASE UPDATE: Run the [create-trophies] command of the master script to obtain icons.
|
@ -2,6 +2,7 @@
|
|||
__pycache__/
|
||||
app/__pycache__/
|
||||
app/static/avatars/
|
||||
app/static/images/trophies/
|
||||
|
||||
## Devlopement files
|
||||
|
||||
|
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 397 B |
Before Width: | Height: | Size: 563 B |
Before Width: | Height: | Size: 490 B |
Before Width: | Height: | Size: 558 B |
Before Width: | Height: | Size: 529 B |
Before Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 584 B |
Before Width: | Height: | Size: 602 B |
Before Width: | Height: | Size: 574 B |
Before Width: | Height: | Size: 424 B |
Before Width: | Height: | Size: 490 B |
Before Width: | Height: | Size: 509 B |
Before Width: | Height: | Size: 604 B |
Before Width: | Height: | Size: 519 B |
Before Width: | Height: | Size: 643 B |
Before Width: | Height: | Size: 541 B |
Before Width: | Height: | Size: 528 B |
Before Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 788 B |
Before Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 564 B |
Before Width: | Height: | Size: 727 B |
Before Width: | Height: | Size: 519 B |
Before Width: | Height: | Size: 646 B |
Before Width: | Height: | Size: 547 B |
Before Width: | Height: | Size: 460 B |
Before Width: | Height: | Size: 443 B |
Before Width: | Height: | Size: 490 B |
Before Width: | Height: | Size: 666 B |
Before Width: | Height: | Size: 526 B |
Before Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 516 B |
Before Width: | Height: | Size: 572 B |
|
@ -1,35 +0,0 @@
|
|||
#! /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")
|
27
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 <member> #<group-id>' 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")
|
||||
|
|