fix all errors

This commit is contained in:
Anthony Samms
2026-01-14 13:27:47 -05:00
parent 0e8e616576
commit 70fcda4670
3 changed files with 39 additions and 63 deletions

View File

@@ -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

View File

@@ -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