Browse Source

trophies: generate icons dynamically in the master script

DATABASE UPDATE: Run the [create-trophies] command of the master script
to obtain icons.
pull/61/head
Lephe 4 months ago
parent
commit
19e4ee2e30
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
38 changed files with 27 additions and 36 deletions
  1. +1
    -0
      .gitignore
  2. +0
    -0
      app/data/trophies.png
  3. BIN
      app/static/images/trophies/actif.png
  4. BIN
      app/static/images/trophies/aficionado.png
  5. BIN
      app/static/images/trophies/artiste.png
  6. BIN
      app/static/images/trophies/beau-parleur.png
  7. BIN
      app/static/images/trophies/bourreau-des-coeurs.png
  8. BIN
      app/static/images/trophies/codeur-invetere.png
  9. BIN
      app/static/images/trophies/concourant-encore.png
  10. BIN
      app/static/images/trophies/concurrent-de-l-extreme.png
  11. BIN
      app/static/images/trophies/dessinateur-en-herbe.png
  12. BIN
      app/static/images/trophies/encyclopedie-vivante.png
  13. BIN
      app/static/images/trophies/gourou.png
  14. BIN
      app/static/images/trophies/grand-joueur.png
  15. BIN
      app/static/images/trophies/grand-maitre-des-traits-d-esprit.png
  16. BIN
      app/static/images/trophies/grand-manitou.png
  17. BIN
      app/static/images/trophies/guerrier-du-savoir.png
  18. BIN
      app/static/images/trophies/hard-tester.png
  19. BIN
      app/static/images/trophies/initie.png
  20. BIN
      app/static/images/trophies/je-code-donc-je-suis.png
  21. BIN
      app/static/images/trophies/maitre-du-code.png
  22. BIN
      app/static/images/trophies/membre-d-honneur.png
  23. BIN
      app/static/images/trophies/membre-de-creativecalc.png
  24. BIN
      app/static/images/trophies/open-pixel.png
  25. BIN
      app/static/images/trophies/papy-casio.png
  26. BIN
      app/static/images/trophies/participant.png
  27. BIN
      app/static/images/trophies/pedagogue.png
  28. BIN
      app/static/images/trophies/plume-infaillible.png
  29. BIN
      app/static/images/trophies/premiers-mots.png
  30. BIN
      app/static/images/trophies/programmeur-du-dimanche.png
  31. BIN
      app/static/images/trophies/roi-du-pixel.png
  32. BIN
      app/static/images/trophies/romancier-emerite.png
  33. BIN
      app/static/images/trophies/survivant-de-la-v42.png
  34. BIN
      app/static/images/trophies/testeur.png
  35. BIN
      app/static/images/trophies/veni-vidi-casii.png
  36. BIN
      app/static/images/trophies/veteran-mythique.png
  37. +0
    -35
      assets/trophies-generate.py
  38. +26
    -1
      master.py

+ 1
- 0
.gitignore View File

@@ -2,6 +2,7 @@
__pycache__/
app/__pycache__/
app/static/avatars/
app/static/images/trophies/

## Devlopement files



assets/trophies.png → app/data/trophies.png View File


BIN
app/static/images/trophies/actif.png View File

Before After
Width: 48  |  Height: 48  |  Size: 397 B

BIN
app/static/images/trophies/aficionado.png View File

Before After
Width: 48  |  Height: 48  |  Size: 563 B

BIN
app/static/images/trophies/artiste.png View File

Before After
Width: 48  |  Height: 48  |  Size: 490 B

BIN
app/static/images/trophies/beau-parleur.png View File

Before After
Width: 48  |  Height: 48  |  Size: 558 B

BIN
app/static/images/trophies/bourreau-des-coeurs.png View File

Before After
Width: 48  |  Height: 48  |  Size: 529 B

BIN
app/static/images/trophies/codeur-invetere.png View File

Before After
Width: 48  |  Height: 48  |  Size: 581 B

BIN
app/static/images/trophies/concourant-encore.png View File

