Update tja.py

This commit is contained in:
Anthony Samms
2025-11-03 10:45:24 -05:00
parent f93accd4a1
commit b5625f7565

View File

@@ -360,7 +360,7 @@ class TJAParser:
data = item.split(':')[1] data = item.split(':')[1]
if not data: if not data:
logger.warning(f"Invalid WAVE value: {data} in TJA file {self.file_path}") logger.warning(f"Invalid WAVE value: {data} in TJA file {self.file_path}")
self.metadata.wave = '' self.metadata.wave = Path()
else: else:
self.metadata.wave = self.file_path.parent / data.strip() self.metadata.wave = self.file_path.parent / data.strip()
elif item.startswith('OFFSET'): elif item.startswith('OFFSET'):
@@ -381,7 +381,7 @@ class TJAParser:
data = item.split(':')[1] data = item.split(':')[1]
if not data: if not data:
logger.warning(f"Invalid BGMOVIE value: {data} in TJA file {self.file_path}") logger.warning(f"Invalid BGMOVIE value: {data} in TJA file {self.file_path}")
self.metadata.bgmovie = None self.metadata.bgmovie = Path()
else: else:
self.metadata.bgmovie = self.file_path.parent / data.strip() self.metadata.bgmovie = self.file_path.parent / data.strip()
elif item.startswith('MOVIEOFFSET'): elif item.startswith('MOVIEOFFSET'):
@@ -412,7 +412,8 @@ class TJAParser:
current_diff = 0 current_diff = 0
else: else:
logger.error(f"Course level empty in {self.file_path}") logger.error(f"Course level empty in {self.file_path}")
self.metadata.course_data[current_diff] = CourseData() if current_diff is not None:
self.metadata.course_data[current_diff] = CourseData()
elif current_diff is not None: elif current_diff is not None:
if item.startswith('LEVEL'): if item.startswith('LEVEL'):
data = item.split(':')[1] data = item.split(':')[1]
@@ -445,13 +446,11 @@ class TJAParser:
continue continue
balloon_data = item.split(':')[1] balloon_data = item.split(':')[1]
if balloon_data == '': if balloon_data == '':
logger.debug(f"Invalid BALLOON value: {balloon_data} in TJA file {self.file_path}")
continue continue
self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.split(',') if x != ''] self.metadata.course_data[current_diff].balloon = [int(x) for x in balloon_data.split(',') if x != '']
elif item.startswith('SCOREINIT'): elif item.startswith('SCOREINIT'):
score_init = item.split(':')[1] score_init = item.split(':')[1]
if score_init == '': if score_init == '':
logger.debug(f"Invalid SCOREINIT value: {score_init} in TJA file {self.file_path}")
continue continue
try: try:
self.metadata.course_data[current_diff].scoreinit = [int(x) for x in score_init.split(',') if x != ''] self.metadata.course_data[current_diff].scoreinit = [int(x) for x in score_init.split(',') if x != '']
@@ -461,7 +460,6 @@ class TJAParser:
elif item.startswith('SCOREDIFF'): elif item.startswith('SCOREDIFF'):
score_diff = item.split(':')[1] score_diff = item.split(':')[1]
if score_diff == '': if score_diff == '':
logger.debug(f"Invalid SCOREDIFF value: {score_diff} in TJA file {self.file_path}")
continue continue
self.metadata.course_data[current_diff].scorediff = int(float(score_diff)) self.metadata.course_data[current_diff].scorediff = int(float(score_diff))
for region_code in self.metadata.title: for region_code in self.metadata.title:
@@ -628,6 +626,7 @@ class TJAParser:
start_branch_gogo = gogo_time start_branch_gogo = gogo_time
branch_balloon_count = 0 branch_balloon_count = 0
is_branching = False is_branching = False
prev_note = None
for bar in notes: for bar in notes:
#Length of the bar is determined by number of notes excluding commands #Length of the bar is determined by number of notes excluding commands
bar_length = sum(len(part) for part in bar if '#' not in part) bar_length = sum(len(part) for part in bar if '#' not in part)
@@ -849,17 +848,8 @@ class TJAParser:
note = Balloon(note) note = Balloon(note)
note.count = 1 if not balloon else balloon.pop(0) note.count = 1 if not balloon else balloon.pop(0)
elif item == '8': elif item == '8':
if not curr_note_list or curr_note_list[-1].type not in {5, 6, 7, 9}: if prev_note is None:
if master_notes.play_notes and master_notes.play_notes[-1].type in {5, 6, 7, 9}: raise ValueError("No previous note found")
prev_note = master_notes.play_notes[-1]
elif branch_m[-1].play_notes and branch_m[-1].play_notes[-1].type in {5, 6, 7, 9}:
prev_note = branch_m[-1].play_notes[-1]
elif branch_e[-1].play_notes and branch_e[-1].play_notes[-1].type in {5, 6, 7, 9}:
prev_note = branch_e[-1].play_notes[-1]
elif branch_n[-1].play_notes and branch_n[-1].play_notes[-1].type in {5, 6, 7, 9}:
prev_note = branch_n[-1].play_notes[-1]
else:
prev_note = curr_note_list[-1]
new_pixels_per_ms = prev_note.pixels_per_frame_x / (1000 / 60) new_pixels_per_ms = prev_note.pixels_per_frame_x / (1000 / 60)
if new_pixels_per_ms == 0: if new_pixels_per_ms == 0:
note.load_ms = note.hit_ms note.load_ms = note.hit_ms
@@ -871,6 +861,7 @@ class TJAParser:
bisect.insort(curr_draw_list, note, key=lambda x: x.load_ms) bisect.insort(curr_draw_list, note, key=lambda x: x.load_ms)
self.get_moji(curr_note_list, ms_per_measure) self.get_moji(curr_note_list, ms_per_measure)
index += 1 index += 1
prev_note = note
# Sorting by load_ms is necessary for drawing, as some notes appear on the # Sorting by load_ms is necessary for drawing, as some notes appear on the
# screen slower regardless of when they reach the judge circle # screen slower regardless of when they reach the judge circle
# Bars can be sorted like this because they don't need hit detection # Bars can be sorted like this because they don't need hit detection