- fixed missing last 10 cup icon

- simplified get_cup_icon function by using stroke_width and stroke_fill argument
- fixed track download
This commit is contained in:
raphael60650 2021-07-19 21:34:22 +02:00
parent 01ac79f623
commit 1b8dc36fac
4 changed files with 16 additions and 30 deletions

View file

@ -7,35 +7,23 @@ from .Cup import Cup
from .Track import Track
def get_cup_icon(i: int, cup_id: str = "_",
font_path: str = "./file/SuperMario256.ttf", cup_icon_dir: str = "./file/cup_icon"):
def get_cup_icon(id, font_path: str = "./file/SuperMario256.ttf", cup_icon_dir: str = "./file/cup_icon"):
"""
:param i: cup number
:param cup_icon_dir: directory to cup icon
:param font_path: path to the font used to generate icon
:param cup_id: id of the cup
:return: cup icon
"""
if os.path.exists(f"{cup_icon_dir}/{cup_id}.png"):
cup_icon = Image.open(f"{cup_icon_dir}/{cup_id}.png").resize((128, 128))
if os.path.exists(f"{cup_icon_dir}/{id}.png"):
cup_icon = Image.open(f"{cup_icon_dir}/{id}.png").resize((128, 128))
else:
cup_icon = Image.new("RGBA", (128, 128))
draw = ImageDraw.Draw(cup_icon)
font = ImageFont.truetype(font_path, 90)
draw.text((4 - 2, 4 - 2), "CT", (0, 0, 0), font=font)
draw.text((4 + 2, 4 - 2), "CT", (0, 0, 0), font=font)
draw.text((4 - 2, 4 + 2), "CT", (0, 0, 0), font=font)
draw.text((4 + 2, 4 + 2), "CT", (0, 0, 0), font=font)
draw.text((4, 4), "CT", (255, 165, 0), font=font)
draw.text((4, 4), "CT", (255, 165, 0), font=font, stroke_width=2, stroke_fill=(0, 0, 0))
font = ImageFont.truetype(font_path, 60)
draw.text((5 - 2, 80 - 2), "%03i" % i, (0, 0, 0), font=font)
draw.text((5 + 2, 80 - 2), "%03i" % i, (0, 0, 0), font=font)
draw.text((5 - 2, 80 + 2), "%03i" % i, (0, 0, 0), font=font)
draw.text((5 + 2, 80 + 2), "%03i" % i, (0, 0, 0), font=font)
draw.text((5, 80), "%03i" % id, (255, 165, 0), font=font, stroke_width=2, stroke_fill=(0, 0, 0))
draw.text((5, 80), "%03i" % i, (255, 165, 0), font=font)
return cup_icon
@ -102,16 +90,15 @@ class CT_Config:
CT_ICON_WIDTH = 128
icon_files = ["left", "right"]
total_cup_count = len(self.ordered_cups) + math.ceil(len(self.unordered_tracks) / 4)
ct_icon = Image.new("RGBA", (
CT_ICON_WIDTH, CT_ICON_WIDTH * (total_cup_count + 2))) # +2 because of left and right arrow
total_cup_count = math.ceil(len(self.all_tracks) // 4) + 10 # +10 because left, right, start at 0, 8 normal cup
ct_icon = Image.new("RGBA", (CT_ICON_WIDTH, CT_ICON_WIDTH * (total_cup_count + 2)))
# +2 because of left and right arrow
icon_files.extend([str(i) for i, cup in enumerate(self.ordered_cups)]) # adding ordered cup id
icon_files.extend(["_"] * ((len(self.unordered_tracks) // 4) + 1)) # creating unordered track icon
icon_files.extend(range(total_cup_count))
for i, id in enumerate(icon_files):
cup_icon = get_cup_icon(i, id)
ct_icon.paste(cup_icon, (0, i * CT_ICON_WIDTH))
for index, id in enumerate(icon_files): # index is a number, id can be string or number ("left", 0, 12, ...)
cup_icon = get_cup_icon(id)
ct_icon.paste(cup_icon, (0, index * CT_ICON_WIDTH))
return ct_icon

View file

@ -373,7 +373,8 @@ class Game:
if not self.gui.boolvar_disable_download.get():
while True:
download_returncode = track.download_wu8()
download_returncode = track.download_wu8(
GITHUB_DEV_BRANCH if self.gui.is_dev_version else GITHUB_MASTER_BRANCH)
if download_returncode == -1: # can't download
error_count += 1
if error_count > error_max: # Too much track wasn't correctly converted

View file

@ -38,10 +38,10 @@ class Track:
def convert_wu8_to_szs(self):
return wszst.normalize(src_file=self.file_wu8, use_popen=True)
def download_wu8(self):
def download_wu8(self, github_content_root: str):
returncode = 0
dl = requests.get(get_github_content_root(self) + self.file_wu8, allow_redirects=True, stream=True)
dl = requests.get(github_content_root + self.file_wu8, allow_redirects=True, stream=True)
if os.path.exists(self.file_wu8):
if int(dl.headers['Content-Length']) == os.path.getsize(self.file_wu8):
return 1

View file

@ -6,8 +6,6 @@ GITHUB_MASTER_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/m
GITHUB_DEV_BRANCH = f"https://raw.githubusercontent.com/{GITHUB_REPOSITORY}/dev/"
VERSION_FILE_URL = GITHUB_MASTER_BRANCH + "version"
get_github_content_root = lambda self: GITHUB_DEV_BRANCH if self.is_dev_version else GITHUB_MASTER_BRANCH
get_filename = lambda file: ".".join(file.split(".")[:-1])
get_nodir = lambda file: file.replace("\\", "/").split("/")[-1]
get_dir = lambda file: "/".join(file.replace("\\", "/").split("/")[:-1])