91 lines
3.4 KiB
Python
91 lines
3.4 KiB
Python
|
|
import os
|
||
|
|
import sys
|
||
|
|
|
||
|
|
try:
|
||
|
|
from PIL import Image, ImageTk, ImageSequence
|
||
|
|
HAS_PIL = True
|
||
|
|
except ImportError:
|
||
|
|
HAS_PIL = False
|
||
|
|
print("WARNUNG: Pillow (PIL) nicht gefunden!")
|
||
|
|
|
||
|
|
class AssetManager:
|
||
|
|
"""Lädt alle Bilder und hält die Referenzen dauerhaft im Speicher."""
|
||
|
|
def __init__(self):
|
||
|
|
self.raw_bg = None
|
||
|
|
self.raw_title = None
|
||
|
|
self.raw_logo = None
|
||
|
|
|
||
|
|
self.btn_orange = None
|
||
|
|
self.btn_orange_active = None
|
||
|
|
self.sel_active = None
|
||
|
|
self.sel_inactive = None
|
||
|
|
|
||
|
|
self.raw_dice = {}
|
||
|
|
self.raw_anim = []
|
||
|
|
self.anim_cache_large = []
|
||
|
|
|
||
|
|
if not HAS_PIL:
|
||
|
|
return
|
||
|
|
|
||
|
|
def get_full_path(rel_path):
|
||
|
|
try:
|
||
|
|
base_path = sys._MEIPASS
|
||
|
|
except Exception:
|
||
|
|
base_path = os.path.abspath(".")
|
||
|
|
return os.path.join(base_path, rel_path)
|
||
|
|
|
||
|
|
def load_raw(paths):
|
||
|
|
if isinstance(paths, str):
|
||
|
|
paths = [paths]
|
||
|
|
for p in paths:
|
||
|
|
full_path = get_full_path(p)
|
||
|
|
if os.path.exists(full_path):
|
||
|
|
return Image.open(full_path).convert("RGBA")
|
||
|
|
return None
|
||
|
|
|
||
|
|
# 1. Rohe Bilder laden (mit Status-Ausgabe)
|
||
|
|
self.raw_bg = load_raw(["ressources/background.jpeg", "ressources/background.jpg", "ressources/background.png"])
|
||
|
|
self.raw_title = load_raw(["ressources/title1.png"])
|
||
|
|
self.raw_logo = load_raw(["ressources/logo.jpg", "ressources/logo.png"])
|
||
|
|
|
||
|
|
# 2. Feste UI-Buttons laden
|
||
|
|
def load_btn(paths, size):
|
||
|
|
r = load_raw(paths)
|
||
|
|
return ImageTk.PhotoImage(r.resize(size, Image.Resampling.LANCZOS)) if r else None
|
||
|
|
|
||
|
|
self.btn_orange = load_btn(["ressources/button1.png", "ressources/button1.jpeg"], (200, 50))
|
||
|
|
self.btn_orange_active = load_btn(["ressources/button1_active.png"], (200, 50))
|
||
|
|
self.sel_active = load_btn(["ressources/selection_active.png"], (150, 35))
|
||
|
|
self.sel_inactive = load_btn(["ressources/selection_inactive.png"], (150, 35))
|
||
|
|
|
||
|
|
# Erfolgs-Banner laden
|
||
|
|
self.bonus_achieved_img = load_raw(["ressources/bonus_achived.jpg", "ressources/bonus_achieved.jpg"])
|
||
|
|
self.yahtzee_achieved_img = load_raw(["ressources/yahtzee_achived.jpg", "ressources/yahtzee_achieved.jpg"])
|
||
|
|
|
||
|
|
# 3. Rohe Würfel für dynamische Größen
|
||
|
|
for i in range(1, 7):
|
||
|
|
self.raw_dice[i] = load_raw(f"ressources/dices/default/dice{i}.png")
|
||
|
|
|
||
|
|
# Animations-GIF laden (Sucht jetzt gezielt nach dice.gif)
|
||
|
|
self.raw_anim_frames = []
|
||
|
|
self.anim_cache_large = []
|
||
|
|
|
||
|
|
gif_paths = ["ressources/dice.gif", "ressources/dices/dice.gif", "ressources/dice_2.gif"]
|
||
|
|
anim_full_path = None
|
||
|
|
for gp in gif_paths:
|
||
|
|
full = get_full_path(gp)
|
||
|
|
if os.path.exists(full):
|
||
|
|
anim_full_path = full
|
||
|
|
break
|
||
|
|
|
||
|
|
if anim_full_path:
|
||
|
|
try:
|
||
|
|
gif = Image.open(anim_full_path)
|
||
|
|
for frame in ImageSequence.Iterator(gif):
|
||
|
|
# Konvertiere jeden Frame sauber in RGBA und skaliere ihn sofort fest vor
|
||
|
|
f_rgba = frame.copy().convert("RGBA")
|
||
|
|
self.raw_anim_frames.append(f_rgba)
|
||
|
|
self.anim_cache_large.append(ImageTk.PhotoImage(f_rgba.resize((150, 150), Image.Resampling.LANCZOS)))
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Fehler beim Laden des GIFs: {e}")
|