mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 19:28:25 +02:00
added a weight notion to track (a track with a weight of 4 will be duplicated 4 times)
This commit is contained in:
parent
7200e21927
commit
a55ed656d9
4 changed files with 70 additions and 68 deletions
|
@ -11,8 +11,10 @@ class CT_Config:
|
||||||
def __init__(self, version: str = None, name: str = None, nickname: str = None,
|
def __init__(self, version: str = None, name: str = None, nickname: str = None,
|
||||||
game_variant: str = "01", region: int = None, cheat_region: int = None,
|
game_variant: str = "01", region: int = None, cheat_region: int = None,
|
||||||
tags_color: dict = None, prefix_list: list = None, suffix_list: list = None,
|
tags_color: dict = None, prefix_list: list = None, suffix_list: list = None,
|
||||||
tag_retro: str = "Retro", default_track: Track = None, pack_path: str = "",
|
tag_retro: str = "Retro", default_track: dict = None, pack_path: str = "",
|
||||||
file_process: dict = None, file_structure: dict = None, default_sort: str = ""):
|
file_process: dict = None, file_structure: dict = None, default_sort: str = "",
|
||||||
|
cup: list = None, tracks_list: list = None,
|
||||||
|
*args, **kwargs):
|
||||||
|
|
||||||
self.version = version
|
self.version = version
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -24,10 +26,6 @@ class CT_Config:
|
||||||
self.ordered_cups = []
|
self.ordered_cups = []
|
||||||
self.unordered_tracks = []
|
self.unordered_tracks = []
|
||||||
|
|
||||||
self.tags_color = tags_color if tags_color else {}
|
|
||||||
self.prefix_list = prefix_list if tags_color else []
|
|
||||||
self.suffix_list = suffix_list if tags_color else []
|
|
||||||
self.tag_retro = tag_retro
|
|
||||||
self.default_track = default_track
|
self.default_track = default_track
|
||||||
|
|
||||||
self.pack_path = pack_path
|
self.pack_path = pack_path
|
||||||
|
@ -40,6 +38,41 @@ class CT_Config:
|
||||||
self.filter_track_highlight = lambda track: False
|
self.filter_track_highlight = lambda track: False
|
||||||
self.filter_track_random_new = lambda track: getattr(track, "new", False)
|
self.filter_track_random_new = lambda track: getattr(track, "new", False)
|
||||||
|
|
||||||
|
self.sort_track_attr = default_sort
|
||||||
|
|
||||||
|
self.default_track = Track().load_from_json(default_track if default_track else {})
|
||||||
|
Cup.default_track = self.default_track
|
||||||
|
|
||||||
|
for id, cup_json in enumerate(cup if cup else []):
|
||||||
|
# tracks with defined order
|
||||||
|
cup = Cup(id=id)
|
||||||
|
cup.load_from_json(cup_json)
|
||||||
|
self.ordered_cups.append(cup)
|
||||||
|
|
||||||
|
for track_json in tracks_list if tracks_list else []:
|
||||||
|
# unordered tracks
|
||||||
|
track = get_trackdata_from_json(track_json)
|
||||||
|
self.unordered_tracks.extend([track] * track.weight)
|
||||||
|
|
||||||
|
if pack_path:
|
||||||
|
with open(f"{pack_path}/file_process.json", encoding="utf8") as fp_file:
|
||||||
|
self.file_process = json.load(fp_file)
|
||||||
|
with open(f"{pack_path}/file_structure.json", encoding="utf8") as fs_file:
|
||||||
|
self.file_structure = json.load(fs_file)
|
||||||
|
|
||||||
|
dir = self.file_process['placement'].get('cup_icon_dir') if 'placement' in self.file_process else None
|
||||||
|
if not dir: dir = "/ct_icons/"
|
||||||
|
Cup.icon_dir = f"{self.pack_path}/file/{dir}/"
|
||||||
|
|
||||||
|
wu8_dirname = self.file_process["track_dir"] if "track_dir" in self.file_process else "/Track-WU8/"
|
||||||
|
Track._wu8_dir = f"{self.pack_path}/file/{wu8_dirname}/"
|
||||||
|
|
||||||
|
Track._szs_dir = "./file/Track/"
|
||||||
|
Track.tag_retro = tag_retro if tag_retro else {}
|
||||||
|
Track.prefix_list = prefix_list if prefix_list else []
|
||||||
|
Track.suffix_list = suffix_list if suffix_list else []
|
||||||
|
Track.tags_color = tags_color if tags_color else {}
|
||||||
|
|
||||||
def add_ordered_cup(self, cup: Cup) -> None:
|
def add_ordered_cup(self, cup: Cup) -> None:
|
||||||
"""
|
"""
|
||||||
add a cup to the config
|
add a cup to the config
|
||||||
|
@ -160,54 +193,7 @@ class CT_Config:
|
||||||
:param pack_path: path to the pack (parent dir of the ct_config.json)
|
:param pack_path: path to the pack (parent dir of the ct_config.json)
|
||||||
:param ctconfig_json: json of the ctconfig to load
|
:param ctconfig_json: json of the ctconfig to load
|
||||||
"""
|
"""
|
||||||
self.ordered_cups = []
|
self.__init__(pack_path=pack_path, **ctconfig_json)
|
||||||
self.unordered_tracks = []
|
|
||||||
self.all_tracks = []
|
|
||||||
|
|
||||||
self.pack_path = pack_path
|
|
||||||
|
|
||||||
with open(f"{pack_path}/file_process.json", encoding="utf8") as fp_file:
|
|
||||||
self.file_process = json.load(fp_file)
|
|
||||||
with open(f"{pack_path}/file_structure.json", encoding="utf8") as fs_file:
|
|
||||||
self.file_structure = json.load(fs_file)
|
|
||||||
|
|
||||||
dir = self.file_process['placement'].get('cup_icon_dir') if 'placement' in self.file_process else None
|
|
||||||
if not dir: dir = "/ct_icons/"
|
|
||||||
Cup.icon_dir = f"{self.pack_path}/file/{dir}/"
|
|
||||||
|
|
||||||
# default track
|
|
||||||
self.default_track = Track()
|
|
||||||
if "default_track" in ctconfig_json: self.default_track.load_from_json(ctconfig_json["default_track"])
|
|
||||||
Cup.default_track = self.default_track
|
|
||||||
|
|
||||||
for id, cup_json in enumerate(ctconfig_json["cup"] if "cup" in ctconfig_json else []):
|
|
||||||
# tracks with defined order
|
|
||||||
cup = Cup(id=id)
|
|
||||||
cup.load_from_json(cup_json)
|
|
||||||
self.ordered_cups.append(cup)
|
|
||||||
|
|
||||||
for track_json in ctconfig_json["tracks_list"] if "tracks_list" in ctconfig_json else []:
|
|
||||||
# unordered tracks
|
|
||||||
track = get_trackdata_from_json(track_json)
|
|
||||||
self.unordered_tracks.append(track)
|
|
||||||
|
|
||||||
self.version = ctconfig_json.get("version")
|
|
||||||
|
|
||||||
if "name" in ctconfig_json: self.name = ctconfig_json["name"]
|
|
||||||
if "game_variant" in ctconfig_json: self.game_variant = ctconfig_json["game_variant"]
|
|
||||||
if "default_sort" in ctconfig_json: self.sort_track_attr = ctconfig_json["default_sort"]
|
|
||||||
self.nickname = ctconfig_json["nickname"] if "nickname" in ctconfig_json else self.name
|
|
||||||
|
|
||||||
for param in ["region", "cheat_region", "tags_color", "prefix_list", "suffix_list", "tag_retro"]:
|
|
||||||
setattr(self, param, ctconfig_json.get(param))
|
|
||||||
|
|
||||||
wu8_dirname = self.file_process["track_dir"] if "track_dir" in self.file_process else "/Track-WU8/"
|
|
||||||
Track._wu8_dir = f"{self.pack_path}/file/{wu8_dirname}/"
|
|
||||||
Track._szs_dir = "./file/Track/"
|
|
||||||
Track.tag_retro = self.tag_retro
|
|
||||||
Track.prefix_list = self.prefix_list
|
|
||||||
Track.suffix_list = self.suffix_list
|
|
||||||
Track.tags_color = self.tags_color
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import json
|
||||||
from source.definition import *
|
from source.definition import *
|
||||||
from source.wszst import *
|
from source.wszst import *
|
||||||
from source.Error import *
|
from source.Error import *
|
||||||
|
from source.Track import Track
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
|
@ -301,15 +302,15 @@ class Game:
|
||||||
track_id = bmgtrack[start_track_id:start_track_id + 3]
|
track_id = bmgtrack[start_track_id:start_track_id + 3]
|
||||||
if track_id[1] in "1234": # if the track is a original track from the wii
|
if track_id[1] in "1234": # if the track is a original track from the wii
|
||||||
prefix = "Wii"
|
prefix = "Wii"
|
||||||
if prefix in self.common.ct_config.tags_color:
|
if prefix in Track.tags_color:
|
||||||
prefix = "\\\\c{" + self.common.ct_config.tags_color[prefix] + "}" + prefix + "\\\\c{off}"
|
prefix = "\\\\c{" + Track.tags_color[prefix] + "}" + prefix + "\\\\c{off}"
|
||||||
prefix += " "
|
prefix += " "
|
||||||
|
|
||||||
elif track_id[1] in "5678": # if the track is a retro track from the original game
|
elif track_id[1] in "5678": # if the track is a retro track from the original game
|
||||||
prefix, *track_name = track_name.split(" ")
|
prefix, *track_name = track_name.split(" ")
|
||||||
track_name = " ".join(track_name)
|
track_name = " ".join(track_name)
|
||||||
if prefix in self.common.ct_config.tags_color:
|
if prefix in Track.tags_color:
|
||||||
prefix = "\\\\c{" + self.common.ct_config.tags_color[prefix] + "}" + prefix + "\\\\c{off}"
|
prefix = "\\\\c{" + Track.tags_color[prefix] + "}" + prefix + "\\\\c{off}"
|
||||||
prefix += " "
|
prefix += " "
|
||||||
|
|
||||||
track_id = hex(bmgID_track_move[track_id])[2:]
|
track_id = hex(bmgID_track_move[track_id])[2:]
|
||||||
|
@ -425,7 +426,7 @@ class Game:
|
||||||
|
|
||||||
max_step = (
|
max_step = (
|
||||||
len(self.common.ct_config.file_process["img_encode"]) +
|
len(self.common.ct_config.file_process["img_encode"]) +
|
||||||
len(self.common.ct_config.all_tracks) +
|
self.common.ct_config.get_tracks_count() +
|
||||||
3 +
|
3 +
|
||||||
len("EGFIS")
|
len("EGFIS")
|
||||||
)
|
)
|
||||||
|
@ -454,7 +455,8 @@ class Game:
|
||||||
self.common.gui_main.progress(show=False)
|
self.common.gui_main.progress(show=False)
|
||||||
|
|
||||||
def generate_cticons(self):
|
def generate_cticons(self):
|
||||||
file = self.common.ct_config.file_process["placement"].get("ct_icons")
|
file = self.common.ct_config.file_process["placement"].get("ct_icons") \
|
||||||
|
if "placement" in self.common.ct_config.file_process else None
|
||||||
if not file: file = "ct_icons.tpl.png"
|
if not file: file = "ct_icons.tpl.png"
|
||||||
file = f"{self.common.ct_config.pack_path}/file/{file}"
|
file = f"{self.common.ct_config.pack_path}/file/{file}"
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Track:
|
||||||
|
|
||||||
def __init__(self, name: str = " ", author: str = "Nintendo", special: str = "T11", music: str = "T11",
|
def __init__(self, name: str = " ", author: str = "Nintendo", special: str = "T11", music: str = "T11",
|
||||||
sha1: str = None, since_version: str = None, score: int = -1, warning: int = 0,
|
sha1: str = None, since_version: str = None, score: int = -1, warning: int = 0,
|
||||||
version: str = None, tags: list = None, is_in_group: bool = False, *args, **kwargs):
|
version: str = None, tags: list = None, is_in_group: bool = False, weight: int = 1, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Track class
|
Track class
|
||||||
:param name: track name
|
:param name: track name
|
||||||
|
@ -60,6 +60,7 @@ class Track:
|
||||||
self.warning = warning # Track bug level (1 = minor, 2 = major)
|
self.warning = warning # Track bug level (1 = minor, 2 = major)
|
||||||
self.version = version
|
self.version = version
|
||||||
self.tags = tags if tags else []
|
self.tags = tags if tags else []
|
||||||
|
self.weight = weight
|
||||||
|
|
||||||
self._is_in_group = is_in_group
|
self._is_in_group = is_in_group
|
||||||
|
|
||||||
|
@ -196,8 +197,7 @@ class Track:
|
||||||
load the track from a dictionary
|
load the track from a dictionary
|
||||||
:param track_json: track's dictionary
|
:param track_json: track's dictionary
|
||||||
"""
|
"""
|
||||||
for key, value in track_json.items(): # load all value in the json as class attribute
|
self.__init__(**track_json)
|
||||||
setattr(self, key, value)
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -222,7 +222,10 @@ class TrackGroup(Track):
|
||||||
for key, value in group_json.items(): # load all value in the json as class attribute
|
for key, value in group_json.items(): # load all value in the json as class attribute
|
||||||
if key == "group":
|
if key == "group":
|
||||||
for track_json in value:
|
for track_json in value:
|
||||||
self.tracks.append(Track(is_in_group=True, *args, **kwargs).load_from_json(track_json))
|
track = Track(is_in_group=True, *args, **kwargs).load_from_json(track_json)
|
||||||
|
self.tracks.extend(
|
||||||
|
[track] * track.weight
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
|
@ -8,8 +8,8 @@ WLECT_PATH = "./tools/szs/wlect"
|
||||||
def patch(lecode_file: str = f"./file/lecode-PAL.bin",
|
def patch(lecode_file: str = f"./file/lecode-PAL.bin",
|
||||||
dest_lecode_file: str = f"./files/rel/lecode-PAL.bin",
|
dest_lecode_file: str = f"./files/rel/lecode-PAL.bin",
|
||||||
game_track_path: str = "./files/Race/Course/",
|
game_track_path: str = "./files/Race/Course/",
|
||||||
copy_track_paths: list = [],
|
copy_track_paths: list = None,
|
||||||
move_track_paths: list = [],
|
move_track_paths: list = None,
|
||||||
ctfile_path: str = "./file/CTFILE.txt",
|
ctfile_path: str = "./file/CTFILE.txt",
|
||||||
lpar_path: str = "./file/lpar-normal.txt") -> None:
|
lpar_path: str = "./file/lpar-normal.txt") -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -17,10 +17,14 @@ def patch(lecode_file: str = f"./file/lecode-PAL.bin",
|
||||||
:param lecode_file: path to the lecode file
|
:param lecode_file: path to the lecode file
|
||||||
:param dest_lecode_file: destination of the lecode file
|
:param dest_lecode_file: destination of the lecode file
|
||||||
:param game_track_path: subpath to the track directory
|
:param game_track_path: subpath to the track directory
|
||||||
:param copy_track_paths: where are stored the track to move
|
:param copy_track_paths: where are stored the track to copy
|
||||||
|
:param move_track_paths: where are stored the track to move
|
||||||
:param ctfile_path: where is the ctfile (track and cup definition)
|
:param ctfile_path: where is the ctfile (track and cup definition)
|
||||||
:param lpar_path: where is the lpar_path (game modification like speed, speedometer, ...)
|
:param lpar_path: where is the lpar_path (game modification like speed, speedometer, ...)
|
||||||
"""
|
"""
|
||||||
|
if not copy_track_paths: copy_track_paths = []
|
||||||
|
if not move_track_paths: move_track_paths = []
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
WLECT_PATH, "patch", lecode_file, "-od", dest_lecode_file, "--track-dir", game_track_path,
|
WLECT_PATH, "patch", lecode_file, "-od", dest_lecode_file, "--track-dir", game_track_path,
|
||||||
"--le-define", ctfile_path, "--lpar", lpar_path, "--overwrite"
|
"--le-define", ctfile_path, "--lpar", lpar_path, "--overwrite"
|
||||||
|
@ -29,5 +33,12 @@ def patch(lecode_file: str = f"./file/lecode-PAL.bin",
|
||||||
cmd.extend(["--copy-tracks", path])
|
cmd.extend(["--copy-tracks", path])
|
||||||
for path in move_track_paths:
|
for path in move_track_paths:
|
||||||
cmd.extend(["--move-tracks", path])
|
cmd.extend(["--move-tracks", path])
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
subprocess.run(cmd, creationflags=subprocess.CREATE_NO_WINDOW, check=True, stdout=subprocess.PIPE)
|
subprocess.run(
|
||||||
|
cmd,
|
||||||
|
creationflags=subprocess.CREATE_NO_WINDOW,
|
||||||
|
check=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
timeout=900
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue