mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
Cleaned up parser a little, more feature complete implementation soon
This commit is contained in:
1382
Renatus.osu
Normal file
1382
Renatus.osu
Normal file
File diff suppressed because it is too large
Load Diff
114
osz.py
114
osz.py
@@ -13,67 +13,77 @@ from libs.global_data import Modifiers
|
|||||||
from libs.utils import strip_comments
|
from libs.utils import strip_comments
|
||||||
from libs.tja import TimelineObject, Note, NoteType, Drumroll, Balloon, NoteList, CourseData, ParserState
|
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()
|
contents = osu_file.open(mode='r', encoding='utf-8').read()
|
||||||
|
|
||||||
import re
|
class OsuParser:
|
||||||
def read_osu_note_data(file_path, target_header="HitObjects"):
|
def __init__(self):
|
||||||
note_data = []
|
|
||||||
current_header = None
|
|
||||||
|
|
||||||
with file_path.open(mode='r', encoding='utf-8') as f:
|
def read_osu_data(self, file_path, target_header="HitObjects"):
|
||||||
|
data = []
|
||||||
|
current_header = None
|
||||||
|
|
||||||
for line in f:
|
with file_path.open(mode='r', encoding='utf-8') as f:
|
||||||
line = line.rstrip("\n")
|
|
||||||
|
|
||||||
if re.match(r"\[\w*\]", line): # header pattern
|
for line in f:
|
||||||
current_header = line[1:-1]
|
line = line.rstrip("\n")
|
||||||
|
|
||||||
if current_header == target_header:
|
if re.match(r"\[\w*\]", line): # header pattern
|
||||||
if re.match(r"[-+]?\d*\.?\d+" , line):
|
current_header = line[1:-1]
|
||||||
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)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
return note_data
|
if current_header == target_header:
|
||||||
|
|
||||||
|
if re.match(r"[-+]?\d*\.?\d+" , line): # Events, TimingPoints, HitObjects
|
||||||
note_data = read_osu_note_data(osu_file)
|
string_array = re.findall(r"[-+]?\d*\.?\d+" , line) # search for floats
|
||||||
|
int_array = [float(num_str) for num_str in string_array]
|
||||||
def note_data_to_NoteList(note_data):
|
data.append(int_array)
|
||||||
osu_NoteList = NoteList()
|
|
||||||
counter = 0
|
if re.match(r'\w*\:\s(\w*.?\w*)', line): # General, Editor, Metadata, Difficulty
|
||||||
for line in note_data:
|
match = re.search(r'\w*\:\s(\w*.?\w*)', line)
|
||||||
if line[3] == 1 and line[4] == 0: # DON
|
if match:
|
||||||
don = Note()
|
data.append(match.group(1))
|
||||||
don.type = NoteType(1)
|
|
||||||
don.hit_ms = line[2]
|
else:
|
||||||
don.bpm = 207
|
continue
|
||||||
don.scroll_x = 1
|
|
||||||
don.scroll_y = 0
|
return data
|
||||||
don.display = True
|
|
||||||
don.index = counter
|
def note_data_to_NoteList(self, note_data):
|
||||||
counter = counter + 1
|
osu_NoteList = NoteList()
|
||||||
don.moji = 0
|
counter = 0
|
||||||
osu_NoteList.play_notes.append(don)
|
for line in note_data:
|
||||||
if line[3] == 1 and line[4] == 2: # KAT
|
if line[3] == 1 and line[4] == 0: # DON
|
||||||
kat = Note()
|
don = Note()
|
||||||
kat.type = NoteType(2)
|
don.type = NoteType(1)
|
||||||
kat.hit_ms = line[2]
|
don.hit_ms = line[2]
|
||||||
kat.bpm = 207
|
don.bpm = 207
|
||||||
kat.scroll_x = 1
|
don.scroll_x = 1
|
||||||
kat.scroll_y = 0
|
don.scroll_y = 0
|
||||||
kat.display = True
|
don.display = True
|
||||||
kat.index = counter
|
don.index = counter
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
kat.moji = 1
|
don.moji = 0
|
||||||
osu_NoteList.play_notes.append(kat)
|
osu_NoteList.play_notes.append(don)
|
||||||
osu_NoteList.draw_notes = osu_NoteList.play_notes.copy()
|
if line[3] == 1 and line[4] != 0: # KAT
|
||||||
return osu_NoteList
|
kat = Note()
|
||||||
|
kat.type = NoteType(2)
|
||||||
|
kat.hit_ms = line[2]
|
||||||
|
kat.bpm = 207
|
||||||
|
kat.scroll_x = 1
|
||||||
|
kat.scroll_y = 0
|
||||||
|
kat.display = True
|
||||||
|
kat.index = counter
|
||||||
|
counter = counter + 1
|
||||||
|
kat.moji = 1
|
||||||
|
osu_NoteList.play_notes.append(kat)
|
||||||
|
osu_NoteList.draw_notes = osu_NoteList.play_notes.copy()
|
||||||
|
return osu_NoteList
|
||||||
|
|
||||||
|
|
||||||
|
myparse = OsuParser()
|
||||||
|
|
||||||
|
print(myparse.read_osu_data(osu_file, target_header="TimingPoints"))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ from libs.utils import (
|
|||||||
)
|
)
|
||||||
from libs.video import VideoPlayer
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -416,10 +416,11 @@ class Player:
|
|||||||
unload_offset = travel_distance / sudden_pixels_per_ms
|
unload_offset = travel_distance / sudden_pixels_per_ms
|
||||||
note.unload_ms = note.hit_ms + unload_offset
|
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):
|
def reset_chart(self):
|
||||||
|
myparse = OsuParser()
|
||||||
#notes, self.branch_m, self.branch_e, self.branch_n = self.tja.notes_to_position(self.difficulty)
|
#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.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])
|
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])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user