- tools/make_icon.py genere assets/icon/ (police Bangers, aucune image du jeu) - launcher/build.rs compile dtr.rc avec rc.exe du SDK Windows (sans dependance) - la fenetre du launcher prend dtr-256.png au lieu du curseur du jeu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
5.3 KiB
Python
139 lines
5.3 KiB
Python
r"""Génère l'icône du projet (« DT » dédoublé, façon BD) dans assets/icon/.
|
||
|
||
python tools/make_icon.py
|
||
|
||
Demande pygame (pip install pygame-ce). Produit :
|
||
dtr.ico 16 à 256 px (sans l'étiquette RECOMP sous 48 px, illisible)
|
||
dtr-512.png avatar du dépôt (Gitea)
|
||
dtr-256.png icône de la fenêtre du launcher (sans l'étiquette : lisible en petit)
|
||
social-preview.png aperçu social GitHub (1280×640)
|
||
dtr.rc ressource Windows (icône de l'exe)
|
||
Aucune image du jeu : seulement la police Bangers (SIL OFL) du launcher.
|
||
"""
|
||
import io
|
||
import math
|
||
import os
|
||
import struct
|
||
|
||
import pygame
|
||
|
||
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
||
FONT = os.path.join(ROOT, "launcher", "assets", "fonts", "Bangers-Regular.ttf")
|
||
OUT = os.path.join(ROOT, "assets", "icon")
|
||
Y, BK, P1, P2, PINK = (255, 210, 0), (0, 0, 0), (31, 27, 56), (74, 58, 140), (255, 51, 102)
|
||
N = 512
|
||
|
||
|
||
def outlined(text, size, color, ow, shadow=0):
|
||
f = pygame.font.Font(FONT, size)
|
||
base, o = f.render(text, True, color), f.render(text, True, BK)
|
||
s = pygame.Surface((base.get_width() + 2 * ow + shadow, base.get_height() + 2 * ow + shadow), pygame.SRCALPHA)
|
||
for dx in range(-ow, ow + 1):
|
||
for dy in range(-ow, ow + 1):
|
||
if dx * dx + dy * dy <= ow * ow:
|
||
if shadow:
|
||
s.blit(o, (ow + dx + shadow, ow + dy + shadow))
|
||
s.blit(o, (ow + dx, ow + dy))
|
||
s.blit(base, (ow, ow))
|
||
return s
|
||
|
||
|
||
def rays(w, h, cx, cy, n, alpha):
|
||
r = pygame.Surface((w, h), pygame.SRCALPHA)
|
||
big = 2 * max(w, h)
|
||
for k in range(n):
|
||
a0 = k * 2 * math.pi / n
|
||
a1 = a0 + math.pi / n
|
||
pygame.draw.polygon(r, (255, 210, 0, alpha), [(cx, cy), (cx + big * math.cos(a0), cy + big * math.sin(a0)),
|
||
(cx + big * math.cos(a1), cy + big * math.sin(a1))])
|
||
return r
|
||
|
||
|
||
def gradient(w, h):
|
||
s = pygame.Surface((w, h), pygame.SRCALPHA)
|
||
for y in range(h):
|
||
t = y / h
|
||
pygame.draw.line(s, [int(P2[i] + (P1[i] - P2[i]) * t) for i in range(3)], (0, y), (w, y))
|
||
return s
|
||
|
||
|
||
def icon(with_tag):
|
||
s = gradient(N, N)
|
||
s.blit(rays(N, N, N / 2, N / 2, 24, 34), (0, 0))
|
||
mask = pygame.Surface((N, N), pygame.SRCALPHA)
|
||
pygame.draw.rect(mask, (255, 255, 255, 255), (4, 4, N - 8, N - 8), border_radius=96)
|
||
s.blit(mask, (0, 0), special_flags=pygame.BLEND_RGBA_MIN)
|
||
pygame.draw.rect(s, BK, (4, 4, N - 8, N - 8), 18, border_radius=96)
|
||
size, dy = (340, -26) if with_tag else (390, 0)
|
||
echo = pygame.transform.rotate(outlined("DT", size, PINK, 14), -6)
|
||
s.blit(echo, echo.get_rect(center=(N // 2 + 34, N // 2 + dy + 20)))
|
||
t = pygame.transform.rotate(outlined("DT", size, Y, 14, 12), 4)
|
||
s.blit(t, t.get_rect(center=(N // 2 - 16, N // 2 + dy)))
|
||
if with_tag:
|
||
f = pygame.font.Font(FONT, 64)
|
||
lab = f.render("RECOMP", True, BK)
|
||
r = pygame.Rect(0, 0, lab.get_width() + 44, lab.get_height() + 4)
|
||
r.center = (N // 2, 410)
|
||
pygame.draw.rect(s, BK, r.move(6, 6), border_radius=26)
|
||
pygame.draw.rect(s, Y, r, border_radius=26)
|
||
pygame.draw.rect(s, BK, r, 7, border_radius=26)
|
||
s.blit(lab, lab.get_rect(center=(r.centerx, r.centery + 2)))
|
||
return s
|
||
|
||
|
||
def png_bytes(surf):
|
||
b = io.BytesIO()
|
||
pygame.image.save(surf, b, "png")
|
||
return b.getvalue()
|
||
|
||
|
||
def write_ico(path, images):
|
||
"""ICO avec des entrées PNG (format accepté par Windows Vista et suivants, et par rc.exe)."""
|
||
head = struct.pack("<HHH", 0, 1, len(images))
|
||
entries, data = b"", b""
|
||
offset = 6 + 16 * len(images)
|
||
for size, blob in images:
|
||
b = 0 if size >= 256 else size
|
||
entries += struct.pack("<BBBBHHII", b, b, 0, 0, 1, 32, len(blob), offset + len(data))
|
||
data += blob
|
||
with open(path, "wb") as f:
|
||
f.write(head + entries + data)
|
||
|
||
|
||
def social(full):
|
||
W, H = 1280, 640
|
||
s = gradient(W, H)
|
||
s.blit(rays(W, H, 330, H / 2, 36, 26), (0, 0))
|
||
ic = pygame.transform.smoothscale(full, (400, 400))
|
||
s.blit(ic, (130, 120))
|
||
x0 = 600
|
||
t = outlined("DOUBLE TROUBLE", 118, Y, 6, 8)
|
||
s.blit(t, (x0, 150))
|
||
r = outlined("RECOMP", 118, (255, 255, 255), 6, 8)
|
||
s.blit(r, (x0, 265))
|
||
sub = outlined("Bud Tucker in Double Trouble (1996)", 40, (255, 255, 255), 3, 3)
|
||
s.blit(sub, (x0 + 4, 400))
|
||
sub2 = outlined("C natif · 1080p à 4K · pack HD · mods", 40, Y, 3, 3)
|
||
s.blit(sub2, (x0 + 4, 452))
|
||
pygame.draw.rect(s, (74, 58, 140), s.get_rect(), 8)
|
||
return s
|
||
|
||
|
||
def main():
|
||
pygame.init()
|
||
os.makedirs(OUT, exist_ok=True)
|
||
full, small = icon(True), icon(False)
|
||
sizes = [16, 24, 32, 48, 64, 128, 256]
|
||
imgs = [(sz, png_bytes(pygame.transform.smoothscale(full if sz >= 48 else small, (sz, sz)))) for sz in sizes]
|
||
write_ico(os.path.join(OUT, "dtr.ico"), imgs)
|
||
pygame.image.save(full, os.path.join(OUT, "dtr-512.png"))
|
||
pygame.image.save(pygame.transform.smoothscale(small, (256, 256)), os.path.join(OUT, "dtr-256.png"))
|
||
pygame.image.save(social(full), os.path.join(OUT, "social-preview.png"))
|
||
with open(os.path.join(OUT, "dtr.rc"), "w", encoding="ascii", newline="\r\n") as f:
|
||
f.write("// icone de l'executable (launcher, jeu) : rc /fo dtr.res dtr.rc\n1 ICON \"dtr.ico\"\n")
|
||
print("ok :", OUT)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|