feat: begin port of current oppai rx/ap

This commit is contained in:
tsunyoku
2022-11-20 14:15:29 +00:00
parent e3e583ce40
commit 3f6af95873
12 changed files with 1919 additions and 0 deletions
+50
View File
@@ -151,6 +151,37 @@ macro_rules! parse_general_body {
}};
}
macro_rules! parse_metadata_body {
($self:ident, $reader:ident, $section:ident) => {{
let mut empty = true;
let mut creator = None;
let mut beatmap_id = None;
while next_line!($reader)? != 0 {
if let Some(bytes) = $reader.get_section() {
*$section = Section::from_bytes(bytes);
empty = false;
break;
}
let (key, value) = $reader.split_colon().ok_or(ParseError::BadLine)?;
if key == b"Creator" {
creator = Some(value)
} else if key == b"BeatmapID" {
if let Some(val) = u32::parse_in_range(value) {
beatmap_id = Some(val);
}
}
}
$self.creator = creator.unwrap_or("").to_string();
$self.beatmap_id = beatmap_id.unwrap_or(0);
Ok(empty)
}};
}
macro_rules! parse_difficulty_body {
($self:ident, $reader:ident, $section:ident) => {{
let mut ar = None;
@@ -752,6 +783,7 @@ macro_rules! parse_body {
loop {
match section {
Section::General => section!(map, parse_general, reader, section),
Section::Metadata => section!(map, parse_metadata, reader, section),
Section::Difficulty => section!(map, parse_difficulty, reader, section),
Section::Events => section!(map, parse_events, reader, section),
Section::TimingPoints => section!(map, parse_timingpoints, reader, section),
@@ -956,6 +988,14 @@ impl Beatmap {
parse_general_body!(self, reader, section)
}
fn parse_metadata<R: Read>(
&mut self,
reader: &mut FileReader<R>,
section: &mut Section,
) -> ParseResult<bool> {
parse_metadata_body!(self, reader, section)
}
fn parse_difficulty<R: Read>(
&mut self,
reader: &mut FileReader<R>,
@@ -1023,6 +1063,14 @@ impl Beatmap {
parse_general_body!(self, reader, section)
}
async fn parse_metadata<R: AsyncRead + Unpin>(
&mut self,
reader: &mut FileReader<R>,
section: &mut Section,
) -> ParseResult<bool> {
parse_metadata_body!(self, reader, section)
}
async fn parse_difficulty<R: AsyncRead + Unpin>(
&mut self,
reader: &mut FileReader<R>,
@@ -1076,6 +1124,7 @@ enum Section {
TimingPoints,
HitObjects,
Events,
Metadata,
}
impl Section {
@@ -1086,6 +1135,7 @@ impl Section {
b"TimingPoints" => Self::TimingPoints,
b"HitObjects" => Self::HitObjects,
b"Events" => Self::Events,
b"Metadata" => Self::Metadata,
_ => Self::None,
}
}