Cleaned up parser a little, more feature complete implementation soon

This commit is contained in:
Valerio
2026-01-05 18:38:33 -05:00
parent b766a9e170
commit 299ac2c47b
3 changed files with 1448 additions and 55 deletions

1382
Renatus.osu Normal file

File diff suppressed because it is too large Load Diff

38
osz.py
View File

@@ -13,12 +13,16 @@ from libs.global_data import Modifiers
from libs.utils import strip_comments
from libs.tja import TimelineObject, Note, NoteType, Drumroll, Balloon, NoteList, CourseData, ParserState
osu_file = Path("./PNames.osu")
import re
osu_file = Path("./Renatus.osu")
contents = osu_file.open(mode='r', encoding='utf-8').read()
import re
def read_osu_note_data(file_path, target_header="HitObjects"):
note_data = []
class OsuParser:
def __init__(self):
def read_osu_data(self, file_path, target_header="HitObjects"):
data = []
current_header = None
with file_path.open(mode='r', encoding='utf-8') as f:
@@ -30,19 +34,23 @@ def read_osu_note_data(file_path, target_header="HitObjects"):
current_header = line[1:-1]
if current_header == target_header:
if re.match(r"[-+]?\d*\.?\d+" , line):
if re.match(r"[-+]?\d*\.?\d+" , line): # Events, TimingPoints, HitObjects
string_array = re.findall(r"[-+]?\d*\.?\d+" , line) # search for floats
int_array = [int(num_str) for num_str in string_array]
note_data.append(int_array)
int_array = [float(num_str) for num_str in string_array]
data.append(int_array)
if re.match(r'\w*\:\s(\w*.?\w*)', line): # General, Editor, Metadata, Difficulty
match = re.search(r'\w*\:\s(\w*.?\w*)', line)
if match:
data.append(match.group(1))
else:
continue
return note_data
return data
note_data = read_osu_note_data(osu_file)
def note_data_to_NoteList(note_data):
def note_data_to_NoteList(self, note_data):
osu_NoteList = NoteList()
counter = 0
for line in note_data:
@@ -58,7 +66,7 @@ def note_data_to_NoteList(note_data):
counter = counter + 1
don.moji = 0
osu_NoteList.play_notes.append(don)
if line[3] == 1 and line[4] == 2: # KAT
if line[3] == 1 and line[4] != 0: # KAT
kat = Note()
kat.type = NoteType(2)
kat.hit_ms = line[2]
@@ -74,6 +82,8 @@ def note_data_to_NoteList(note_data):
return osu_NoteList
myparse = OsuParser()
print(myparse.read_osu_data(osu_file, target_header="TimingPoints"))

View File

@@ -50,7 +50,7 @@ from libs.utils import (
)
from libs.video import VideoPlayer
from libs.osz import read_osu_note_data, note_data_to_NoteList
from libs.osz import OsuParser
logger = logging.getLogger(__name__)
@@ -416,10 +416,11 @@ class Player:
unload_offset = travel_distance / sudden_pixels_per_ms
note.unload_ms = note.hit_ms + unload_offset
###from libs.osz import read_osu_note_data, note_data_to_NoteList
###from libs.osz import OsuParser
def reset_chart(self):
myparse = OsuParser()
#notes, self.branch_m, self.branch_e, self.branch_n = self.tja.notes_to_position(self.difficulty)
notes = note_data_to_NoteList(read_osu_note_data(Path("./PNames.osu")))
notes = myparse.note_data_to_NoteList(myparse.read_osu_data(Path("./PNames.osu")))
self.branch_m, self.branch_e, self.branch_n = [], [], []
self.play_notes, self.draw_note_list, self.draw_bar_list = deque(apply_modifiers(notes, self.modifiers)[0]), deque(apply_modifiers(notes, self.modifiers)[1]), deque(apply_modifiers(notes, self.modifiers)[2])