Skip to content

Commit

Permalink
readded a better track selection filter (advanced menu), fixed an iss…
Browse files Browse the repository at this point in the history
…ue with tracks always renormalizing, added a default sort in ct_config, added a Common class to reunite all component with more readability and less weird code, splited the Gui into a directory
  • Loading branch information
Faraphel committed Jan 25, 2022
1 parent 85e36c4 commit b3d5af6
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 177 deletions.
1 change: 1 addition & 0 deletions Pack/MKWFaraphel/ct_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@
]
}
],
"default_sort": "name",
"tracks_list":[
{
"name":"4IT Clown's Road",
Expand Down
6 changes: 3 additions & 3 deletions main.pyw
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from source.Gui import Gui
from source.Common import Common

gui = Gui()
gui.root.mainloop()
common = Common()
common.mainloop()
26 changes: 19 additions & 7 deletions source/CT_Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

class CT_Config:
def __init__(self, version: str = None, name: str = None, nickname: str = None,
game_variant: str = "01", gui=None, 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,
tag_retro: str = "Retro", default_track: Track = None, pack_path: str = "",
file_process: dict = None, file_structure: dict = None):
file_process: dict = None, file_structure: dict = None, default_sort: str = "name"):

self.version = version
self.name = name
Expand All @@ -23,7 +23,6 @@ def __init__(self, version: str = None, name: str = None, nickname: str = None,

self.ordered_cups = []
self.unordered_tracks = []
self.gui = gui

self.tags_color = tags_color if tags_color else {}
self.prefix_list = prefix_list if tags_color else []
Expand All @@ -32,10 +31,15 @@ def __init__(self, version: str = None, name: str = None, nickname: str = None,
self.default_track = default_track

self.pack_path = pack_path
self.sort_track_attr = default_sort

self.file_process = file_process
self.file_structure = file_structure

self.filter_track_selection = lambda track: True
self.filter_track_highlight = lambda track: False
self.filter_track_random_new = lambda track: getattr(track, "new", False)

def add_ordered_cup(self, cup: Cup) -> None:
"""
add a cup to the config
Expand All @@ -53,9 +57,11 @@ def add_unordered_track(self, track: Track) -> None:
def unordered_tracks_to_cup(self):
track_in_cup: int = 4

for cup_id, track_id in enumerate(range(0, len(self.unordered_tracks), track_in_cup), start=1):
track_selection = list(filter(self.filter_track_selection, self.unordered_tracks))

for cup_id, track_id in enumerate(range(0, len(track_selection), track_in_cup), start=1):
cup = Cup(id=cup_id, name=f"CT{cup_id}")
for index, track in enumerate(self.unordered_tracks[track_id:track_id + track_in_cup]):
for index, track in enumerate(track_selection[track_id:track_id + track_in_cup]):
cup.tracks[index] = track
yield cup

Expand All @@ -77,8 +83,13 @@ def create_ctfile(self, directory: str = "./file/", highlight_version: str = Non
ctfile.write(header); rctfile.write(header)

# all cups
kwargs = {
"filter_highlight": self.filter_track_highlight,
"filter_random_new": self.filter_track_random_new,
"ct_config": self
}

for cup in self.get_all_cups():
kwargs = {"highlight_version": highlight_version, "ct_config": self}
ctfile.write(cup.get_ctfile(race=False, **kwargs))
rctfile.write(cup.get_ctfile(race=True, **kwargs))

Expand Down Expand Up @@ -183,8 +194,9 @@ def load_ctconfig_json(self, ctconfig_json: dict, pack_path: str):
self.version = ctconfig_json.get("version")

if "name" in ctconfig_json: self.name = ctconfig_json["name"]
self.nickname = ctconfig_json["nickname"] if "nickname" in ctconfig_json else self.name
if "game_variant" in ctconfig_json: self.game_variant = ctconfig_json["game_variant"]
if "default_sort" in ctconfig_json: self.default_sort = 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))
Expand Down
21 changes: 21 additions & 0 deletions source/Common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from source.CT_Config import CT_Config
from source.Option import Option
from source.Game import Game
from source.Gui.Main import Main
from source.Gui.TrackSelection import TrackSelection

class Common:
def __init__(self):
"""
Common allow to store multiple object that need each other and still make the code readable enough without
having to access an object with some obscure way
"""

self.option = Option().load_from_file("./option.json")
self.ct_config = CT_Config()
self.game = Game(common=self)

self.gui_main = Main(common=self)

def show_gui_track_configuration(self): TrackSelection(common=self)
def mainloop(self): self.gui_main.mainloop()
Loading

0 comments on commit b3d5af6

Please sign in to comment.