Before After
Width: 48  |  Height: 48  |  Size: 584 B

BIN
app/static/images/trophies/concurrent-de-l-extreme.png View File

Before After
Width: 48  |  Height: 48  |  Size: 602 B

BIN
app/static/images/trophies/dessinateur-en-herbe.png View File

Before After
Width: 48  |  Height: 48  |  Size: 574 B

BIN
app/static/images/trophies/encyclopedie-vivante.png View File

Before After
Width: 48  |  Height: 48  |  Size: 424 B

BIN
app/static/images/trophies/gourou.png View File

Before After
Width: 48  |  Height: 48  |  Size: 490 B

BIN
app/static/images/trophies/grand-joueur.png View File

Before After
Width: 48  |  Height: 48  |  Size: 509 B

BIN
app/static/images/trophies/grand-maitre-des-traits-d-esprit.png View File

Before After
Width: 48  |  Height: 48  |  Size: 604 B

BIN
app/static/images/trophies/grand-manitou.png View File

Before After
Width: 48  |  Height: 48  |  Size: 519 B

BIN
app/static/images/trophies/guerrier-du-savoir.png View File

Before After
Width: 48  |  Height: 48  |  Size: 643 B

BIN
app/static/images/trophies/hard-tester.png View File

Before After
Width: 48  |  Height: 48  |  Size: 541 B

BIN
app/static/images/trophies/initie.png View File

Before After
Width: 48  |  Height: 48  |  Size: 528 B

BIN
app/static/images/trophies/je-code-donc-je-suis.png View File

Before After
Width: 48  |  Height: 48  |  Size: 524 B

BIN
app/static/images/trophies/maitre-du-code.png View File

Before After
Width: 48  |  Height: 48  |  Size: 788 B

BIN
app/static/images/trophies/membre-d-honneur.png View File

Before After
Width: 48  |  Height: 48  |  Size: 575 B

BIN
app/static/images/trophies/membre-de-creativecalc.png View File

Before After
Width: 48  |  Height: 48  |  Size: 564 B

BIN
app/static/images/trophies/open-pixel.png View File

Before After
Width: 48  |  Height: 48  |  Size: 727 B

BIN
app/static/images/trophies/papy-casio.png View File

Before After
Width: 48  |  Height: 48  |  Size: 519 B

BIN
app/static/images/trophies/participant.png View File

Before After
Width: 48  |  Height: 48  |  Size: 646 B

BIN
app/static/images/trophies/pedagogue.png View File

Before After
Width: 48  |  Height: 48  |  Size: 547 B

BIN
app/static/images/trophies/plume-infaillible.png View File

Before After
Width: 48  |  Height: 48  |  Size: 460 B

BIN
app/static/images/trophies/premiers-mots.png View File

Before After
Width: 48  |  Height: 48  |  Size: 443 B

BIN
app/static/images/trophies/programmeur-du-dimanche.png View File

Before After
Width: 48  |  Height: 48  |  Size: 490 B

BIN
app/static/images/trophies/roi-du-pixel.png View File

Before After
Width: 48  |  Height: 48  |  Size: 666 B

BIN
app/static/images/trophies/romancier-emerite.png View File

Before After
Width: 48  |  Height: 48  |  Size: 526 B

BIN
app/static/images/trophies/survivant-de-la-v42.png View File

Before After
Width: 48  |  Height: 48  |  Size: 402 B

BIN
app/static/images/trophies/testeur.png View File

Before After
Width: 48  |  Height: 48  |  Size: 401 B

BIN
app/static/images/trophies/veni-vidi-casii.png View File

Before After
Width: 48  |  Height: 48  |  Size: 516 B

BIN
app/static/images/trophies/veteran-mythique.png View File

Before After
Width: 48  |  Height: 48  |  Size: 572 B

+ 0
- 35
assets/trophies-generate.py View File

@@ -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")

+ 26
- 1
master.py View File

@@ -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")


Loading…
Cancel
Save