mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 19:28:25 +02:00
splitted all class in source into directory
This commit is contained in:
parent
d9b9f56169
commit
a01b390ce0
50 changed files with 1103 additions and 1001 deletions
|
@ -1,169 +0,0 @@
|
||||||
from .Cup import *
|
|
||||||
import math
|
|
||||||
from PIL import Image, ImageFont, ImageDraw
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def get_cup_icon(cup_id, font_path: str = "./file/SuperMario256.ttf", cup_icon_dir: str = "./file/cup_icon"):
|
|
||||||
"""
|
|
||||||
: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))
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
font = ImageFont.truetype(font_path, 60)
|
|
||||||
draw.text((5 - 2, 80 - 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
|
||||||
draw.text((5 + 2, 80 - 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
|
||||||
draw.text((5 - 2, 80 + 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
|
||||||
draw.text((5 + 2, 80 + 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
|
||||||
|
|
||||||
draw.text((5, 80), "%03i" % cup_id, (255, 165, 0), font=font)
|
|
||||||
return cup_icon
|
|
||||||
|
|
||||||
|
|
||||||
class CT_Config:
|
|
||||||
def __init__(self, version: str = None):
|
|
||||||
self.version = version
|
|
||||||
self.ordered_cups = []
|
|
||||||
self.unordered_tracks = []
|
|
||||||
self.all_tracks = []
|
|
||||||
self.all_version: set = {version}
|
|
||||||
|
|
||||||
def load_ctconfig_json(self, ctconfig_json: dict):
|
|
||||||
"""
|
|
||||||
:param ctconfig_json: json of the ctconfig to load
|
|
||||||
:return: ?
|
|
||||||
"""
|
|
||||||
self.ordered_cups = []
|
|
||||||
self.unordered_tracks = []
|
|
||||||
self.all_tracks = []
|
|
||||||
|
|
||||||
for cup_json in ctconfig_json["cup"].values(): # tracks with defined order
|
|
||||||
cup = Cup()
|
|
||||||
cup.load_from_json(cup_json)
|
|
||||||
if not cup.locked: # locked cup are not useful (they are original track or random track)
|
|
||||||
self.ordered_cups.append(cup)
|
|
||||||
self.all_tracks.extend(cup.tracks)
|
|
||||||
|
|
||||||
for track_json in ctconfig_json["tracks_list"]: # unordered tracks
|
|
||||||
track = Track()
|
|
||||||
track.load_from_json(track_json)
|
|
||||||
self.unordered_tracks.append(track)
|
|
||||||
self.all_tracks.append(track)
|
|
||||||
|
|
||||||
self.version = ctconfig_json["version"]
|
|
||||||
|
|
||||||
self.all_version = set()
|
|
||||||
for track in self.all_tracks:
|
|
||||||
self.all_version.add(track.since_version)
|
|
||||||
self.all_version = sorted(self.all_version)
|
|
||||||
|
|
||||||
def load_ctconfig_file(self, ctconfig_file: str = "./ct_config.json"):
|
|
||||||
"""
|
|
||||||
:param ctconfig_file: path to the ctconfig file
|
|
||||||
:return: ?
|
|
||||||
"""
|
|
||||||
with open(ctconfig_file, encoding="utf-8") as f:
|
|
||||||
ctconfig_json = json.load(f)
|
|
||||||
self.load_ctconfig_json(ctconfig_json)
|
|
||||||
|
|
||||||
def add_ordered_cup(self, cup: Cup):
|
|
||||||
"""
|
|
||||||
:param cup: a Cup object to add as an ordered cup
|
|
||||||
:return: ?
|
|
||||||
"""
|
|
||||||
self.ordered_cups.append(cup)
|
|
||||||
for track in cup.tracks:
|
|
||||||
self.all_version.add(track.since_version)
|
|
||||||
self.all_tracks.append(track)
|
|
||||||
|
|
||||||
def add_unordered_track(self, track: Track):
|
|
||||||
"""
|
|
||||||
:param track: a Track object to add as an unordered tracks
|
|
||||||
:return: ?
|
|
||||||
"""
|
|
||||||
self.unordered_tracks.append(track)
|
|
||||||
self.all_version.add(track.since_version)
|
|
||||||
self.all_tracks.append(track)
|
|
||||||
|
|
||||||
def search_tracks(self, values_list=False, not_value=False, **kwargs):
|
|
||||||
"""
|
|
||||||
:param values_list: search track with a value list instead of a single value
|
|
||||||
:param not_value: search track that does not have value
|
|
||||||
:param kwargs: any track property = any value
|
|
||||||
:return: track list respecting condition
|
|
||||||
"""
|
|
||||||
track = self.all_tracks.copy()
|
|
||||||
|
|
||||||
if values_list:
|
|
||||||
if not_value: filter_func = lambda track: getattr(track, keyword) not in value
|
|
||||||
else: filter_func = lambda track: getattr(track, keyword) in value
|
|
||||||
else:
|
|
||||||
if not_value: filter_func = lambda track: getattr(track, keyword) != value
|
|
||||||
else: filter_func = lambda track: getattr(track, keyword) == value
|
|
||||||
|
|
||||||
for keyword, value in kwargs.items():
|
|
||||||
track = list(filter(filter_func, track))
|
|
||||||
return track
|
|
||||||
|
|
||||||
def create_ctfile(self, directory="./file/"):
|
|
||||||
"""
|
|
||||||
:param directory: create CTFILE.txt and RCTFILE.txt in this directory
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
with open(directory+"CTFILE.txt", "w", encoding="utf-8") as ctfile, \
|
|
||||||
open(directory+"RCTFILE.txt", "w", encoding="utf-8") as rctfile:
|
|
||||||
header = (
|
|
||||||
"#CT-CODE\n"
|
|
||||||
"[RACING-TRACK-LIST]\n"
|
|
||||||
"%LE-FLAGS=1\n"
|
|
||||||
"%WIIMM-CUP=1\n"
|
|
||||||
"N N$SWAP | N$F_WII\n\n")
|
|
||||||
ctfile.write(header); rctfile.write(header)
|
|
||||||
|
|
||||||
# generate cup for undefined track
|
|
||||||
unordered_cups = []
|
|
||||||
for i, track in enumerate(self.unordered_tracks):
|
|
||||||
if i % 4 == 0:
|
|
||||||
_actual_cup = Cup(name=f"TL{i // 4}")
|
|
||||||
unordered_cups.append(_actual_cup)
|
|
||||||
_actual_cup.tracks[i % 4] = track
|
|
||||||
|
|
||||||
# all cups
|
|
||||||
for cup in self.ordered_cups + unordered_cups:
|
|
||||||
ctfile.write(cup.get_ctfile_cup(race=False))
|
|
||||||
rctfile.write(cup.get_ctfile_cup(race=True))
|
|
||||||
|
|
||||||
def get_cticon(self):
|
|
||||||
"""
|
|
||||||
get all cup icon into a single image
|
|
||||||
:return: ct_icon image
|
|
||||||
"""
|
|
||||||
CT_ICON_WIDTH = 128
|
|
||||||
icon_files = ["left", "right"]
|
|
||||||
|
|
||||||
total_cup_count = math.ceil(len(self.all_tracks) / 4)
|
|
||||||
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
|
|
||||||
|
|
||||||
for i, id in enumerate(icon_files):
|
|
||||||
cup_icon = get_cup_icon(i)
|
|
||||||
ct_icon.paste(cup_icon, (0, i * CT_ICON_WIDTH))
|
|
||||||
|
|
||||||
return ct_icon # ct_icon.save("./file/ct_icons.tpl.png")
|
|
15
source/CT_Config/__init__.py
Normal file
15
source/CT_Config/__init__.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class CT_Config:
|
||||||
|
def __init__(self, version: str = None):
|
||||||
|
self.version = version
|
||||||
|
self.ordered_cups = []
|
||||||
|
self.unordered_tracks = []
|
||||||
|
self.all_tracks = []
|
||||||
|
self.all_version = {version}
|
||||||
|
|
||||||
|
from .add_ordered_cup import add_ordered_cup
|
||||||
|
from .add_unordered_track import add_unordered_track
|
||||||
|
from .create_ctfile import create_ctfile
|
||||||
|
from .get_cticon import get_cticon
|
||||||
|
from .load_ctconfig_file import load_ctconfig_file
|
||||||
|
from .load_ctconfig_json import load_ctconfig_json
|
||||||
|
from .search_tracks import search_tracks
|
12
source/CT_Config/add_ordered_cup.py
Normal file
12
source/CT_Config/add_ordered_cup.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from source.Cup import Cup
|
||||||
|
|
||||||
|
|
||||||
|
def add_ordered_cup(self, cup: Cup):
|
||||||
|
"""
|
||||||
|
:param cup: a Cup object to add as an ordered cup
|
||||||
|
:return: ?
|
||||||
|
"""
|
||||||
|
self.ordered_cups.append(cup)
|
||||||
|
for track in cup.tracks:
|
||||||
|
self.all_version.add(track.since_version)
|
||||||
|
self.all_tracks.append(track)
|
11
source/CT_Config/add_unordered_track.py
Normal file
11
source/CT_Config/add_unordered_track.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from source.Track import Track
|
||||||
|
|
||||||
|
|
||||||
|
def add_unordered_track(self, track: Track):
|
||||||
|
"""
|
||||||
|
:param track: a Track object to add as an unordered tracks
|
||||||
|
:return: ?
|
||||||
|
"""
|
||||||
|
self.unordered_tracks.append(track)
|
||||||
|
self.all_version.add(track.since_version)
|
||||||
|
self.all_tracks.append(track)
|
29
source/CT_Config/create_ctfile.py
Normal file
29
source/CT_Config/create_ctfile.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from source.Cup import Cup
|
||||||
|
|
||||||
|
def create_ctfile(self, directory="./file/"):
|
||||||
|
"""
|
||||||
|
:param directory: create CTFILE.txt and RCTFILE.txt in this directory
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
with open(directory + "CTFILE.txt", "w", encoding="utf-8") as ctfile, \
|
||||||
|
open(directory + "RCTFILE.txt", "w", encoding="utf-8") as rctfile:
|
||||||
|
header = (
|
||||||
|
"#CT-CODE\n"
|
||||||
|
"[RACING-TRACK-LIST]\n"
|
||||||
|
"%LE-FLAGS=1\n"
|
||||||
|
"%WIIMM-CUP=1\n"
|
||||||
|
"N N$SWAP | N$F_WII\n\n")
|
||||||
|
ctfile.write(header); rctfile.write(header)
|
||||||
|
|
||||||
|
# generate cup for undefined track
|
||||||
|
unordered_cups = []
|
||||||
|
for i, track in enumerate(self.unordered_tracks):
|
||||||
|
if i % 4 == 0:
|
||||||
|
_actual_cup = Cup(name=f"TL{i // 4}")
|
||||||
|
unordered_cups.append(_actual_cup)
|
||||||
|
_actual_cup.tracks[i % 4] = track
|
||||||
|
|
||||||
|
# all cups
|
||||||
|
for cup in self.ordered_cups + unordered_cups:
|
||||||
|
ctfile.write(cup.get_ctfile_cup(race=False))
|
||||||
|
rctfile.write(cup.get_ctfile_cup(race=True))
|
55
source/CT_Config/get_cticon.py
Normal file
55
source/CT_Config/get_cticon.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
from PIL import Image, ImageFont, ImageDraw
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_cup_icon(cup_id, font_path: str = "./file/SuperMario256.ttf", cup_icon_dir: str = "./file/cup_icon"):
|
||||||
|
"""
|
||||||
|
: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))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
font = ImageFont.truetype(font_path, 60)
|
||||||
|
draw.text((5 - 2, 80 - 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
||||||
|
draw.text((5 + 2, 80 - 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
||||||
|
draw.text((5 - 2, 80 + 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
||||||
|
draw.text((5 + 2, 80 + 2), "%03i" % cup_id, (0, 0, 0), font=font)
|
||||||
|
|
||||||
|
draw.text((5, 80), "%03i" % cup_id, (255, 165, 0), font=font)
|
||||||
|
return cup_icon
|
||||||
|
|
||||||
|
|
||||||
|
def get_cticon(self):
|
||||||
|
"""
|
||||||
|
get all cup icon into a single image
|
||||||
|
:return: ct_icon image
|
||||||
|
"""
|
||||||
|
CT_ICON_WIDTH = 128
|
||||||
|
icon_files = ["left", "right"]
|
||||||
|
|
||||||
|
total_cup_count = math.ceil(len(self.all_tracks) / 4)
|
||||||
|
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
|
||||||
|
|
||||||
|
for i, id in enumerate(icon_files):
|
||||||
|
cup_icon = get_cup_icon(i)
|
||||||
|
ct_icon.paste(cup_icon, (0, i * CT_ICON_WIDTH))
|
||||||
|
|
||||||
|
return ct_icon
|
11
source/CT_Config/load_ctconfig_file.py
Normal file
11
source/CT_Config/load_ctconfig_file.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def load_ctconfig_file(self, ctconfig_file: str = "./ct_config.json"):
|
||||||
|
"""
|
||||||
|
:param ctconfig_file: path to the ctconfig file
|
||||||
|
:return: ?
|
||||||
|
"""
|
||||||
|
with open(ctconfig_file, encoding="utf-8") as f:
|
||||||
|
ctconfig_json = json.load(f)
|
||||||
|
self.load_ctconfig_json(ctconfig_json)
|
32
source/CT_Config/load_ctconfig_json.py
Normal file
32
source/CT_Config/load_ctconfig_json.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from source.Cup import Cup
|
||||||
|
from source.Track import Track
|
||||||
|
|
||||||
|
|
||||||
|
def load_ctconfig_json(self, ctconfig_json: dict):
|
||||||
|
"""
|
||||||
|
:param ctconfig_json: json of the ctconfig to load
|
||||||
|
:return: ?
|
||||||
|
"""
|
||||||
|
self.ordered_cups = []
|
||||||
|
self.unordered_tracks = []
|
||||||
|
self.all_tracks = []
|
||||||
|
|
||||||
|
for cup_json in ctconfig_json["cup"].values(): # tracks with defined order
|
||||||
|
cup = Cup()
|
||||||
|
cup.load_from_json(cup_json)
|
||||||
|
if not cup.locked: # locked cup are not useful (they are original track or random track)
|
||||||
|
self.ordered_cups.append(cup)
|
||||||
|
self.all_tracks.extend(cup.tracks)
|
||||||
|
|
||||||
|
for track_json in ctconfig_json["tracks_list"]: # unordered tracks
|
||||||
|
track = Track()
|
||||||
|
track.load_from_json(track_json)
|
||||||
|
self.unordered_tracks.append(track)
|
||||||
|
self.all_tracks.append(track)
|
||||||
|
|
||||||
|
self.version = ctconfig_json["version"]
|
||||||
|
|
||||||
|
self.all_version = set()
|
||||||
|
for track in self.all_tracks:
|
||||||
|
self.all_version.add(track.since_version)
|
||||||
|
self.all_version = sorted(self.all_version)
|
19
source/CT_Config/search_tracks.py
Normal file
19
source/CT_Config/search_tracks.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
def search_tracks(self, values_list=False, not_value=False, **kwargs):
|
||||||
|
"""
|
||||||
|
:param values_list: search track with a value list instead of a single value
|
||||||
|
:param not_value: search track that does not have value
|
||||||
|
:param kwargs: any track property = any value
|
||||||
|
:return: track list respecting condition
|
||||||
|
"""
|
||||||
|
track = self.all_tracks.copy()
|
||||||
|
|
||||||
|
if values_list:
|
||||||
|
if not_value: filter_func = lambda track: getattr(track, keyword) not in value
|
||||||
|
else: filter_func = lambda track: getattr(track, keyword) in value
|
||||||
|
else:
|
||||||
|
if not_value: filter_func = lambda track: getattr(track, keyword) != value
|
||||||
|
else: filter_func = lambda track: getattr(track, keyword) == value
|
||||||
|
|
||||||
|
for keyword, value in kwargs.items():
|
||||||
|
track = list(filter(filter_func, track))
|
||||||
|
return track
|
|
@ -1,36 +0,0 @@
|
||||||
from .Track import *
|
|
||||||
|
|
||||||
|
|
||||||
class Cup:
|
|
||||||
def __init__(self, name: str = None,
|
|
||||||
track1: Track = None,
|
|
||||||
track2: Track = None,
|
|
||||||
track3: Track = None,
|
|
||||||
track4: Track = None, locked: bool = False,
|
|
||||||
*args, **kwargs):
|
|
||||||
|
|
||||||
self.name = name
|
|
||||||
self.tracks = [
|
|
||||||
track1 if track1 else Track(),
|
|
||||||
track2 if track2 else Track(),
|
|
||||||
track3 if track3 else Track(),
|
|
||||||
track4 if track4 else Track()
|
|
||||||
]
|
|
||||||
self.locked = locked
|
|
||||||
|
|
||||||
def load_from_json(self, cup: dict):
|
|
||||||
for key, value in cup.items(): # load all value in the json as class attribute
|
|
||||||
if key != "tracks": setattr(self, key, value)
|
|
||||||
else: # if the key is tracks
|
|
||||||
for i, track_json in value.items(): # load all tracks from their json
|
|
||||||
self.tracks[int(i)].load_from_json(track_json)
|
|
||||||
|
|
||||||
def get_ctfile_cup(self, race=False):
|
|
||||||
"""
|
|
||||||
:param race: is it a text used for Race_*.szs ?
|
|
||||||
:return: ctfile definition for the cup
|
|
||||||
"""
|
|
||||||
ctfile_cup = f'\nC "{self.name}"\n'
|
|
||||||
for track in self.tracks:
|
|
||||||
ctfile_cup += track.get_ctfile_track(race)
|
|
||||||
return ctfile_cup
|
|
22
source/Cup/__init__.py
Normal file
22
source/Cup/__init__.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from source.Track import Track
|
||||||
|
|
||||||
|
|
||||||
|
class Cup:
|
||||||
|
def __init__(self, name: str = None,
|
||||||
|
track1: Track = None,
|
||||||
|
track2: Track = None,
|
||||||
|
track3: Track = None,
|
||||||
|
track4: Track = None, locked: bool = False,
|
||||||
|
*args, **kwargs):
|
||||||
|
|
||||||
|
self.name = name
|
||||||
|
self.tracks = [
|
||||||
|
track1 if track1 else Track(),
|
||||||
|
track2 if track2 else Track(),
|
||||||
|
track3 if track3 else Track(),
|
||||||
|
track4 if track4 else Track()
|
||||||
|
]
|
||||||
|
self.locked = locked
|
||||||
|
|
||||||
|
from .get_ctfile_cup import get_ctfile_cup
|
||||||
|
from .load_from_json import load_from_json
|
9
source/Cup/get_ctfile_cup.py
Normal file
9
source/Cup/get_ctfile_cup.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
def get_ctfile_cup(self, race=False):
|
||||||
|
"""
|
||||||
|
:param race: is it a text used for Race_*.szs ?
|
||||||
|
:return: ctfile definition for the cup
|
||||||
|
"""
|
||||||
|
ctfile_cup = f'\nC "{self.name}"\n'
|
||||||
|
for track in self.tracks:
|
||||||
|
ctfile_cup += track.get_ctfile_track(race)
|
||||||
|
return ctfile_cup
|
7
source/Cup/load_from_json.py
Normal file
7
source/Cup/load_from_json.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
def load_from_json(self, cup: dict):
|
||||||
|
for key, value in cup.items(): # load all value in the json as class attribute
|
||||||
|
if key != "tracks":
|
||||||
|
setattr(self, key, value)
|
||||||
|
else: # if the key is tracks
|
||||||
|
for i, track_json in value.items(): # load all tracks from their json
|
||||||
|
self.tracks[int(i)].load_from_json(track_json)
|
501
source/Game.py
501
source/Game.py
|
@ -1,501 +0,0 @@
|
||||||
from . import wszst
|
|
||||||
from .definition import *
|
|
||||||
|
|
||||||
from threading import Thread
|
|
||||||
from PIL import Image
|
|
||||||
import subprocess
|
|
||||||
import shutil
|
|
||||||
import json
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
|
|
||||||
region_id_to_name = {
|
|
||||||
"J": "JAP",
|
|
||||||
"P": "PAL",
|
|
||||||
"K": "KO",
|
|
||||||
"E": "USA"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidGamePath(Exception):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__("This path is not valid !")
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidFormat(Exception):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__("This game format is not supported !")
|
|
||||||
|
|
||||||
|
|
||||||
class TooMuchDownloadFailed(Exception):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__("Too much download failed !")
|
|
||||||
|
|
||||||
|
|
||||||
class TooMuchSha1CheckFailed(Exception):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__("Too much sha1 check failed !")
|
|
||||||
|
|
||||||
|
|
||||||
class CantConvertTrack(Exception):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__("Can't convert track, check if download are enabled.")
|
|
||||||
|
|
||||||
|
|
||||||
def patch_img_desc(img_desc_path: str = "./file/img_desc", dest_dir: str = "./file"):
|
|
||||||
il = Image.open(img_desc_path+"/illustration.png")
|
|
||||||
il_16_9 = il.resize((832, 456))
|
|
||||||
il_4_3 = il.resize((608, 456))
|
|
||||||
|
|
||||||
for file_lang in glob.glob(img_desc_path+"??.png"):
|
|
||||||
img_lang = Image.open(file_lang)
|
|
||||||
img_lang_16_9 = img_lang.resize((832, 456))
|
|
||||||
img_lang_4_3 = img_lang.resize((608, 456))
|
|
||||||
|
|
||||||
new_16_9 = Image.new("RGBA", (832, 456), (0, 0, 0, 255))
|
|
||||||
new_16_9.paste(il_16_9, (0, 0), il_16_9)
|
|
||||||
new_16_9.paste(img_lang_16_9, (0, 0), img_lang_16_9)
|
|
||||||
new_16_9.save(dest_dir+f"/strapA_16_9_832x456{get_filename(get_nodir(file_lang))}.png")
|
|
||||||
|
|
||||||
new_4_3 = Image.new("RGBA", (608, 456), (0, 0, 0, 255))
|
|
||||||
new_4_3.paste(il_4_3, (0, 0), il_4_3)
|
|
||||||
new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3)
|
|
||||||
new_4_3.save(dest_dir+f"/strapA_608x456{get_filename(get_nodir(file_lang))}.png")
|
|
||||||
|
|
||||||
|
|
||||||
def patch_image(fc, gui):
|
|
||||||
for i, file in enumerate(fc["img"]):
|
|
||||||
gui.progress(statut=gui.translate("Converting images") + f"\n({i + 1}/{len(fc['img'])}) {file}", add=1)
|
|
||||||
subprocess.run(["./tools/szs/wimgt", "ENCODE", "./file/" + file, "-x", fc["img"][file], "--overwrite"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)
|
|
||||||
|
|
||||||
|
|
||||||
def patch_bmg(gamefile: str, gui): # gamefile est le fichier .szs trouvé dans le /files/Scene/UI/ du jeu
|
|
||||||
NINTENDO_CWF_REPLACE = "Wiimmfi"
|
|
||||||
MAINMENU_REPLACE = f"MKWFaraphel {gui.ctconfig.version}"
|
|
||||||
menu_replacement = {
|
|
||||||
"CWF de Nintendo": NINTENDO_CWF_REPLACE,
|
|
||||||
"Wi-Fi Nintendo": NINTENDO_CWF_REPLACE,
|
|
||||||
"CWF Nintendo": NINTENDO_CWF_REPLACE,
|
|
||||||
"Nintendo WFC": NINTENDO_CWF_REPLACE,
|
|
||||||
"Wi-Fi": NINTENDO_CWF_REPLACE,
|
|
||||||
"インターネット": NINTENDO_CWF_REPLACE,
|
|
||||||
|
|
||||||
"Menu principal": MAINMENU_REPLACE,
|
|
||||||
"Menú principal": MAINMENU_REPLACE,
|
|
||||||
"Main Menu": MAINMENU_REPLACE,
|
|
||||||
"トップメニュー": MAINMENU_REPLACE,
|
|
||||||
|
|
||||||
"Mario Kart Wii": MAINMENU_REPLACE,
|
|
||||||
}
|
|
||||||
|
|
||||||
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
|
|
||||||
gui.progress(statut=gui.translate("Patching text", " ", bmglang), add=1)
|
|
||||||
|
|
||||||
subprocess.run(["./tools/szs/wszst", "EXTRACT", get_nodir(gamefile), "-d", get_nodir(gamefile) + ".d",
|
|
||||||
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile))
|
|
||||||
|
|
||||||
# Menu.bmg
|
|
||||||
bmgmenu = subprocess.run(["./tools/szs/wbmgt", "CAT", get_nodir(gamefile) + ".d/message/Menu.bmg"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile),
|
|
||||||
check=True, stdout=subprocess.PIPE).stdout.decode()
|
|
||||||
|
|
||||||
# Common.bmg
|
|
||||||
bmgtracks = subprocess.run(["./tools/szs/wbmgt", "CAT", get_nodir(gamefile) + ".d/message/Common.bmg"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile),
|
|
||||||
check=True, stdout=subprocess.PIPE).stdout.decode()
|
|
||||||
trackheader = "#--- standard track names"
|
|
||||||
trackend = "2328"
|
|
||||||
bmgtracks = bmgtracks[bmgtracks.find(trackheader) + len(trackheader):bmgtracks.find(trackend)]
|
|
||||||
|
|
||||||
with open("./file/ExtraCommon.txt", "w", encoding="utf8") as f:
|
|
||||||
f.write("#BMG\n\n"
|
|
||||||
f" 703e\t= \\\\c{{white}}{gui.translate('Random: All tracks', lang=bmglang)}\n"
|
|
||||||
f" 703f\t= \\\\c{{white}}{gui.translate('Random: Original tracks', lang=bmglang)}\n"
|
|
||||||
f" 7040\t= \\\\c{{white}}{gui.translate('Random: Custom Tracks', lang=bmglang)}\n"
|
|
||||||
f" 7041\t= \\\\c{{white}}{gui.translate('Random: New tracks', lang=bmglang)}\n")
|
|
||||||
|
|
||||||
for bmgtrack in bmgtracks.split("\n"):
|
|
||||||
if "=" in bmgtrack:
|
|
||||||
|
|
||||||
prefix = ""
|
|
||||||
if "T" in bmgtrack[:bmgtrack.find("=")]:
|
|
||||||
sTid = bmgtrack.find("T")
|
|
||||||
Tid = bmgtrack[sTid:sTid + 3]
|
|
||||||
if Tid[1] in "1234":
|
|
||||||
prefix = trackname_color["Wii"] + " " # Si la course est original à la wii
|
|
||||||
Tid = hex(bmgID_track_move[Tid])[2:]
|
|
||||||
|
|
||||||
else: # Arena
|
|
||||||
sTid = bmgtrack.find("U") + 1
|
|
||||||
Tid = bmgtrack[sTid:sTid + 2]
|
|
||||||
Tid = hex((int(Tid[0]) - 1) * 5 + (int(Tid[1]) - 1) + 0x7020)[2:]
|
|
||||||
|
|
||||||
Tname = bmgtrack[bmgtrack.find("= ") + 2:]
|
|
||||||
f.write(f" {Tid}\t= {prefix}{Tname}\n")
|
|
||||||
|
|
||||||
if not (os.path.exists("./file/tmp/")): os.makedirs("./file/tmp/")
|
|
||||||
|
|
||||||
filecopy(gamefile + ".d/message/Common.bmg", "./file/tmp/Common.bmg")
|
|
||||||
bmgcommon = subprocess.run(
|
|
||||||
["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/CTFILE.txt", "--patch-bmg",
|
|
||||||
"OVERWRITE=./file/tmp/Common.bmg", "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode()
|
|
||||||
rbmgcommon = subprocess.run(
|
|
||||||
["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/RCTFILE.txt", "--patch-bmg",
|
|
||||||
"OVERWRITE=./file/tmp/Common.bmg", "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode()
|
|
||||||
|
|
||||||
shutil.rmtree(gamefile + ".d")
|
|
||||||
os.remove("./file/tmp/Common.bmg")
|
|
||||||
os.remove("./file/ExtraCommon.txt")
|
|
||||||
|
|
||||||
def finalise(file, bmgtext, replacement_list=None):
|
|
||||||
if replacement_list:
|
|
||||||
for text, colored_text in replacement_list.items(): bmgtext = bmgtext.replace(text, colored_text)
|
|
||||||
with open(file, "w", encoding="utf-8") as f:
|
|
||||||
f.write(bmgtext)
|
|
||||||
subprocess.run(["./tools/szs/wbmgt", "ENCODE", get_nodir(file), "--overwrite"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(file))
|
|
||||||
os.remove(file)
|
|
||||||
|
|
||||||
finalise(f"./file/Menu_{bmglang}.txt", bmgmenu, menu_replacement)
|
|
||||||
finalise(f"./file/Common_{bmglang}.txt", bmgcommon)
|
|
||||||
finalise(f"./file/Common_R{bmglang}.txt", rbmgcommon)
|
|
||||||
|
|
||||||
|
|
||||||
def patch_track(gui):
|
|
||||||
max_process = gui.intvar_process_track.get()
|
|
||||||
process_list = {}
|
|
||||||
error_count, error_max = 0, 3
|
|
||||||
|
|
||||||
def add_process(track):
|
|
||||||
nonlocal error_count, error_max, process_list
|
|
||||||
track_file = track.get_track_name()
|
|
||||||
total_track = len(gui.ctconfig.all_tracks)
|
|
||||||
|
|
||||||
process_list[track_file] = None # Used for showing track in progress even if there's no process
|
|
||||||
gui.progress(statut=gui.translate("Converting tracks", f"\n({i + 1}/{total_track})\n",
|
|
||||||
"\n".join(process_list.keys())), add=1)
|
|
||||||
|
|
||||||
for _track in [track.file_szs, track.file_wu8]:
|
|
||||||
if os.path.exists(_track):
|
|
||||||
if os.path.getsize(_track) < 1000: # File under this size are corrupted
|
|
||||||
os.remove(_track)
|
|
||||||
|
|
||||||
if not gui.boolvar_disable_download.get():
|
|
||||||
while True:
|
|
||||||
download_returncode = track.download_wu8()
|
|
||||||
if download_returncode == -1: # can't download
|
|
||||||
error_count += 1
|
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
|
||||||
"""messagebox.showerror(
|
|
||||||
gui.translate("Error"),
|
|
||||||
gui.translate("Too much tracks had a download issue."))
|
|
||||||
return -1"""
|
|
||||||
raise TooMuchDownloadFailed()
|
|
||||||
else:
|
|
||||||
"""messagebox.showwarning(gui.translate("Warning"),
|
|
||||||
gui.translate("Can't download this track !",
|
|
||||||
f" ({error_count} / {error_max})"))"""
|
|
||||||
elif download_returncode == 2:
|
|
||||||
break # if download is disabled, do not check sha1
|
|
||||||
|
|
||||||
if track.sha1:
|
|
||||||
if not gui.boolvar_dont_check_track_sha1.get():
|
|
||||||
if not track.check_sha1(): # Check si le sha1 du fichier est le bon
|
|
||||||
error_count += 1
|
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
|
||||||
"""messagebox.showerror(
|
|
||||||
gui.translate("Error"),
|
|
||||||
gui.translate("Too much tracks had an issue during sha1 check."))"""
|
|
||||||
raise TooMuchSha1CheckFailed()
|
|
||||||
continue
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
if not (
|
|
||||||
os.path.exists(track.file_szs)) or download_returncode == 3: # returncode 3 is track has been updated
|
|
||||||
if os.path.exists(track.file_wu8):
|
|
||||||
process_list[track_file] = track.convert_wu8_to_szs()
|
|
||||||
else:
|
|
||||||
"""messagebox.showerror(gui.translate("Error"),
|
|
||||||
gui.translate("Can't convert track.\nEnable track download and retry."))"""
|
|
||||||
raise CantConvertTrack()
|
|
||||||
elif gui.boolvar_del_track_after_conv.get():
|
|
||||||
os.remove(track.file_wu8)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def clean_process():
|
|
||||||
nonlocal error_count, error_max, process_list
|
|
||||||
|
|
||||||
for track_file, process in process_list.copy().items():
|
|
||||||
if process is not None:
|
|
||||||
if process.poll() is None:
|
|
||||||
pass # if the process is still running
|
|
||||||
else: # process ended
|
|
||||||
process_list.pop(track_file)
|
|
||||||
stderr = process.stderr.read()
|
|
||||||
if b"wszst: ERROR" in stderr: # Error occured
|
|
||||||
os.remove(track.file_szs)
|
|
||||||
error_count += 1
|
|
||||||
if error_count > error_max: # Too much track wasn't correctly converted
|
|
||||||
"""messagebox.showerror(
|
|
||||||
gui.translate("Error"),
|
|
||||||
gui.translate("Too much track had a conversion issue."))"""
|
|
||||||
raise CantConvertTrack
|
|
||||||
else: # if the error max hasn't been reach
|
|
||||||
"""messagebox.showwarning(
|
|
||||||
gui.translate("Warning"),
|
|
||||||
gui.translate("The track", " ", track.file_wu8,
|
|
||||||
"do not have been properly converted.",
|
|
||||||
f" ({error_count} / {error_max})"))"""
|
|
||||||
else:
|
|
||||||
if gui.boolvar_del_track_after_conv.get(): os.remove(track.file_wu8)
|
|
||||||
else:
|
|
||||||
process_list.pop(track_file)
|
|
||||||
if not (any(process_list.values())): return 1 # si il n'y a plus de processus
|
|
||||||
|
|
||||||
if len(process_list):
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
for i, track in enumerate(gui.ctconfig.all_tracks):
|
|
||||||
while True:
|
|
||||||
if len(process_list) < max_process:
|
|
||||||
returncode = add_process(track)
|
|
||||||
if returncode == 0:
|
|
||||||
break
|
|
||||||
elif returncode == -1:
|
|
||||||
return -1 # if error occur, stop function
|
|
||||||
elif clean_process() == -1:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
while True:
|
|
||||||
returncode = clean_process()
|
|
||||||
if returncode == 1:
|
|
||||||
break # End the process if all process ended
|
|
||||||
elif returncode == 0:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
|
||||||
def __init__(self, path: str, region_ID: str = "P", game_ID: str = "RMCP01"):
|
|
||||||
if not os.path.exists(path): raise InvalidGamePath()
|
|
||||||
self.extension = get_extension(path).upper()
|
|
||||||
self.path = path
|
|
||||||
self.region = region_id_to_name[region_ID]
|
|
||||||
self.region_ID = region_ID
|
|
||||||
self.game_ID = game_ID
|
|
||||||
|
|
||||||
def extract_game(self):
|
|
||||||
if self.extension == "DOL":
|
|
||||||
self.path = os.path.realpath(self.path + "/../../") # main.dol is in PATH/sys/, so go back 2 dir upper
|
|
||||||
|
|
||||||
elif self.extension in ["ISO", "WBFS", "CSIO"]:
|
|
||||||
# Fiding a directory name that doesn't already exist
|
|
||||||
directory_name, i = "MKWiiFaraphel", 1
|
|
||||||
while True:
|
|
||||||
path_dir = os.path.realpath(self.path + f"/../{directory_name}")
|
|
||||||
if not (os.path.exists(path_dir)): break
|
|
||||||
directory_name, i = f"MKWiiFaraphel ({i})", i + 1
|
|
||||||
|
|
||||||
wszst.extract(self.path, path_dir)
|
|
||||||
|
|
||||||
self.path = path_dir
|
|
||||||
if os.path.exists(self.path + "/DATA"): self.path += "/DATA"
|
|
||||||
self.extension = "DOL"
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise InvalidFormat()
|
|
||||||
|
|
||||||
if glob.glob(self.path + "/files/rel/lecode-???.bin"): # if a LECODE file is already here
|
|
||||||
raise Warning("ROM Already patched") # warning already patched
|
|
||||||
|
|
||||||
with open(self.path + "/setup.txt") as f: setup = f.read()
|
|
||||||
setup = setup[setup.find("!part-id = ") + len("!part-id = "):]
|
|
||||||
self.game_ID = setup[:setup.find("\n")]
|
|
||||||
|
|
||||||
self.region_ID = self.game_ID[3]
|
|
||||||
self.region = region_id_to_name[self.region_ID] if self.region_ID in region_id_to_name else self.region
|
|
||||||
|
|
||||||
def patch_autoadd(self, auto_add_dir: str = "./file/auto-add"):
|
|
||||||
if os.path.exists(auto_add_dir): shutil.rmtree(auto_add_dir)
|
|
||||||
if not os.path.exists(self.path + "/tmp/"): os.makedirs(self.path + "/tmp/")
|
|
||||||
subprocess.run(["./tools/szs/wszst", "AUTOADD", get_nodir(self.path) + "/files/Race/Course/",
|
|
||||||
"--DEST", get_nodir(self.path) + "/tmp/auto-add/"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
shutil.move(self.path + "/tmp/auto-add/", auto_add_dir)
|
|
||||||
shutil.rmtree(self.path + "/tmp/")
|
|
||||||
|
|
||||||
def install_mod(self, gui):
|
|
||||||
def func():
|
|
||||||
try:
|
|
||||||
with open("./fs.json") as f: fs = json.load(f)
|
|
||||||
|
|
||||||
# This part is used to estimate the max_step
|
|
||||||
extracted_file = []
|
|
||||||
max_step, step = 1, 0
|
|
||||||
|
|
||||||
def count_rf(path):
|
|
||||||
nonlocal max_step
|
|
||||||
max_step += 1
|
|
||||||
if get_extension(path) == "szs":
|
|
||||||
if not (os.path.realpath(path) in extracted_file):
|
|
||||||
extracted_file.append(os.path.realpath(path))
|
|
||||||
max_step += 1
|
|
||||||
|
|
||||||
for fp in fs:
|
|
||||||
for f in glob.glob(self.path + "/files/" + fp, recursive=True):
|
|
||||||
if type(fs[fp]) == str:
|
|
||||||
count_rf(path=f)
|
|
||||||
elif type(fs[fp]) == dict:
|
|
||||||
for nf in fs[fp]:
|
|
||||||
if type(fs[fp][nf]) == str:
|
|
||||||
count_rf(path=f)
|
|
||||||
elif type(fs[fp][nf]) == list:
|
|
||||||
for ffp in fs[fp][nf]: count_rf(path=f)
|
|
||||||
###
|
|
||||||
extracted_file = []
|
|
||||||
max_step += 4 # PATCH main.dol and PATCH lecode.bin, converting, changing ID
|
|
||||||
gui.progress(show=True, indeter=False, statut=gui.translate("Installing mod"), max=max_step, step=0)
|
|
||||||
|
|
||||||
def replace_file(path, file, subpath="/"):
|
|
||||||
gui.progress(statut=gui.translate("Editing", "\n", get_nodir(path)), add=1)
|
|
||||||
extension = get_extension(path)
|
|
||||||
|
|
||||||
if extension == "szs":
|
|
||||||
if not (os.path.realpath(path) in extracted_file):
|
|
||||||
subprocess.run(["./tools/szs/wszst", "EXTRACT", get_nodir(path), "-d", get_nodir(path) + ".d",
|
|
||||||
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(path),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
extracted_file.append(os.path.realpath(path))
|
|
||||||
|
|
||||||
szs_extract_path = path + ".d"
|
|
||||||
if os.path.exists(szs_extract_path + subpath):
|
|
||||||
if subpath[-1] == "/":
|
|
||||||
filecopy(f"./file/{file}", szs_extract_path + subpath + file)
|
|
||||||
else:
|
|
||||||
filecopy(f"./file/{file}", szs_extract_path + subpath)
|
|
||||||
|
|
||||||
elif path[-1] == "/":
|
|
||||||
filecopy(f"./file/{file}", path + file)
|
|
||||||
else:
|
|
||||||
filecopy(f"./file/{file}", path)
|
|
||||||
|
|
||||||
for fp in fs:
|
|
||||||
for f in glob.glob(self.path + "/files/" + fp, recursive=True):
|
|
||||||
if type(fs[fp]) == str:
|
|
||||||
replace_file(path=f, file=fs[fp])
|
|
||||||
elif type(fs[fp]) == dict:
|
|
||||||
for nf in fs[fp]:
|
|
||||||
if type(fs[fp][nf]) == str:
|
|
||||||
replace_file(path=f, subpath=nf, file=fs[fp][nf])
|
|
||||||
elif type(fs[fp][nf]) == list:
|
|
||||||
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
|
|
||||||
|
|
||||||
for file in extracted_file:
|
|
||||||
gui.progress(statut=gui.translate("Recompilating", "\n", get_nodir(file)), add=1)
|
|
||||||
subprocess.run(["./tools/szs/wszst", "CREATE", get_nodir(file) + ".d", "-d", get_nodir(file),
|
|
||||||
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(file),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
if os.path.exists(file + ".d"): shutil.rmtree(file + ".d")
|
|
||||||
|
|
||||||
gui.progress(statut=gui.translate("Patch main.dol"), add=1)
|
|
||||||
subprocess.run(["./tools/szs/wstrt", "patch", get_nodir(self.path) + "/sys/main.dol", "--clean-dol",
|
|
||||||
"--add-lecode"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
|
|
||||||
gui.progress(statut=gui.translate("Patch lecode.bin"), add=1)
|
|
||||||
|
|
||||||
shutil.copytree("./file/Track/", self.path+"/files/Race/Course/", dirs_exist_ok=True)
|
|
||||||
if not(os.path.exists(self.path+"/tmp/")): os.makedirs(self.path+"/tmp/")
|
|
||||||
filecopy("./file/CTFILE.txt", self.path+"/tmp/CTFILE.txt")
|
|
||||||
filecopy("./file/lpar-default.txt", self.path + "/tmp/lpar-default.txt")
|
|
||||||
filecopy(f"./file/lecode-{self.region}.bin", self.path + f"/tmp/lecode-{self.region}.bin")
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
["./tools/szs/wlect", "patch", f"./tmp/lecode-{self.region}.bin", "-od",
|
|
||||||
f"./files/rel/lecode-{self.region}.bin", "--track-dir", "./files/Race/Course/",
|
|
||||||
"--move-tracks", "./files/Race/Course/", "--le-define", "./tmp/CTFILE.txt", "--lpar",
|
|
||||||
"./tmp/lpar-default.txt", "--overwrite"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=self.path, check=True, stdout=subprocess.PIPE)
|
|
||||||
|
|
||||||
shutil.rmtree(self.path + "/tmp/")
|
|
||||||
|
|
||||||
output_format = gui.stringvar_game_format.get()
|
|
||||||
gui.progress(statut=gui.translate("Converting to", " ", output_format), add=1)
|
|
||||||
|
|
||||||
if output_format in ["ISO", "WBFS", "CISO"]:
|
|
||||||
path_game_format: str = os.path.realpath(self.path + "/../MKWFaraphel." + output_format.lower())
|
|
||||||
subprocess.run(["./tools/wit/wit", "COPY", get_nodir(self.path), "--DEST",
|
|
||||||
get_nodir(path_game_format), f"--{output_format.lower()}", "--overwrite"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(path_game_format),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
shutil.rmtree(self.path)
|
|
||||||
self.path = path_game_format
|
|
||||||
|
|
||||||
gui.progress(statut=gui.translate("Changing game's ID"), add=1)
|
|
||||||
subprocess.run(["./tools/wit/wit", "EDIT", get_nodir(self.path), "--id",
|
|
||||||
f"RMC{self.region_ID}60", "--name",
|
|
||||||
f"Mario Kart Wii Faraphel {gui.ctconfig.version}", "--modify", "ALL"],
|
|
||||||
creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
|
||||||
check=True, stdout=subprocess.PIPE)
|
|
||||||
|
|
||||||
# messagebox.showinfo(gui.translate("End"), gui.translate("The mod has been installed !"))
|
|
||||||
|
|
||||||
except: gui.log_error()
|
|
||||||
finally: gui.progress(show=False)
|
|
||||||
|
|
||||||
t = Thread(target=func)
|
|
||||||
t.setDaemon(True)
|
|
||||||
t.start()
|
|
||||||
return t
|
|
||||||
|
|
||||||
def convert_to(self, format: str = "FST"):
|
|
||||||
"""
|
|
||||||
:param format: game format (ISO, WBFS, ...)
|
|
||||||
:return: converted game path
|
|
||||||
"""
|
|
||||||
|
|
||||||
def patch_file(self, gui):
|
|
||||||
def func():
|
|
||||||
try:
|
|
||||||
if not (os.path.exists("./file/Track-WU8/")): os.makedirs("./file/Track-WU8/")
|
|
||||||
with open("./convert_file.json") as f:
|
|
||||||
fc = json.load(f)
|
|
||||||
max_step = len(fc["img"]) + len(gui.ctconfig.all_tracks) + 3 + len("EGFIS")
|
|
||||||
|
|
||||||
gui.progress(show=True, indeter=False, statut=gui.translate("Converting files"), max=max_step, step=0)
|
|
||||||
gui.progress(statut=gui.translate("Configurating LE-CODE"), add=1)
|
|
||||||
gui.ctconfig.create_ctfile()
|
|
||||||
|
|
||||||
gui.progress(statut=gui.translate("Creating ct_icon.png"), add=1)
|
|
||||||
ct_icon = gui.ctconfig.get_cticon()
|
|
||||||
ct_icon.save("./file/ct_icons.tpl.png")
|
|
||||||
|
|
||||||
gui.progress(statut=gui.translate("Creating descriptive images"), add=1)
|
|
||||||
patch_img_desc()
|
|
||||||
patch_image(fc, gui)
|
|
||||||
for file in glob.glob(self.path + "/files/Scene/UI/MenuSingle_?.szs"): patch_bmg(file, gui)
|
|
||||||
# MenuSingle could be any other file, Common and Menu are all the same in all other files.
|
|
||||||
self.patch_autoadd()
|
|
||||||
if patch_track(gui) != 0: return
|
|
||||||
|
|
||||||
gui.button_install_mod.grid(row=2, column=1, columnspan=2, sticky="NEWS")
|
|
||||||
gui.button_install_mod.config(
|
|
||||||
text=gui.translate("Install mod", " (v", gui.ctconfig.version, ")"))
|
|
||||||
|
|
||||||
except: gui.log_error()
|
|
||||||
finally: gui.progress(show=False)
|
|
||||||
|
|
||||||
t = Thread(target=func)
|
|
||||||
t.setDaemon(True)
|
|
||||||
t.start()
|
|
||||||
return t
|
|
24
source/Game/__init__.py
Normal file
24
source/Game/__init__.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
from source.definition import *
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .exception import *
|
||||||
|
|
||||||
|
|
||||||
|
class Game:
|
||||||
|
def __init__(self, path: str, region_ID: str = "P", game_ID: str = "RMCP01"):
|
||||||
|
if not os.path.exists(path): raise InvalidGamePath()
|
||||||
|
self.extension = get_extension(path).upper()
|
||||||
|
self.path = path
|
||||||
|
self.region = region_id_to_name[region_ID]
|
||||||
|
self.region_ID = region_ID
|
||||||
|
self.game_ID = game_ID
|
||||||
|
|
||||||
|
from .convert_to import convert_to
|
||||||
|
from .extract import extract
|
||||||
|
from .install_mod import install_mod
|
||||||
|
from .patch_autoadd import patch_autoadd
|
||||||
|
from .patch_bmg import patch_bmg
|
||||||
|
from .patch_file import patch_file
|
||||||
|
from .patch_image import patch_image
|
||||||
|
from .patch_img_desc import patch_img_desc
|
||||||
|
from .patch_track import patch_track
|
7
source/Game/convert_to.py
Normal file
7
source/Game/convert_to.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
def convert_to(self, format: str = "FST"):
|
||||||
|
"""
|
||||||
|
:param format: game format (ISO, WBFS, ...)
|
||||||
|
:return: converted game path
|
||||||
|
"""
|
||||||
|
|
||||||
|
# TODO: code this function
|
23
source/Game/exception.py
Normal file
23
source/Game/exception.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
class InvalidGamePath(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("This path is not valid !")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidFormat(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("This game format is not supported !")
|
||||||
|
|
||||||
|
|
||||||
|
class TooMuchDownloadFailed(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("Too much download failed !")
|
||||||
|
|
||||||
|
|
||||||
|
class TooMuchSha1CheckFailed(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("Too much sha1 check failed !")
|
||||||
|
|
||||||
|
|
||||||
|
class CantConvertTrack(Exception):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("Can't convert track, check if download are enabled.")
|
39
source/Game/extract.py
Normal file
39
source/Game/extract.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .exception import *
|
||||||
|
from source.definition import *
|
||||||
|
from source import wszst
|
||||||
|
|
||||||
|
|
||||||
|
def extract(self):
|
||||||
|
if self.extension == "DOL":
|
||||||
|
self.path = os.path.realpath(self.path + "/../../") # main.dol is in PATH/sys/, so go back 2 dir upper
|
||||||
|
|
||||||
|
elif self.extension in ["ISO", "WBFS", "CSIO"]:
|
||||||
|
# Fiding a directory name that doesn't already exist
|
||||||
|
directory_name, i = "MKWiiFaraphel", 1
|
||||||
|
while True:
|
||||||
|
path_dir = os.path.realpath(self.path + f"/../{directory_name}")
|
||||||
|
if not (os.path.exists(path_dir)): break
|
||||||
|
directory_name, i = f"MKWiiFaraphel ({i})", i + 1
|
||||||
|
|
||||||
|
wszst.extract(self.path, path_dir)
|
||||||
|
|
||||||
|
self.path = path_dir
|
||||||
|
if os.path.exists(self.path + "/DATA"): self.path += "/DATA"
|
||||||
|
self.extension = "DOL"
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise InvalidFormat()
|
||||||
|
|
||||||
|
if glob.glob(self.path + "/files/rel/lecode-???.bin"): # if a LECODE file is already here
|
||||||
|
raise Warning("ROM Already patched") # warning already patched
|
||||||
|
|
||||||
|
with open(self.path + "/setup.txt") as f:
|
||||||
|
setup = f.read()
|
||||||
|
setup = setup[setup.find("!part-id = ") + len("!part-id = "):]
|
||||||
|
self.game_ID = setup[:setup.find("\n")]
|
||||||
|
|
||||||
|
self.region_ID = self.game_ID[3]
|
||||||
|
self.region = region_id_to_name[self.region_ID] if self.region_ID in region_id_to_name else self.region
|
136
source/Game/install_mod.py
Normal file
136
source/Game/install_mod.py
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
from threading import Thread
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import json
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def install_mod(self, gui):
|
||||||
|
def func():
|
||||||
|
try:
|
||||||
|
with open("./fs.json") as f:
|
||||||
|
fs = json.load(f)
|
||||||
|
|
||||||
|
# This part is used to estimate the max_step
|
||||||
|
extracted_file = []
|
||||||
|
max_step, step = 1, 0
|
||||||
|
|
||||||
|
def count_rf(path):
|
||||||
|
nonlocal max_step
|
||||||
|
max_step += 1
|
||||||
|
if get_extension(path) == "szs":
|
||||||
|
if not (os.path.realpath(path) in extracted_file):
|
||||||
|
extracted_file.append(os.path.realpath(path))
|
||||||
|
max_step += 1
|
||||||
|
|
||||||
|
for fp in fs:
|
||||||
|
for f in glob.glob(self.path + "/files/" + fp, recursive=True):
|
||||||
|
if type(fs[fp]) == str:
|
||||||
|
count_rf(path=f)
|
||||||
|
elif type(fs[fp]) == dict:
|
||||||
|
for nf in fs[fp]:
|
||||||
|
if type(fs[fp][nf]) == str:
|
||||||
|
count_rf(path=f)
|
||||||
|
elif type(fs[fp][nf]) == list:
|
||||||
|
for ffp in fs[fp][nf]: count_rf(path=f)
|
||||||
|
###
|
||||||
|
extracted_file = []
|
||||||
|
max_step += 4 # PATCH main.dol and PATCH lecode.bin, converting, changing ID
|
||||||
|
gui.progress(show=True, indeter=False, statut=gui.translate("Installing mod"), max=max_step, step=0)
|
||||||
|
|
||||||
|
def replace_file(path, file, subpath="/"):
|
||||||
|
gui.progress(statut=gui.translate("Editing", "\n", get_nodir(path)), add=1)
|
||||||
|
extension = get_extension(path)
|
||||||
|
|
||||||
|
if extension == "szs":
|
||||||
|
if not (os.path.realpath(path) in extracted_file):
|
||||||
|
subprocess.run(["./tools/szs/wszst", "EXTRACT", get_nodir(path), "-d", get_nodir(path) + ".d",
|
||||||
|
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(path),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
extracted_file.append(os.path.realpath(path))
|
||||||
|
|
||||||
|
szs_extract_path = path + ".d"
|
||||||
|
if os.path.exists(szs_extract_path + subpath):
|
||||||
|
if subpath[-1] == "/":
|
||||||
|
filecopy(f"./file/{file}", szs_extract_path + subpath + file)
|
||||||
|
else:
|
||||||
|
filecopy(f"./file/{file}", szs_extract_path + subpath)
|
||||||
|
|
||||||
|
elif path[-1] == "/":
|
||||||
|
filecopy(f"./file/{file}", path + file)
|
||||||
|
else:
|
||||||
|
filecopy(f"./file/{file}", path)
|
||||||
|
|
||||||
|
for fp in fs:
|
||||||
|
for f in glob.glob(self.path + "/files/" + fp, recursive=True):
|
||||||
|
if type(fs[fp]) == str:
|
||||||
|
replace_file(path=f, file=fs[fp])
|
||||||
|
elif type(fs[fp]) == dict:
|
||||||
|
for nf in fs[fp]:
|
||||||
|
if type(fs[fp][nf]) == str:
|
||||||
|
replace_file(path=f, subpath=nf, file=fs[fp][nf])
|
||||||
|
elif type(fs[fp][nf]) == list:
|
||||||
|
for ffp in fs[fp][nf]: replace_file(path=f, subpath=nf, file=ffp)
|
||||||
|
|
||||||
|
for file in extracted_file:
|
||||||
|
gui.progress(statut=gui.translate("Recompilating", "\n", get_nodir(file)), add=1)
|
||||||
|
subprocess.run(["./tools/szs/wszst", "CREATE", get_nodir(file) + ".d", "-d", get_nodir(file),
|
||||||
|
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(file),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
if os.path.exists(file + ".d"): shutil.rmtree(file + ".d")
|
||||||
|
|
||||||
|
gui.progress(statut=gui.translate("Patch main.dol"), add=1)
|
||||||
|
subprocess.run(["./tools/szs/wstrt", "patch", get_nodir(self.path) + "/sys/main.dol", "--clean-dol",
|
||||||
|
"--add-lecode"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
gui.progress(statut=gui.translate("Patch lecode.bin"), add=1)
|
||||||
|
|
||||||
|
shutil.copytree("./file/Track/", self.path + "/files/Race/Course/", dirs_exist_ok=True)
|
||||||
|
if not (os.path.exists(self.path + "/tmp/")): os.makedirs(self.path + "/tmp/")
|
||||||
|
filecopy("./file/CTFILE.txt", self.path + "/tmp/CTFILE.txt")
|
||||||
|
filecopy("./file/lpar-default.txt", self.path + "/tmp/lpar-default.txt")
|
||||||
|
filecopy(f"./file/lecode-{self.region}.bin", self.path + f"/tmp/lecode-{self.region}.bin")
|
||||||
|
|
||||||
|
subprocess.run(
|
||||||
|
["./tools/szs/wlect", "patch", f"./tmp/lecode-{self.region}.bin", "-od",
|
||||||
|
f"./files/rel/lecode-{self.region}.bin", "--track-dir", "./files/Race/Course/",
|
||||||
|
"--move-tracks", "./files/Race/Course/", "--le-define", "./tmp/CTFILE.txt", "--lpar",
|
||||||
|
"./tmp/lpar-default.txt", "--overwrite"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=self.path, check=True, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
shutil.rmtree(self.path + "/tmp/")
|
||||||
|
|
||||||
|
output_format = gui.stringvar_game_format.get()
|
||||||
|
gui.progress(statut=gui.translate("Converting to", " ", output_format), add=1)
|
||||||
|
|
||||||
|
if output_format in ["ISO", "WBFS", "CISO"]:
|
||||||
|
path_game_format: str = os.path.realpath(self.path + "/../MKWFaraphel." + output_format.lower())
|
||||||
|
subprocess.run(["./tools/wit/wit", "COPY", get_nodir(self.path), "--DEST",
|
||||||
|
get_nodir(path_game_format), f"--{output_format.lower()}", "--overwrite"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(path_game_format),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
shutil.rmtree(self.path)
|
||||||
|
self.path = path_game_format
|
||||||
|
|
||||||
|
gui.progress(statut=gui.translate("Changing game's ID"), add=1)
|
||||||
|
subprocess.run(["./tools/wit/wit", "EDIT", get_nodir(self.path), "--id",
|
||||||
|
f"RMC{self.region_ID}60", "--name",
|
||||||
|
f"Mario Kart Wii Faraphel {gui.ctconfig.version}", "--modify", "ALL"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
# messagebox.showinfo(gui.translate("End"), gui.translate("The mod has been installed !"))
|
||||||
|
|
||||||
|
except:
|
||||||
|
gui.log_error()
|
||||||
|
finally:
|
||||||
|
gui.progress(show=False)
|
||||||
|
|
||||||
|
t = Thread(target=func)
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
return t
|
16
source/Game/patch_autoadd.py
Normal file
16
source/Game/patch_autoadd.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def patch_autoadd(self, auto_add_dir: str = "./file/auto-add"):
|
||||||
|
if os.path.exists(auto_add_dir): shutil.rmtree(auto_add_dir)
|
||||||
|
if not os.path.exists(self.path + "/tmp/"): os.makedirs(self.path + "/tmp/")
|
||||||
|
subprocess.run(["./tools/szs/wszst", "AUTOADD", get_nodir(self.path) + "/files/Race/Course/",
|
||||||
|
"--DEST", get_nodir(self.path) + "/tmp/auto-add/"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(self.path),
|
||||||
|
check=True, stdout=subprocess.PIPE)
|
||||||
|
shutil.move(self.path + "/tmp/auto-add/", auto_add_dir)
|
||||||
|
shutil.rmtree(self.path + "/tmp/")
|
99
source/Game/patch_bmg.py
Normal file
99
source/Game/patch_bmg.py
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def patch_bmg(gamefile: str, gui): # gamefile est le fichier .szs trouvé dans le /files/Scene/UI/ du jeu
|
||||||
|
NINTENDO_CWF_REPLACE = "Wiimmfi"
|
||||||
|
MAINMENU_REPLACE = f"MKWFaraphel {gui.ctconfig.version}"
|
||||||
|
menu_replacement = {
|
||||||
|
"CWF de Nintendo": NINTENDO_CWF_REPLACE,
|
||||||
|
"Wi-Fi Nintendo": NINTENDO_CWF_REPLACE,
|
||||||
|
"CWF Nintendo": NINTENDO_CWF_REPLACE,
|
||||||
|
"Nintendo WFC": NINTENDO_CWF_REPLACE,
|
||||||
|
"Wi-Fi": NINTENDO_CWF_REPLACE,
|
||||||
|
"インターネット": NINTENDO_CWF_REPLACE,
|
||||||
|
|
||||||
|
"Menu principal": MAINMENU_REPLACE,
|
||||||
|
"Menú principal": MAINMENU_REPLACE,
|
||||||
|
"Main Menu": MAINMENU_REPLACE,
|
||||||
|
"トップメニュー": MAINMENU_REPLACE,
|
||||||
|
|
||||||
|
"Mario Kart Wii": MAINMENU_REPLACE,
|
||||||
|
}
|
||||||
|
|
||||||
|
bmglang = gamefile[-len("E.txt"):-len(".txt")] # Langue du fichier
|
||||||
|
gui.progress(statut=gui.translate("Patching text", " ", bmglang), add=1)
|
||||||
|
|
||||||
|
subprocess.run(["./tools/szs/wszst", "EXTRACT", get_nodir(gamefile), "-d", get_nodir(gamefile) + ".d",
|
||||||
|
"--overwrite"], creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile))
|
||||||
|
|
||||||
|
# Menu.bmg
|
||||||
|
bmgmenu = subprocess.run(["./tools/szs/wbmgt", "CAT", get_nodir(gamefile) + ".d/message/Menu.bmg"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile),
|
||||||
|
check=True, stdout=subprocess.PIPE).stdout.decode()
|
||||||
|
|
||||||
|
# Common.bmg
|
||||||
|
bmgtracks = subprocess.run(["./tools/szs/wbmgt", "CAT", get_nodir(gamefile) + ".d/message/Common.bmg"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(gamefile),
|
||||||
|
check=True, stdout=subprocess.PIPE).stdout.decode()
|
||||||
|
trackheader = "#--- standard track names"
|
||||||
|
trackend = "2328"
|
||||||
|
bmgtracks = bmgtracks[bmgtracks.find(trackheader) + len(trackheader):bmgtracks.find(trackend)]
|
||||||
|
|
||||||
|
with open("./file/ExtraCommon.txt", "w", encoding="utf8") as f:
|
||||||
|
f.write("#BMG\n\n"
|
||||||
|
f" 703e\t= \\\\c{{white}}{gui.translate('Random: All tracks', lang=bmglang)}\n"
|
||||||
|
f" 703f\t= \\\\c{{white}}{gui.translate('Random: Original tracks', lang=bmglang)}\n"
|
||||||
|
f" 7040\t= \\\\c{{white}}{gui.translate('Random: Custom Tracks', lang=bmglang)}\n"
|
||||||
|
f" 7041\t= \\\\c{{white}}{gui.translate('Random: New tracks', lang=bmglang)}\n")
|
||||||
|
|
||||||
|
for bmgtrack in bmgtracks.split("\n"):
|
||||||
|
if "=" in bmgtrack:
|
||||||
|
|
||||||
|
prefix = ""
|
||||||
|
if "T" in bmgtrack[:bmgtrack.find("=")]:
|
||||||
|
sTid = bmgtrack.find("T")
|
||||||
|
Tid = bmgtrack[sTid:sTid + 3]
|
||||||
|
if Tid[1] in "1234":
|
||||||
|
prefix = trackname_color["Wii"] + " " # Si la course est original à la wii
|
||||||
|
Tid = hex(bmgID_track_move[Tid])[2:]
|
||||||
|
|
||||||
|
else: # Arena
|
||||||
|
sTid = bmgtrack.find("U") + 1
|
||||||
|
Tid = bmgtrack[sTid:sTid + 2]
|
||||||
|
Tid = hex((int(Tid[0]) - 1) * 5 + (int(Tid[1]) - 1) + 0x7020)[2:]
|
||||||
|
|
||||||
|
Tname = bmgtrack[bmgtrack.find("= ") + 2:]
|
||||||
|
f.write(f" {Tid}\t= {prefix}{Tname}\n")
|
||||||
|
|
||||||
|
if not (os.path.exists("./file/tmp/")): os.makedirs("./file/tmp/")
|
||||||
|
|
||||||
|
filecopy(gamefile + ".d/message/Common.bmg", "./file/tmp/Common.bmg")
|
||||||
|
bmgcommon = subprocess.run(
|
||||||
|
["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/CTFILE.txt", "--patch-bmg",
|
||||||
|
"OVERWRITE=./file/tmp/Common.bmg", "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode()
|
||||||
|
rbmgcommon = subprocess.run(
|
||||||
|
["tools/szs/wctct", "bmg", "--le-code", "--long", "./file/RCTFILE.txt", "--patch-bmg",
|
||||||
|
"OVERWRITE=./file/tmp/Common.bmg", "--patch-bmg", "OVERWRITE=./file/ExtraCommon.txt"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE).stdout.decode()
|
||||||
|
|
||||||
|
shutil.rmtree(gamefile + ".d")
|
||||||
|
os.remove("./file/tmp/Common.bmg")
|
||||||
|
os.remove("./file/ExtraCommon.txt")
|
||||||
|
|
||||||
|
def finalise(file, bmgtext, replacement_list=None):
|
||||||
|
if replacement_list:
|
||||||
|
for text, colored_text in replacement_list.items(): bmgtext = bmgtext.replace(text, colored_text)
|
||||||
|
with open(file, "w", encoding="utf-8") as f:
|
||||||
|
f.write(bmgtext)
|
||||||
|
subprocess.run(["./tools/szs/wbmgt", "ENCODE", get_nodir(file), "--overwrite"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, cwd=get_dir(file))
|
||||||
|
os.remove(file)
|
||||||
|
|
||||||
|
finalise(f"./file/Menu_{bmglang}.txt", bmgmenu, menu_replacement)
|
||||||
|
finalise(f"./file/Common_{bmglang}.txt", bmgcommon)
|
||||||
|
finalise(f"./file/Common_R{bmglang}.txt", rbmgcommon)
|
48
source/Game/patch_file.py
Normal file
48
source/Game/patch_file.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
from threading import Thread
|
||||||
|
import glob
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .patch_img_desc import patch_img_desc
|
||||||
|
from .patch_image import patch_image
|
||||||
|
from .patch_track import patch_track
|
||||||
|
from .patch_bmg import patch_bmg
|
||||||
|
|
||||||
|
|
||||||
|
def patch_file(self, gui):
|
||||||
|
def func():
|
||||||
|
try:
|
||||||
|
if not (os.path.exists("./file/Track-WU8/")): os.makedirs("./file/Track-WU8/")
|
||||||
|
with open("./convert_file.json") as f:
|
||||||
|
fc = json.load(f)
|
||||||
|
max_step = len(fc["img"]) + len(gui.ctconfig.all_tracks) + 3 + len("EGFIS")
|
||||||
|
|
||||||
|
gui.progress(show=True, indeter=False, statut=gui.translate("Converting files"), max=max_step, step=0)
|
||||||
|
gui.progress(statut=gui.translate("Configurating LE-CODE"), add=1)
|
||||||
|
gui.ctconfig.create_ctfile()
|
||||||
|
|
||||||
|
gui.progress(statut=gui.translate("Creating ct_icon.png"), add=1)
|
||||||
|
ct_icon = gui.ctconfig.get_cticon()
|
||||||
|
ct_icon.save("./file/ct_icons.tpl.png")
|
||||||
|
|
||||||
|
gui.progress(statut=gui.translate("Creating descriptive images"), add=1)
|
||||||
|
patch_img_desc()
|
||||||
|
patch_image(fc, gui)
|
||||||
|
for file in glob.glob(self.path + "/files/Scene/UI/MenuSingle_?.szs"): patch_bmg(file, gui)
|
||||||
|
# MenuSingle could be any other file, Common and Menu are all the same in all other files.
|
||||||
|
self.patch_autoadd()
|
||||||
|
if patch_track(gui) != 0: return
|
||||||
|
|
||||||
|
gui.button_install_mod.grid(row=2, column=1, columnspan=2, sticky="NEWS")
|
||||||
|
gui.button_install_mod.config(
|
||||||
|
text=gui.translate("Install mod", " (v", gui.ctconfig.version, ")"))
|
||||||
|
|
||||||
|
except:
|
||||||
|
gui.log_error()
|
||||||
|
finally:
|
||||||
|
gui.progress(show=False)
|
||||||
|
|
||||||
|
t = Thread(target=func)
|
||||||
|
t.setDaemon(True)
|
||||||
|
t.start()
|
||||||
|
return t
|
10
source/Game/patch_image.py
Normal file
10
source/Game/patch_image.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def patch_image(fc, gui):
|
||||||
|
for i, file in enumerate(fc["img"]):
|
||||||
|
gui.progress(statut=gui.translate("Converting images") + f"\n({i + 1}/{len(fc['img'])}) {file}", add=1)
|
||||||
|
subprocess.run(["./tools/szs/wimgt", "ENCODE", "./file/" + file, "-x", fc["img"][file], "--overwrite"],
|
||||||
|
creationflags=CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)
|
25
source/Game/patch_img_desc.py
Normal file
25
source/Game/patch_img_desc.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from PIL import Image
|
||||||
|
import glob
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def patch_img_desc(img_desc_path: str = "./file/img_desc", dest_dir: str = "./file"):
|
||||||
|
il = Image.open(img_desc_path+"/illustration.png")
|
||||||
|
il_16_9 = il.resize((832, 456))
|
||||||
|
il_4_3 = il.resize((608, 456))
|
||||||
|
|
||||||
|
for file_lang in glob.glob(img_desc_path+"??.png"):
|
||||||
|
img_lang = Image.open(file_lang)
|
||||||
|
img_lang_16_9 = img_lang.resize((832, 456))
|
||||||
|
img_lang_4_3 = img_lang.resize((608, 456))
|
||||||
|
|
||||||
|
new_16_9 = Image.new("RGBA", (832, 456), (0, 0, 0, 255))
|
||||||
|
new_16_9.paste(il_16_9, (0, 0), il_16_9)
|
||||||
|
new_16_9.paste(img_lang_16_9, (0, 0), img_lang_16_9)
|
||||||
|
new_16_9.save(dest_dir+f"/strapA_16_9_832x456{get_filename(get_nodir(file_lang))}.png")
|
||||||
|
|
||||||
|
new_4_3 = Image.new("RGBA", (608, 456), (0, 0, 0, 255))
|
||||||
|
new_4_3.paste(il_4_3, (0, 0), il_4_3)
|
||||||
|
new_4_3.paste(img_lang_4_3, (0, 0), img_lang_4_3)
|
||||||
|
new_4_3.save(dest_dir+f"/strapA_608x456{get_filename(get_nodir(file_lang))}.png")
|
123
source/Game/patch_track.py
Normal file
123
source/Game/patch_track.py
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .exception import *
|
||||||
|
|
||||||
|
|
||||||
|
def patch_track(gui):
|
||||||
|
max_process = gui.intvar_process_track.get()
|
||||||
|
process_list = {}
|
||||||
|
error_count, error_max = 0, 3
|
||||||
|
|
||||||
|
def add_process(track):
|
||||||
|
nonlocal error_count, error_max, process_list
|
||||||
|
track_file = track.get_track_name()
|
||||||
|
total_track = len(gui.ctconfig.all_tracks)
|
||||||
|
|
||||||
|
process_list[track_file] = None # Used for showing track in progress even if there's no process
|
||||||
|
gui.progress(statut=gui.translate("Converting tracks", f"\n({i + 1}/{total_track})\n",
|
||||||
|
"\n".join(process_list.keys())), add=1)
|
||||||
|
|
||||||
|
for _track in [track.file_szs, track.file_wu8]:
|
||||||
|
if os.path.exists(_track):
|
||||||
|
if os.path.getsize(_track) < 1000: # File under this size are corrupted
|
||||||
|
os.remove(_track)
|
||||||
|
|
||||||
|
if not gui.boolvar_disable_download.get():
|
||||||
|
while True:
|
||||||
|
download_returncode = track.download_wu8()
|
||||||
|
if download_returncode == -1: # can't download
|
||||||
|
error_count += 1
|
||||||
|
if error_count > error_max: # Too much track wasn't correctly converted
|
||||||
|
"""messagebox.showerror(
|
||||||
|
gui.translate("Error"),
|
||||||
|
gui.translate("Too much tracks had a download issue."))
|
||||||
|
return -1"""
|
||||||
|
raise TooMuchDownloadFailed()
|
||||||
|
else:
|
||||||
|
"""messagebox.showwarning(gui.translate("Warning"),
|
||||||
|
gui.translate("Can't download this track !",
|
||||||
|
f" ({error_count} / {error_max})"))"""
|
||||||
|
elif download_returncode == 2:
|
||||||
|
break # if download is disabled, do not check sha1
|
||||||
|
|
||||||
|
if track.sha1:
|
||||||
|
if not gui.boolvar_dont_check_track_sha1.get():
|
||||||
|
if not track.check_sha1(): # Check si le sha1 du fichier est le bon
|
||||||
|
error_count += 1
|
||||||
|
if error_count > error_max: # Too much track wasn't correctly converted
|
||||||
|
"""messagebox.showerror(
|
||||||
|
gui.translate("Error"),
|
||||||
|
gui.translate("Too much tracks had an issue during sha1 check."))"""
|
||||||
|
raise TooMuchSha1CheckFailed()
|
||||||
|
continue
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
if not (
|
||||||
|
os.path.exists(track.file_szs)) or download_returncode == 3: # returncode 3 is track has been updated
|
||||||
|
if os.path.exists(track.file_wu8):
|
||||||
|
process_list[track_file] = track.convert_wu8_to_szs()
|
||||||
|
else:
|
||||||
|
"""messagebox.showerror(gui.translate("Error"),
|
||||||
|
gui.translate("Can't convert track.\nEnable track download and retry."))"""
|
||||||
|
raise CantConvertTrack()
|
||||||
|
elif gui.boolvar_del_track_after_conv.get():
|
||||||
|
os.remove(track.file_wu8)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def clean_process():
|
||||||
|
nonlocal error_count, error_max, process_list
|
||||||
|
|
||||||
|
for track_file, process in process_list.copy().items():
|
||||||
|
if process is not None:
|
||||||
|
if process.poll() is None:
|
||||||
|
pass # if the process is still running
|
||||||
|
else: # process ended
|
||||||
|
process_list.pop(track_file)
|
||||||
|
stderr = process.stderr.read()
|
||||||
|
if b"wszst: ERROR" in stderr: # Error occured
|
||||||
|
os.remove(track.file_szs)
|
||||||
|
error_count += 1
|
||||||
|
if error_count > error_max: # Too much track wasn't correctly converted
|
||||||
|
"""messagebox.showerror(
|
||||||
|
gui.translate("Error"),
|
||||||
|
gui.translate("Too much track had a conversion issue."))"""
|
||||||
|
raise CantConvertTrack
|
||||||
|
else: # if the error max hasn't been reach
|
||||||
|
"""messagebox.showwarning(
|
||||||
|
gui.translate("Warning"),
|
||||||
|
gui.translate("The track", " ", track.file_wu8,
|
||||||
|
"do not have been properly converted.",
|
||||||
|
f" ({error_count} / {error_max})"))"""
|
||||||
|
else:
|
||||||
|
if gui.boolvar_del_track_after_conv.get(): os.remove(track.file_wu8)
|
||||||
|
else:
|
||||||
|
process_list.pop(track_file)
|
||||||
|
if not (any(process_list.values())): return 1 # si il n'y a plus de processus
|
||||||
|
|
||||||
|
if len(process_list):
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
for i, track in enumerate(gui.ctconfig.all_tracks):
|
||||||
|
while True:
|
||||||
|
if len(process_list) < max_process:
|
||||||
|
returncode = add_process(track)
|
||||||
|
if returncode == 0:
|
||||||
|
break
|
||||||
|
elif returncode == -1:
|
||||||
|
return -1 # if error occur, stop function
|
||||||
|
elif clean_process() == -1:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
returncode = clean_process()
|
||||||
|
if returncode == 1:
|
||||||
|
break # End the process if all process ended
|
||||||
|
elif returncode == 0:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
return 0
|
|
@ -1,27 +1,15 @@
|
||||||
from tkinter import *
|
|
||||||
from tkinter import messagebox, filedialog, ttk
|
from tkinter import messagebox, filedialog, ttk
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import subprocess
|
from tkinter import *
|
||||||
import traceback
|
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .definition import *
|
from source.CT_Config import CT_Config
|
||||||
from .CT_Config import *
|
from source.Game.exception import *
|
||||||
from .Option import *
|
from source.Option import Option
|
||||||
from .Game import *
|
from source.Game import Game
|
||||||
|
|
||||||
|
|
||||||
with open("./translation.json", encoding="utf-8") as f:
|
class Gui:
|
||||||
translation_dict = json.load(f)
|
|
||||||
|
|
||||||
|
|
||||||
def restart():
|
|
||||||
subprocess.Popen([sys.executable] + sys.argv, creationflags=CREATE_NO_WINDOW, cwd=os.getcwd())
|
|
||||||
exit()
|
|
||||||
|
|
||||||
|
|
||||||
class Gui():
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.root = Tk()
|
self.root = Tk()
|
||||||
|
|
||||||
|
@ -54,8 +42,8 @@ class Gui():
|
||||||
|
|
||||||
self.menu_language = Menu(self.menu_bar, tearoff=0)
|
self.menu_language = Menu(self.menu_bar, tearoff=0)
|
||||||
self.menu_bar.add_cascade(label=self.translate("Language"), menu=self.menu_language)
|
self.menu_bar.add_cascade(label=self.translate("Language"), menu=self.menu_language)
|
||||||
self.menu_language.add_radiobutton(label="Français", variable=self.stringvar_language, value="fr", command=lambda: self.option.edit("language", "fr", restart=True))
|
self.menu_language.add_radiobutton(label="Français", variable=self.stringvar_language, value="fr", command=lambda: self.option.edit("language", "fr", need_restart=True))
|
||||||
self.menu_language.add_radiobutton(label="English", variable=self.stringvar_language, value="en", command=lambda: self.option.edit("language", "en", restart=True))
|
self.menu_language.add_radiobutton(label="English", variable=self.stringvar_language, value="en", command=lambda: self.option.edit("language", "en", need_restart=True))
|
||||||
|
|
||||||
self.menu_format = Menu(self.menu_bar, tearoff=0)
|
self.menu_format = Menu(self.menu_bar, tearoff=0)
|
||||||
self.menu_bar.add_cascade(label=self.translate("Format"), menu=self.menu_format)
|
self.menu_bar.add_cascade(label=self.translate("Format"), menu=self.menu_format)
|
||||||
|
@ -90,7 +78,6 @@ class Gui():
|
||||||
self.menu_advanced.add_radiobutton(label=self.translate("4 ", "process"), variable=self.intvar_process_track, value=4, command=lambda: self.option.edit("process_track", 4))
|
self.menu_advanced.add_radiobutton(label=self.translate("4 ", "process"), variable=self.intvar_process_track, value=4, command=lambda: self.option.edit("process_track", 4))
|
||||||
self.menu_advanced.add_radiobutton(label=self.translate("8 ", "process"), variable=self.intvar_process_track, value=8, command=lambda: self.option.edit("process_track", 8))
|
self.menu_advanced.add_radiobutton(label=self.translate("8 ", "process"), variable=self.intvar_process_track, value=8, command=lambda: self.option.edit("process_track", 8))
|
||||||
|
|
||||||
|
|
||||||
self.frame_language = Frame(self.root)
|
self.frame_language = Frame(self.root)
|
||||||
self.frame_language.grid(row=1, column=1, sticky="E")
|
self.frame_language.grid(row=1, column=1, sticky="E")
|
||||||
|
|
||||||
|
@ -119,7 +106,7 @@ class Gui():
|
||||||
try:
|
try:
|
||||||
self.game = Game(path = entry_game_path.get())
|
self.game = Game(path = entry_game_path.get())
|
||||||
self.progress(show=True, indeter=True, statut=self.translate("Extracting the game..."))
|
self.progress(show=True, indeter=True, statut=self.translate("Extracting the game..."))
|
||||||
self.game.extract_game()
|
self.game.extract()
|
||||||
self.frame_action.grid(row=3, column=1, sticky="NEWS")
|
self.frame_action.grid(row=3, column=1, sticky="NEWS")
|
||||||
except InvalidGamePath:
|
except InvalidGamePath:
|
||||||
messagebox.showerror(self.translate("Error"), self.translate("The file path in invalid"))
|
messagebox.showerror(self.translate("Error"), self.translate("The file path in invalid"))
|
||||||
|
@ -142,7 +129,7 @@ class Gui():
|
||||||
def do_everything():
|
def do_everything():
|
||||||
def func():
|
def func():
|
||||||
use_path().join()
|
use_path().join()
|
||||||
self.game.patch_file(gui).join()
|
self.game.patch_file(self).join()
|
||||||
self.game.install_mod(self).join()
|
self.game.install_mod(self).join()
|
||||||
|
|
||||||
if messagebox.askyesno(self.translate("Experimental functionality"),
|
if messagebox.askyesno(self.translate("Experimental functionality"),
|
||||||
|
@ -155,7 +142,6 @@ class Gui():
|
||||||
self.button_do_everything = Button(self.frame_game_path_action, text=self.translate("Do everything"), relief=RIDGE, command=do_everything)
|
self.button_do_everything = Button(self.frame_game_path_action, text=self.translate("Do everything"), relief=RIDGE, command=do_everything)
|
||||||
self.button_do_everything.grid(row=1, column=2, sticky="NEWS")
|
self.button_do_everything.grid(row=1, column=2, sticky="NEWS")
|
||||||
|
|
||||||
|
|
||||||
self.frame_action = LabelFrame(self.root, text=self.translate("Action"))
|
self.frame_action = LabelFrame(self.root, text=self.translate("Action"))
|
||||||
|
|
||||||
self.button_prepare_file = Button(self.frame_action, text=self.translate("Prepare files"), relief=RIDGE, command=lambda: self.game.patch_file(self), width=45)
|
self.button_prepare_file = Button(self.frame_action, text=self.translate("Prepare files"), relief=RIDGE, command=lambda: self.game.patch_file(self), width=45)
|
||||||
|
@ -166,120 +152,9 @@ class Gui():
|
||||||
self.progressbar = ttk.Progressbar(self.root)
|
self.progressbar = ttk.Progressbar(self.root)
|
||||||
self.progresslabel = Label(self.root)
|
self.progresslabel = Label(self.root)
|
||||||
|
|
||||||
|
from .check_update import check_update
|
||||||
def check_update(self):
|
from .log_error import log_error
|
||||||
try:
|
from .progress import progress
|
||||||
gitversion = requests.get(VERSION_FILE_URL, allow_redirects=True).json()
|
from .restart import restart
|
||||||
with open("./version", "rb") as f:
|
from .state_button import state_button
|
||||||
locversion = json.load(f)
|
from .translate import translate
|
||||||
|
|
||||||
if ((float(gitversion["version"]) > float(locversion["version"])) or # if github version is newer than
|
|
||||||
(float(gitversion["version"]) == float(locversion["version"])) and # local version
|
|
||||||
float(gitversion["subversion"]) > float(locversion["subversion"])):
|
|
||||||
if messagebox.askyesno(
|
|
||||||
self.translate("Update available !"),
|
|
||||||
self.translate("An update is available, do you want to install it ?",
|
|
||||||
f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> "
|
|
||||||
f"{gitversion['version']}.{gitversion['subversion']}\n"
|
|
||||||
f"Changelog :\n{gitversion['changelog']}")):
|
|
||||||
|
|
||||||
if not (os.path.exists("./Updater/Updater.exe")):
|
|
||||||
dl = requests.get(gitversion["updater_bin"], allow_redirects=True)
|
|
||||||
with open("./download.zip", "wb") as file:
|
|
||||||
print(self.translate("Downloading the Updater..."))
|
|
||||||
file.write(dl.content)
|
|
||||||
print(self.translate("end of the download, extracting..."))
|
|
||||||
|
|
||||||
with zipfile.ZipFile("./download.zip") as file:
|
|
||||||
file.extractall("./Updater/")
|
|
||||||
print(self.translate("finished extracting"))
|
|
||||||
|
|
||||||
os.remove("./download.zip")
|
|
||||||
print(self.translate("starting application..."))
|
|
||||||
os.startfile(os.path.realpath("./Updater/Updater.exe"))
|
|
||||||
|
|
||||||
if ((float(gitversion["version"]) < float(locversion["version"])) or # if local version is newer than
|
|
||||||
(float(gitversion["version"]) == float(locversion["version"])) and # github version
|
|
||||||
float(gitversion["subversion"]) < float(locversion["subversion"])):
|
|
||||||
self.is_dev_version = True
|
|
||||||
|
|
||||||
except requests.ConnectionError:
|
|
||||||
messagebox.showwarning(self.translate("Warning"),
|
|
||||||
self.translate("Can't connect to internet. Download will be disabled."))
|
|
||||||
self.option.disable_download = True
|
|
||||||
|
|
||||||
except:
|
|
||||||
self.log_error()
|
|
||||||
|
|
||||||
|
|
||||||
def log_error(func):
|
|
||||||
try:
|
|
||||||
func()
|
|
||||||
except Exception:
|
|
||||||
error = traceback.format_exc()
|
|
||||||
with open("./error.log", "a") as f:
|
|
||||||
f.write(f"---\n{error}\n")
|
|
||||||
messagebox.showerror(self.translate("Error"), self.translate("An error occured", " :", "\n", error, "\n\n"))
|
|
||||||
|
|
||||||
|
|
||||||
def translate(self, *texts, lang=None):
|
|
||||||
if lang is None:
|
|
||||||
lang = self.stringvar_language.get()
|
|
||||||
elif lang == "F":
|
|
||||||
lang = "fr"
|
|
||||||
elif lang == "G":
|
|
||||||
lang = "ge"
|
|
||||||
elif lang == "I":
|
|
||||||
lang = "it"
|
|
||||||
elif lang == "S":
|
|
||||||
lang = "sp"
|
|
||||||
|
|
||||||
if lang in translation_dict:
|
|
||||||
_lang_trad = translation_dict[lang]
|
|
||||||
translated_text = ""
|
|
||||||
for text in texts:
|
|
||||||
if text in _lang_trad:
|
|
||||||
translated_text += _lang_trad[text]
|
|
||||||
else:
|
|
||||||
translated_text += text
|
|
||||||
return translated_text
|
|
||||||
|
|
||||||
return "".join(texts) # if no translation language is found
|
|
||||||
|
|
||||||
|
|
||||||
def progress(self, show=None, indeter=None, step=None, statut=None, max=None, add=None):
|
|
||||||
if indeter is True:
|
|
||||||
self.progressbar.config(mode="indeterminate")
|
|
||||||
self.progressbar.start(50)
|
|
||||||
elif indeter is False:
|
|
||||||
self.progressbar.config(mode="determinate")
|
|
||||||
self.progressbar.stop()
|
|
||||||
if show is True:
|
|
||||||
self.state_button(enable=False)
|
|
||||||
self.progressbar.grid(row=100, column=1, sticky="NEWS")
|
|
||||||
self.progresslabel.grid(row=101, column=1, sticky="NEWS")
|
|
||||||
elif show is False:
|
|
||||||
self.state_button(enable=True)
|
|
||||||
self.progressbar.grid_forget()
|
|
||||||
self.progresslabel.grid_forget()
|
|
||||||
|
|
||||||
if statut: self.progresslabel.config(text=statut)
|
|
||||||
if step: self.progressbar["value"] = step
|
|
||||||
if max:
|
|
||||||
self.progressbar["maximum"] = max
|
|
||||||
self.progressbar["value"] = 0
|
|
||||||
if add: self.progressbar.step(add)
|
|
||||||
|
|
||||||
|
|
||||||
def state_button(self, enable=True):
|
|
||||||
button = [
|
|
||||||
self.button_game_extract,
|
|
||||||
self.button_install_mod,
|
|
||||||
self.button_prepare_file,
|
|
||||||
self.button_do_everything
|
|
||||||
]
|
|
||||||
for widget in button:
|
|
||||||
if enable:
|
|
||||||
widget.config(state=NORMAL)
|
|
||||||
else:
|
|
||||||
widget.config(state=DISABLED)
|
|
52
source/Gui/check_update.py
Normal file
52
source/Gui/check_update.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
from tkinter import messagebox
|
||||||
|
import requests
|
||||||
|
import zipfile
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from ..definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def check_update(self):
|
||||||
|
try:
|
||||||
|
gitversion = requests.get(VERSION_FILE_URL, allow_redirects=True).json()
|
||||||
|
with open("./version", "rb") as f:
|
||||||
|
locversion = json.load(f)
|
||||||
|
|
||||||
|
if ((float(gitversion["version"]) > float(locversion["version"])) or # if github version is newer than
|
||||||
|
(float(gitversion["version"]) == float(locversion["version"])) and # local version
|
||||||
|
float(gitversion["subversion"]) > float(locversion["subversion"])):
|
||||||
|
if messagebox.askyesno(
|
||||||
|
self.translate("Update available !"),
|
||||||
|
self.translate("An update is available, do you want to install it ?",
|
||||||
|
f"\n\nVersion : {locversion['version']}.{locversion['subversion']} -> "
|
||||||
|
f"{gitversion['version']}.{gitversion['subversion']}\n"
|
||||||
|
f"Changelog :\n{gitversion['changelog']}")):
|
||||||
|
|
||||||
|
if not (os.path.exists("./Updater/Updater.exe")):
|
||||||
|
dl = requests.get(gitversion["updater_bin"], allow_redirects=True)
|
||||||
|
with open("./download.zip", "wb") as file:
|
||||||
|
print(self.translate("Downloading the Updater..."))
|
||||||
|
file.write(dl.content)
|
||||||
|
print(self.translate("end of the download, extracting..."))
|
||||||
|
|
||||||
|
with zipfile.ZipFile("./download.zip") as file:
|
||||||
|
file.extractall("./Updater/")
|
||||||
|
print(self.translate("finished extracting"))
|
||||||
|
|
||||||
|
os.remove("./download.zip")
|
||||||
|
print(self.translate("starting application..."))
|
||||||
|
os.startfile(os.path.realpath("./Updater/Updater.exe"))
|
||||||
|
|
||||||
|
if ((float(gitversion["version"]) < float(locversion["version"])) or # if local version is newer than
|
||||||
|
(float(gitversion["version"]) == float(locversion["version"])) and # github version
|
||||||
|
float(gitversion["subversion"]) < float(locversion["subversion"])):
|
||||||
|
self.is_dev_version = True
|
||||||
|
|
||||||
|
except requests.ConnectionError:
|
||||||
|
messagebox.showwarning(self.translate("Warning"),
|
||||||
|
self.translate("Can't connect to internet. Download will be disabled."))
|
||||||
|
self.option.disable_download = True
|
||||||
|
|
||||||
|
except:
|
||||||
|
self.log_error()
|
9
source/Gui/log_error.py
Normal file
9
source/Gui/log_error.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from tkinter import messagebox
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
|
def log_error(self):
|
||||||
|
error = traceback.format_exc()
|
||||||
|
with open("./error.log", "a") as f:
|
||||||
|
f.write(f"---\n{error}\n")
|
||||||
|
messagebox.showerror(self.translate("Error"), self.translate("An error occured", " :", "\n", error, "\n\n"))
|
22
source/Gui/progress.py
Normal file
22
source/Gui/progress.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
def progress(self, show=None, indeter=None, step=None, statut=None, max=None, add=None):
|
||||||
|
if indeter is True:
|
||||||
|
self.progressbar.config(mode="indeterminate")
|
||||||
|
self.progressbar.start(50)
|
||||||
|
elif indeter is False:
|
||||||
|
self.progressbar.config(mode="determinate")
|
||||||
|
self.progressbar.stop()
|
||||||
|
if show is True:
|
||||||
|
self.state_button(enable=False)
|
||||||
|
self.progressbar.grid(row=100, column=1, sticky="NEWS")
|
||||||
|
self.progresslabel.grid(row=101, column=1, sticky="NEWS")
|
||||||
|
elif show is False:
|
||||||
|
self.state_button(enable=True)
|
||||||
|
self.progressbar.grid_forget()
|
||||||
|
self.progresslabel.grid_forget()
|
||||||
|
|
||||||
|
if statut: self.progresslabel.config(text=statut)
|
||||||
|
if step: self.progressbar["value"] = step
|
||||||
|
if max:
|
||||||
|
self.progressbar["maximum"] = max
|
||||||
|
self.progressbar["value"] = 0
|
||||||
|
if add: self.progressbar.step(add)
|
10
source/Gui/restart.py
Normal file
10
source/Gui/restart.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
from source.definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def restart():
|
||||||
|
subprocess.Popen([sys.executable] + sys.argv, creationflags=CREATE_NO_WINDOW, cwd=os.getcwd())
|
||||||
|
exit()
|
15
source/Gui/state_button.py
Normal file
15
source/Gui/state_button.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from tkinter import *
|
||||||
|
|
||||||
|
|
||||||
|
def state_button(self, enable=True):
|
||||||
|
button = [
|
||||||
|
self.button_game_extract,
|
||||||
|
self.button_install_mod,
|
||||||
|
self.button_prepare_file,
|
||||||
|
self.button_do_everything
|
||||||
|
]
|
||||||
|
for widget in button:
|
||||||
|
if enable:
|
||||||
|
widget.config(state=NORMAL)
|
||||||
|
else:
|
||||||
|
widget.config(state=DISABLED)
|
29
source/Gui/translate.py
Normal file
29
source/Gui/translate.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
with open("./translation.json", encoding="utf-8") as f:
|
||||||
|
translation_dict = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def translate(self, *texts, lang=None):
|
||||||
|
if lang is None:
|
||||||
|
lang = self.stringvar_language.get()
|
||||||
|
elif lang == "F":
|
||||||
|
lang = "fr"
|
||||||
|
elif lang == "G":
|
||||||
|
lang = "ge"
|
||||||
|
elif lang == "I":
|
||||||
|
lang = "it"
|
||||||
|
elif lang == "S":
|
||||||
|
lang = "sp"
|
||||||
|
|
||||||
|
if lang in translation_dict:
|
||||||
|
_lang_trad = translation_dict[lang]
|
||||||
|
translated_text = ""
|
||||||
|
for text in texts:
|
||||||
|
if text in _lang_trad:
|
||||||
|
translated_text += _lang_trad[text]
|
||||||
|
else:
|
||||||
|
translated_text += text
|
||||||
|
return translated_text
|
||||||
|
|
||||||
|
return "".join(texts) # if no translation language is found
|
|
@ -1,34 +0,0 @@
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class Option:
|
|
||||||
def __init__(self):
|
|
||||||
self.language = "en"
|
|
||||||
self.format = "FST"
|
|
||||||
self.disable_download = False
|
|
||||||
self.del_track_after_conv = False
|
|
||||||
self.dont_check_for_update = False
|
|
||||||
self.dont_check_track_sha1 = False
|
|
||||||
self.process_track = 8
|
|
||||||
|
|
||||||
def load_from_json(self, option_json: dict):
|
|
||||||
for key, value in option_json.items(): # load all value in the json as class attribute
|
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
def load_from_file(self, option_file: str = "./option.json"):
|
|
||||||
if os.path.exists(option_file):
|
|
||||||
with open(option_file, encoding="utf-8") as file:
|
|
||||||
file_json = json.load(file)
|
|
||||||
self.load_from_json(file_json)
|
|
||||||
|
|
||||||
def save_to_file(self, option_file: str = "./option.json"):
|
|
||||||
option_json: dict = self.__dict__ # this return all attribute of the class as a dict
|
|
||||||
with open(option_file, "w", encoding="utf-8") as file:
|
|
||||||
json.dump(option_json, file, ensure_ascii=False)
|
|
||||||
|
|
||||||
def edit(self, option, value, need_restart=False, gui=None):
|
|
||||||
if type(value) in [str, int, bool]: setattr(self, option, value)
|
|
||||||
else: setattr(self, option, value.get())
|
|
||||||
self.save_to_file()
|
|
||||||
if need_restart: gui.restart()
|
|
14
source/Option/__init__.py
Normal file
14
source/Option/__init__.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
class Option:
|
||||||
|
def __init__(self):
|
||||||
|
self.language = "en"
|
||||||
|
self.format = "FST"
|
||||||
|
self.disable_download = False
|
||||||
|
self.del_track_after_conv = False
|
||||||
|
self.dont_check_for_update = False
|
||||||
|
self.dont_check_track_sha1 = False
|
||||||
|
self.process_track = 8
|
||||||
|
|
||||||
|
from .edit import edit
|
||||||
|
from .load_from_file import load_from_file
|
||||||
|
from .load_from_json import load_from_json
|
||||||
|
from .save_to_file import save_to_file
|
7
source/Option/edit.py
Normal file
7
source/Option/edit.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
def edit(self, option, value, need_restart=False, gui=None):
|
||||||
|
if type(value) in [str, int, bool]:
|
||||||
|
setattr(self, option, value)
|
||||||
|
else:
|
||||||
|
setattr(self, option, value.get())
|
||||||
|
self.save_to_file()
|
||||||
|
if need_restart: gui.restart()
|
9
source/Option/load_from_file.py
Normal file
9
source/Option/load_from_file.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def load_from_file(self, option_file: str = "./option.json"):
|
||||||
|
if os.path.exists(option_file):
|
||||||
|
with open(option_file, encoding="utf-8") as file:
|
||||||
|
file_json = json.load(file)
|
||||||
|
self.load_from_json(file_json)
|
3
source/Option/load_from_json.py
Normal file
3
source/Option/load_from_json.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
def load_from_json(self, option_json: dict):
|
||||||
|
for key, value in option_json.items(): # load all value in the json as class attribute
|
||||||
|
setattr(self, key, value)
|
7
source/Option/save_to_file.py
Normal file
7
source/Option/save_to_file.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def save_to_file(self, option_file: str = "./option.json"):
|
||||||
|
option_json: dict = self.__dict__ # this return all attribute of the class as a dict
|
||||||
|
with open(option_file, "w", encoding="utf-8") as file:
|
||||||
|
json.dump(option_json, file, ensure_ascii=False)
|
120
source/Track.py
120
source/Track.py
|
@ -1,120 +0,0 @@
|
||||||
from .definition import *
|
|
||||||
import source.wszst
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class Track:
|
|
||||||
def __init__(self, name: str = "_", file_wu8: str = None, file_szs: str = None, prefix: str = None, suffix: str = None,
|
|
||||||
author="Nintendo", special="T11", music="T11", new=True, sha1: str = None, since_version: str = None,
|
|
||||||
score: int = 0, warning: int = 0, note: str = "", track_wu8_dir: str = "./file/Track-WU8/",
|
|
||||||
track_szs_dir: str = "./file/Track/", *args, **kwargs):
|
|
||||||
|
|
||||||
self.name = name # Track name
|
|
||||||
self.prefix = prefix # Prefix, often used for game or original console like Wii U, DS, ...
|
|
||||||
self.suffix = suffix # Suffix, often used for variety like Boost, Night, ...
|
|
||||||
self.author = author # Track author
|
|
||||||
self.sha1 = sha1 # Track sha1 from wszst SHA1
|
|
||||||
self.special = special # Special slot of the track
|
|
||||||
self.music = music # Music of the track
|
|
||||||
self.new = new # Is the track new
|
|
||||||
self.since_version = since_version # Since which version is this track available
|
|
||||||
self.score = score # Track score between 1 and 3 stars
|
|
||||||
self.warning = warning # Track bug level (1 = minor, 2 = major)
|
|
||||||
self.note = note # Note about the track
|
|
||||||
self.file_wu8 = f"{track_wu8_dir}/{self.get_track_name()}.wu8"
|
|
||||||
self.file_szs = f"{track_szs_dir}/{self.get_track_name()}.szs"
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"{self.get_track_name()} sha1={self.sha1} score={self.score}"
|
|
||||||
|
|
||||||
def get_track_name(self):
|
|
||||||
prefix = self.prefix + " " if self.prefix else ""
|
|
||||||
suffix = self.suffix + " " if self.suffix else ""
|
|
||||||
|
|
||||||
name = (prefix + self.name + suffix)
|
|
||||||
return name
|
|
||||||
|
|
||||||
def load_from_json(self, track_json: dict):
|
|
||||||
for key, value in track_json.items(): # load all value in the json as class attribute
|
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
def get_track_formatted_name(self, highlight_track_from_version: str = None):
|
|
||||||
"""
|
|
||||||
:param highlight_track_from_version: if a specific version need to be highlighted.
|
|
||||||
:return: the name of the track with colored prefix, suffix
|
|
||||||
"""
|
|
||||||
hl_prefix = ""
|
|
||||||
hl_suffix = ""
|
|
||||||
prefix = ""
|
|
||||||
suffix = ""
|
|
||||||
star_text = ""
|
|
||||||
|
|
||||||
if self.score:
|
|
||||||
if 0 < self.score <= 3:
|
|
||||||
star_text = "★" * self.score + "☆" * (3 - self.score)
|
|
||||||
star_text = trackname_color[star_text] + " "
|
|
||||||
|
|
||||||
if self.since_version == highlight_track_from_version:
|
|
||||||
hl_prefix, hl_suffix = "\\\\c{blue1}", "\\\\c{off}"
|
|
||||||
|
|
||||||
if self.prefix in trackname_color:
|
|
||||||
prefix = trackname_color[self.prefix] + " "
|
|
||||||
if self.suffix in trackname_color:
|
|
||||||
suffix = "(" + trackname_color[self.suffix] + ")"
|
|
||||||
|
|
||||||
name = (star_text + prefix + hl_prefix + self.name + hl_suffix + suffix)
|
|
||||||
name = name.replace("_", " ")
|
|
||||||
return name
|
|
||||||
|
|
||||||
def convert_wu8_to_szs(self):
|
|
||||||
return source.wszst.normalize(src_file=self.file_wu8, use_popen=True)
|
|
||||||
|
|
||||||
def download_wu8(self):
|
|
||||||
returncode = 0
|
|
||||||
|
|
||||||
dl = requests.get(get_github_content_root(self) + 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
|
|
||||||
else: returncode = 3
|
|
||||||
|
|
||||||
if dl.status_code == 200: # if page is found
|
|
||||||
with open(self.file_wu8, "wb") as file:
|
|
||||||
chunk_size = 4096
|
|
||||||
for i, chunk in enumerate(dl.iter_content(chunk_size=chunk_size)):
|
|
||||||
file.write(chunk)
|
|
||||||
file.flush()
|
|
||||||
return returncode
|
|
||||||
else:
|
|
||||||
print(f"error {dl.status_code} {self.file_wu8}")
|
|
||||||
return -1
|
|
||||||
|
|
||||||
def check_sha1(self):
|
|
||||||
if source.wszst.sha1(self.file_wu8) == self.sha1: return 0
|
|
||||||
else: return -1
|
|
||||||
|
|
||||||
def get_ctfile_track(self, race=False):
|
|
||||||
"""
|
|
||||||
:param race: is it a text used for Race_*.szs ?
|
|
||||||
:return: ctfile definition for the track
|
|
||||||
"""
|
|
||||||
ctfile_text = (
|
|
||||||
f' T {self.music}; '
|
|
||||||
f'{self.special}; '
|
|
||||||
f'{"0x01" if self.new else "0x00"}; '
|
|
||||||
)
|
|
||||||
if not race:
|
|
||||||
ctfile_text += (
|
|
||||||
f'"{self.get_track_name()}"; ' # track path
|
|
||||||
f'"{self.get_track_formatted_name()}"; ' # track text shown ig
|
|
||||||
f'"-"\n') # sha1, useless for now.
|
|
||||||
else:
|
|
||||||
ctfile_text += (
|
|
||||||
f'"-"; ' # track path, not used in Race_*.szs, save a bit of space
|
|
||||||
f'"{self.get_track_formatted_name()}\\n{self.author}"; ' # only in race show author's name
|
|
||||||
f'"-"\n' # sha1, useless for now.
|
|
||||||
)
|
|
||||||
|
|
||||||
return ctfile_text
|
|
||||||
|
|
||||||
# TODO: code download_wu8
|
|
29
source/Track/__init__.py
Normal file
29
source/Track/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class Track:
|
||||||
|
def __init__(self, name: str = "_", file_wu8: str = None, file_szs: str = None, prefix: str = None, suffix: str = None,
|
||||||
|
author="Nintendo", special="T11", music="T11", new=True, sha1: str = None, since_version: str = None,
|
||||||
|
score: int = 0, warning: int = 0, note: str = "", track_wu8_dir: str = "./file/Track-WU8/",
|
||||||
|
track_szs_dir: str = "./file/Track/", *args, **kwargs):
|
||||||
|
|
||||||
|
self.name = name # Track name
|
||||||
|
self.prefix = prefix # Prefix, often used for game or original console like Wii U, DS, ...
|
||||||
|
self.suffix = suffix # Suffix, often used for variety like Boost, Night, ...
|
||||||
|
self.author = author # Track author
|
||||||
|
self.sha1 = sha1 # Track sha1 from wszst SHA1
|
||||||
|
self.special = special # Special slot of the track
|
||||||
|
self.music = music # Music of the track
|
||||||
|
self.new = new # Is the track new
|
||||||
|
self.since_version = since_version # Since which version is this track available
|
||||||
|
self.score = score # Track score between 1 and 3 stars
|
||||||
|
self.warning = warning # Track bug level (1 = minor, 2 = major)
|
||||||
|
self.note = note # Note about the track
|
||||||
|
self.file_wu8 = f"{track_wu8_dir}/{self.get_track_name()}.wu8"
|
||||||
|
self.file_szs = f"{track_szs_dir}/{self.get_track_name()}.szs"
|
||||||
|
|
||||||
|
from .__repr__ import __repr__
|
||||||
|
from .check_sha1 import check_sha1
|
||||||
|
from .convert_wu8_to_szs import convert_wu8_to_szs
|
||||||
|
from .download_wu8 import download_wu8
|
||||||
|
from .get_ctfile import get_ctfile
|
||||||
|
from .get_track_formatted_name import get_track_formatted_name
|
||||||
|
from .get_track_name import get_track_name
|
||||||
|
from .load_from_json import load_from_json
|
2
source/Track/__repr__.py
Normal file
2
source/Track/__repr__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
def __repr__(self):
|
||||||
|
return f"{self.get_track_name()} sha1={self.sha1} score={self.score}"
|
8
source/Track/check_sha1.py
Normal file
8
source/Track/check_sha1.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import source.wszst
|
||||||
|
|
||||||
|
|
||||||
|
def check_sha1(self):
|
||||||
|
if source.wszst.sha1(self.file_wu8) == self.sha1:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return -1
|
5
source/Track/convert_wu8_to_szs.py
Normal file
5
source/Track/convert_wu8_to_szs.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import source.wszst
|
||||||
|
|
||||||
|
|
||||||
|
def convert_wu8_to_szs(self):
|
||||||
|
return source.wszst.normalize(src_file=self.file_wu8, use_popen=True)
|
26
source/Track/download_wu8.py
Normal file
26
source/Track/download_wu8.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
from ..definition import *
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def download_wu8(self):
|
||||||
|
returncode = 0
|
||||||
|
|
||||||
|
dl = requests.get(get_github_content_root(self) + 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
|
||||||
|
else:
|
||||||
|
returncode = 3
|
||||||
|
|
||||||
|
if dl.status_code == 200: # if page is found
|
||||||
|
with open(self.file_wu8, "wb") as file:
|
||||||
|
chunk_size = 4096
|
||||||
|
for i, chunk in enumerate(dl.iter_content(chunk_size=chunk_size)):
|
||||||
|
file.write(chunk)
|
||||||
|
file.flush()
|
||||||
|
return returncode
|
||||||
|
else:
|
||||||
|
print(f"error {dl.status_code} {self.file_wu8}")
|
||||||
|
return -1
|
23
source/Track/get_ctfile.py
Normal file
23
source/Track/get_ctfile.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
def get_ctfile(self, race=False):
|
||||||
|
"""
|
||||||
|
:param race: is it a text used for Race_*.szs ?
|
||||||
|
:return: ctfile definition for the track
|
||||||
|
"""
|
||||||
|
ctfile_text = (
|
||||||
|
f' T {self.music}; '
|
||||||
|
f'{self.special}; '
|
||||||
|
f'{"0x01" if self.new else "0x00"}; '
|
||||||
|
)
|
||||||
|
if not race:
|
||||||
|
ctfile_text += (
|
||||||
|
f'"{self.get_track_name()}"; ' # track path
|
||||||
|
f'"{self.get_track_formatted_name()}"; ' # track text shown ig
|
||||||
|
f'"-"\n') # sha1, useless for now.
|
||||||
|
else:
|
||||||
|
ctfile_text += (
|
||||||
|
f'"-"; ' # track path, not used in Race_*.szs, save a bit of space
|
||||||
|
f'"{self.get_track_formatted_name()}\\n{self.author}"; ' # only in race show author's name
|
||||||
|
f'"-"\n' # sha1, useless for now.
|
||||||
|
)
|
||||||
|
|
||||||
|
return ctfile_text
|
30
source/Track/get_track_formatted_name.py
Normal file
30
source/Track/get_track_formatted_name.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from ..definition import *
|
||||||
|
|
||||||
|
|
||||||
|
def get_track_formatted_name(self, highlight_track_from_version: str = None):
|
||||||
|
"""
|
||||||
|
:param highlight_track_from_version: if a specific version need to be highlighted.
|
||||||
|
:return: the name of the track with colored prefix, suffix
|
||||||
|
"""
|
||||||
|
hl_prefix = ""
|
||||||
|
hl_suffix = ""
|
||||||
|
prefix = ""
|
||||||
|
suffix = ""
|
||||||
|
star_text = ""
|
||||||
|
|
||||||
|
if self.score:
|
||||||
|
if 0 < self.score <= 3:
|
||||||
|
star_text = "★" * self.score + "☆" * (3 - self.score)
|
||||||
|
star_text = trackname_color[star_text] + " "
|
||||||
|
|
||||||
|
if self.since_version == highlight_track_from_version:
|
||||||
|
hl_prefix, hl_suffix = "\\\\c{blue1}", "\\\\c{off}"
|
||||||
|
|
||||||
|
if self.prefix in trackname_color:
|
||||||
|
prefix = trackname_color[self.prefix] + " "
|
||||||
|
if self.suffix in trackname_color:
|
||||||
|
suffix = "(" + trackname_color[self.suffix] + ")"
|
||||||
|
|
||||||
|
name = (star_text + prefix + hl_prefix + self.name + hl_suffix + suffix)
|
||||||
|
name = name.replace("_", " ")
|
||||||
|
return name
|
6
source/Track/get_track_name.py
Normal file
6
source/Track/get_track_name.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
def get_track_name(self):
|
||||||
|
prefix = self.prefix + " " if self.prefix else ""
|
||||||
|
suffix = self.suffix + " " if self.suffix else ""
|
||||||
|
|
||||||
|
name = (prefix + self.name + suffix)
|
||||||
|
return name
|
3
source/Track/load_from_json.py
Normal file
3
source/Track/load_from_json.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
def load_from_json(self, track_json: dict):
|
||||||
|
for key, value in track_json.items(): # load all value in the json as class attribute
|
||||||
|
setattr(self, key, value)
|
|
@ -87,6 +87,12 @@ trackname_color = {
|
||||||
"★☆☆!!": "\\\\c{YOR6}★☆☆\\\\c{off}",
|
"★☆☆!!": "\\\\c{YOR6}★☆☆\\\\c{off}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
region_id_to_name = {
|
||||||
|
"J": "JAP",
|
||||||
|
"P": "PAL",
|
||||||
|
"K": "KO",
|
||||||
|
"E": "USA"
|
||||||
|
}
|
||||||
|
|
||||||
def filecopy(src, dst):
|
def filecopy(src, dst):
|
||||||
with open(src, "rb") as f1:
|
with open(src, "rb") as f1:
|
||||||
|
|
Loading…
Reference in a new issue