mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-02 02:38:30 +02:00
80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
if TYPE_CHECKING:
|
|
from source.mkw import ModConfig
|
|
from source import TemplateMultipleSafeEval
|
|
|
|
|
|
class Cup:
|
|
"""
|
|
class that represent a mario kart wii track cup
|
|
"""
|
|
|
|
__slots__ = ["_tracks", "cup_name", "cup_id", "mod_config"]
|
|
_last_cup_id = 1
|
|
mod_config: "ModConfig"
|
|
|
|
def __init__(self, mod_config: "ModConfig", tracks: list["Track | TrackGroup"], cup_name: str | None = None):
|
|
self.mod_config = mod_config
|
|
self._tracks = tracks[:4]
|
|
|
|
self.cup_id = self.__class__._last_cup_id
|
|
self.cup_name = cup_name if cup_name is not None else self.cup_id
|
|
self.__class__._last_cup_id += 1
|
|
|
|
def __repr__(self):
|
|
return f"<Cup name={self.cup_name} id={self.cup_id} tracks={self._tracks}>"
|
|
|
|
def get_default_cticon(self) -> Image.Image:
|
|
"""
|
|
Get the default cticon for this cup
|
|
:return: the default cticon
|
|
"""
|
|
from source.mkw.ModConfig import CT_ICON_SIZE
|
|
|
|
ct_icon = Image.new("RGBA", (CT_ICON_SIZE, CT_ICON_SIZE))
|
|
default_font_path = str(self.mod_config.get_default_font().resolve())
|
|
draw = ImageDraw.Draw(ct_icon)
|
|
|
|
draw.text(
|
|
(4, 4),
|
|
"CT",
|
|
(255, 165, 0),
|
|
font=ImageFont.truetype(default_font_path, 90),
|
|
stroke_width=2,
|
|
stroke_fill=(0, 0, 0)
|
|
)
|
|
draw.text(
|
|
(5, 80),
|
|
f"{self.cup_id:03}",
|
|
(255, 165, 0),
|
|
font=ImageFont.truetype(default_font_path, 60),
|
|
stroke_width=2,
|
|
stroke_fill=(0, 0, 0)
|
|
)
|
|
|
|
return ct_icon
|
|
|
|
def get_cticon(self, mod_config: "ModConfig") -> Image.Image:
|
|
"""
|
|
Get the cticon for this cup
|
|
:return: the cticon
|
|
"""
|
|
path = mod_config.get_mod_directory() / f"_CUPS/{self.cup_name}.png"
|
|
if path.exists(): return Image.open(path)
|
|
# if the icon doesn't exist, use the default automatically generated one
|
|
return self.get_default_cticon()
|
|
|
|
def get_ctfile(self, template: "TemplateMultipleSafeEval") -> str:
|
|
"""
|
|
Get the ctfile for this cup
|
|
:return: the ctfile
|
|
"""
|
|
ctfile = f'C "{self.cup_name}"\n'
|
|
for track in self._tracks: ctfile += track.get_ctfile(template=template)
|
|
ctfile += "\n"
|
|
|
|
return ctfile
|
|
|