From 70fcda4670d47fb0d88a6b099f731c9a7d05229e Mon Sep 17 00:00:00 2001 From: Anthony Samms Date: Wed, 14 Jan 2026 13:27:47 -0500 Subject: [PATCH] fix all errors --- libs/file_navigator.py | 49 +++--------------------------------------- libs/parsers/osz.py | 49 +++++++++++++++++++++++++++++------------- scenes/song_select.py | 4 ++-- 3 files changed, 39 insertions(+), 63 deletions(-) diff --git a/libs/file_navigator.py b/libs/file_navigator.py index a2c3c38..b79340c 100644 --- a/libs/file_navigator.py +++ b/libs/file_navigator.py @@ -209,7 +209,7 @@ class BackBox(BaseBox): self.yellow_box.draw(self, fade_override, is_ura, self.name) class SongBox(BaseBox): - def __init__(self, name: str, back_color: Optional[tuple[int, int, int]], fore_color: Optional[tuple[int, int, int]], texture_index: TextureIndex, tja: TJAParser): + def __init__(self, name: str, back_color: Optional[tuple[int, int, int]], fore_color: Optional[tuple[int, int, int]], texture_index: TextureIndex, tja: TJAParser | OsuParser): super().__init__(name, back_color, fore_color, texture_index) self.scores = dict() self.hash = dict() @@ -298,45 +298,7 @@ class SongBox(BaseBox): if self.score_history is not None and get_current_ms() >= self.history_wait + 3000: self.score_history.draw() -class SongBoxOsu(BaseBox): - def __init__(self, name: str, back_color: Optional[tuple[int, int, int]], fore_color: Optional[tuple[int, int, int]], texture_index: TextureIndex, parser: OsuParser): - super().__init__(name, back_color, fore_color, texture_index) - self.scores = dict() - self.hash = dict() - self.score_history = None - self.history_wait = 0 - self.parser = parser - self.is_favorite = False - self.yellow_box = None - - def load_text(self): - super().load_text() - self.text_loaded = True - - def get_scores(self): - with sqlite3.connect(global_data.score_db) as con: - cursor = con.cursor() - # Batch database query for all diffs at once - if self.parser.metadata.course_data: - hash_values = [self.hash[diff] for diff in self.parser.metadata.course_data if diff in self.hash] - placeholders = ','.join('?' * len(hash_values)) - - batch_query = f""" - SELECT hash, score, good, ok, bad, drumroll, clear - FROM Scores - WHERE hash IN ({placeholders}) - """ - cursor.execute(batch_query, hash_values) - - hash_to_score = {row[0]: row[1:] for row in cursor.fetchall()} - - for diff in self.parser.metadata.course_data: - if diff not in self.hash: - continue - diff_hash = self.hash[diff] - self.scores[diff] = hash_to_score.get(diff_hash) - self.score_history = None - +class SongBoxOsu(SongBox): def update(self, current_time: float, is_diff_select: bool): super().update(current_time, is_diff_select) is_open_prev = self.is_open @@ -376,11 +338,6 @@ class SongBoxOsu(BaseBox): elif score and score[5] >= Crown.CLEAR: tex.draw_texture('yellow_box', 'crown_clear', x=x, y=y, frame=min(Difficulty.URA, highest_key), fade=outer_fade_override) - def draw_score_history(self): - if self.is_open and get_current_ms() >= self.wait + 83.33: - if self.score_history is not None and get_current_ms() >= self.history_wait + 3000: - self.score_history.draw() - class FolderBox(BaseBox): def __init__(self, name: str, back_color: Optional[tuple[int, int, int]], fore_color: Optional[tuple[int, int, int]], texture_index: TextureIndex, genre_index: GenreIndex, tja_count: int = 0, box_texture: Optional[str] = None): super().__init__(name, back_color, fore_color, texture_index) @@ -493,7 +450,7 @@ class FolderBox(BaseBox): class YellowBox: """A song box when it is opened.""" - def __init__(self, is_back: bool, tja: Optional[TJAParser] = None, is_dan: bool = False): + def __init__(self, is_back: bool, tja: Optional[TJAParser | OsuParser] = None, is_dan: bool = False): self.is_diff_select = False self.is_back = is_back self.tja = tja diff --git a/libs/parsers/osz.py b/libs/parsers/osz.py index c330b4b..c8b8be2 100644 --- a/libs/parsers/osz.py +++ b/libs/parsers/osz.py @@ -2,7 +2,7 @@ import hashlib import math from pathlib import Path -from libs.parsers.tja import CourseData, Note, NoteType, Drumroll, Balloon, NoteList, TJAMetadata +from libs.parsers.tja import CourseData, Note, NoteType, Drumroll, Balloon, NoteList, TJAEXData, TJAMetadata import re @@ -11,33 +11,32 @@ class OsuParser: editor: dict[str, str] osu_metadata: dict[str, str] difficulty: dict[str, str] - events: list[int] - timing_points: list[int] - hit_objects: list[int] + events: list[list[float]] + timing_points: list[list[float]] + hit_objects: list[list[float]] - bpm: list[int] + bpm: list[float] def __init__(self, osu_file: Path): - self.general = self.read_osu_data(osu_file, target_header="General", is_dict=True) - self.editor = self.read_osu_data(osu_file, target_header="Editor", is_dict=True) - self.osu_metadata = self.read_osu_data(osu_file, target_header="Metadata", is_dict=True) - self.difficulty = self.read_osu_data(osu_file, target_header="Difficulty", is_dict=True) - self.events = self.read_osu_data(osu_file, target_header="Events") - self.timing_points = self.read_osu_data(osu_file, target_header="TimingPoints") + self.general = self.read_osu_data_dict(osu_file, target_header="General") + self.editor = self.read_osu_data_dict(osu_file, target_header="Editor") + self.osu_metadata = self.read_osu_data_dict(osu_file, target_header="Metadata") + self.difficulty = self.read_osu_data_dict(osu_file, target_header="Difficulty") + self.events = self.read_osu_data_list(osu_file, target_header="Events") + self.timing_points = self.read_osu_data_list(osu_file, target_header="TimingPoints") #self.general = self.read_osu_data(osu_file, target_header="Colours", is_dict=True) - self.hit_objects = self.read_osu_data(osu_file, target_header="HitObjects") + self.hit_objects = self.read_osu_data_list(osu_file, target_header="HitObjects") self.bpm = [] self.metadata = TJAMetadata() self.metadata.wave = osu_file.parent / self.general["AudioFilename"] self.metadata.course_data[0] = CourseData() + self.ex_data = TJAEXData() for points in self.timing_points: self.bpm.append(math.floor(1 / points[1] * 1000 * 60)) self.osu_NoteList = self.note_data_to_NoteList(self.hit_objects) - def read_osu_data(self, file_path: Path, target_header="HitObjects", is_dict = False): + def read_osu_data_list(self, file_path: Path, target_header="HitObjects") -> list[list[float]]: data = [] - if is_dict: - data = {} current_header = None with file_path.open(mode='r', encoding='utf-8') as f: @@ -55,6 +54,24 @@ class OsuParser: int_array = [float(num_str) for num_str in string_array] data.append(int_array) + else: + continue + + return data + + def read_osu_data_dict(self, file_path: Path, target_header="HitObjects") -> dict[str, str]: + data = dict() + current_header = None + + with file_path.open(mode='r', encoding='utf-8') as f: + + for line in f: + line = line.rstrip("\n") + + if re.match(r"\[\w*\]", line): # header pattern + current_header = line[1:-1] + + if current_header == target_header: if re.match(r'(\w*)\:\s?(\w*.?\w*)', line): # General, Editor, Metadata, Difficulty match = re.search(r'(\w*)\:\s?(\w*.?\w*)', line) if match: @@ -216,11 +233,13 @@ class OsuParser: counter = counter + 1 balloon.moji = 0 + ''' od = int(self.difficulty["OverallDifficulty"]) # thank you https://github.com/IepIweidieng/osu2tja/blob/dev-iid/osu2tja/osu2tja.py hit_multiplyer = (5 - 2 * (5 - od) / 5 if od < 5 else 5 + 2.5 * (od - 5) / 5 if od > 5 else 5) * 1.65 + ''' balloon.count = 20#int(max(1, (ret[-1][1] - ret[-2][1]) / 1000 * hit_multiplier)) # end of 'stolen' code source.index = counter diff --git a/scenes/song_select.py b/scenes/song_select.py index b0c709c..006c1cf 100644 --- a/scenes/song_select.py +++ b/scenes/song_select.py @@ -102,7 +102,7 @@ class SongSelectScreen(Screen): self.navigator.mark_crowns_dirty_for_song(selected_song) curr_item = self.navigator.get_current_item() - if isinstance(curr_item, SongFile) or isinstance(curr_item, SongFileOsu): + if not isinstance(curr_item, Directory): curr_item.box.get_scores() self.navigator.add_recent() @@ -446,7 +446,7 @@ class SongSelectScreen(Screen): if self.state == State.BROWSING and self.navigator.items != []: curr_item = self.navigator.get_current_item() - if isinstance(curr_item, SongFile) or isinstance(curr_item, SongFileOsu): + if not isinstance(curr_item, Directory): curr_item.box.draw_score_history() self.draw_overlay()