Skip to content

Commit

Permalink
fix: format version
Browse files Browse the repository at this point in the history
  • Loading branch information
2278535805 committed Feb 8, 2025
1 parent 76f2a64 commit d842ff5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 75 deletions.
2 changes: 1 addition & 1 deletion prpr/src/core/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Note {
let mut color = self.object.now_color();
color.a *= res.alpha * ctrl_obj.alpha.now_opt().unwrap_or(1.);
let end_spd = self.speed * ctrl_obj.y.now_opt().unwrap_or(1.);
let spd = if matches!(res.chart_format, ChartFormat::Pgr | ChartFormat::Pgr1) && matches!(self.kind, NoteKind::Hold { .. }) { 1. } else { end_spd };
let spd = if matches!(res.chart_format, ChartFormat::Pgr) && matches!(self.kind, NoteKind::Hold { .. }) { 1. } else { end_spd };

let line_height = config.line_height / res.aspect_ratio * spd;
let height = self.height / res.aspect_ratio * spd;
Expand Down
1 change: 0 additions & 1 deletion prpr/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub enum ChartFormat {
Rpe = 0,
Pec,
Pgr,
Pgr1,
Pbc,
}

Expand Down
2 changes: 1 addition & 1 deletion prpr/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod pec;
pub use pec::parse_pec;

mod pgr;
pub use pgr::{parse_phigros, parse_phigros_fv1};
pub use pgr::parse_phigros;

mod rpe;
pub use rpe::{parse_rpe, RPE_HEIGHT, RPE_WIDTH};
Expand Down
76 changes: 11 additions & 65 deletions prpr/src/parse/pgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct PgrJudgeLine {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct PgrChart {
format_version: u32,
offset: f32,
judge_line_list: Vec<PgrJudgeLine>,
}
Expand Down Expand Up @@ -226,7 +227,7 @@ fn parse_notes(r: f32, mut pgr: Vec<PgrNote>, _speed: &mut AnimFloat, height: &m
.collect()
}

fn parse_judge_line(pgr: PgrJudgeLine, max_time: f32) -> Result<JudgeLine> {
fn parse_judge_line(pgr: PgrJudgeLine, max_time: f32, format_version: u32) -> Result<JudgeLine> {
let r = 60. / pgr.bpm / 32.;
let (mut speed, mut height) = parse_speed_events(r, pgr.speed_events, max_time).context("Failed to parse speed events")?;
let notes_above = parse_notes(r, pgr.notes_above, &mut speed, &mut height, true).context("Failed to parse notes above")?;
Expand All @@ -238,37 +239,13 @@ fn parse_judge_line(pgr: PgrJudgeLine, max_time: f32) -> Result<JudgeLine> {
object: Object {
alpha: parse_float_events(r, pgr.alpha_events).with_context(|| ptl!("alpha-events-parse-failed"))?,
rotation: parse_float_events(r, pgr.rotate_events).with_context(|| ptl!("rotate-events-parse-failed"))?,
translation: parse_move_events(r, pgr.move_events).with_context(|| ptl!("move-events-parse-failed"))?,
..Default::default()
},
ctrl_obj: RefCell::default(),
kind: JudgeLineKind::Normal,
height,
incline: AnimFloat::default(),
notes,
color: Anim::default(),
parent: None,
z_index: 0,
show_below: false,
attach_ui: None,

cache,
})
}

fn parse_judge_line_fv1(pgr: PgrJudgeLine, max_time: f32) -> Result<JudgeLine> {
let r = 60. / 32. / pgr.bpm;
let (mut speed, mut height) = parse_speed_events(r, pgr.speed_events, max_time).context("Failed to parse speed events")?;
let notes_above = parse_notes(r, pgr.notes_above, &mut speed, &mut height, true).context("Failed to parse notes above")?;
let mut notes_below = parse_notes(r, pgr.notes_below, &mut speed, &mut height, false).context("Failed to parse notes below")?;
let mut notes = notes_above;
notes.append(&mut notes_below);
let cache = JudgeLineCache::new(&mut notes);
Ok(JudgeLine {
object: Object {
alpha: parse_float_events(r, pgr.alpha_events).with_context(|| ptl!("alpha-events-parse-failed"))?,
rotation: parse_float_events(r, pgr.rotate_events).with_context(|| ptl!("rotate-events-parse-failed"))?,
translation: parse_move_events_fv1(r, pgr.move_events).with_context(|| ptl!("move-events-parse-failed"))?,
translation: {
match format_version {
1 => parse_move_events_fv1(r, pgr.move_events).with_context(|| ptl!("move-events-parse-failed"))?,
3 => parse_move_events(r, pgr.move_events).with_context(|| ptl!("move-events-parse-failed"))?,
_ => ptl!(bail "unknown-format-version"),
}
},
..Default::default()
},
ctrl_obj: RefCell::default(),
Expand All @@ -288,6 +265,7 @@ fn parse_judge_line_fv1(pgr: PgrJudgeLine, max_time: f32) -> Result<JudgeLine> {

pub fn parse_phigros(source: &str, extra: ChartExtra) -> Result<Chart> {
let pgr: PgrChart = serde_json::from_str(source).with_context(|| ptl!("json-parse-failed"))?;
let format_version = pgr.format_version;
let mut bpm_values = Vec::new();
for (index, judge_line) in pgr.judge_line_list.iter().enumerate() {
bpm_values.push((index as f32, judge_line.bpm));
Expand All @@ -311,40 +289,8 @@ pub fn parse_phigros(source: &str, extra: ChartExtra) -> Result<Chart> {
.judge_line_list
.into_iter()
.enumerate()
.map(|(id, pgr)| parse_judge_line(pgr, max_time).with_context(|| ptl!("judge-line-location", "jlid" => id)))
.map(|(id, pgr)| parse_judge_line(pgr, max_time, format_version).with_context(|| ptl!("judge-line-location", "jlid" => id)))
.collect::<Result<Vec<_>>>()?;
process_lines(&mut lines);
Ok(Chart::new(pgr.offset, lines, BpmList::new_time(bpm_values), ChartSettings::default(), extra, HashMap::new()))
}

pub fn parse_phigros_fv1(source: &str, extra: ChartExtra) -> Result<Chart> {
let pgr: PgrChart = serde_json::from_str(source).with_context(|| ptl!("json-parse-failed"))?;
let mut bpm_values = Vec::new();
for (index, judge_line) in pgr.judge_line_list.iter().enumerate() {
bpm_values.push((index as f32, judge_line.bpm));
}

let max_time = *pgr
.judge_line_list
.iter()
.map(|line| {
line.notes_above
.iter()
.chain(line.notes_below.iter())
.map(|note| note.time.not_nan())
.max()
.unwrap_or_default()
* (60. / line.bpm / 32.)
})
.max()
.unwrap_or_default()
+ 1.;
let mut lines = pgr
.judge_line_list
.into_iter()
.enumerate()
.map(|(id, pgr)| parse_judge_line_fv1(pgr, max_time).with_context(|| ptl!("judge-line-location", "jlid" => id)))
.collect::<Result<Vec<_>>>()?;
process_lines(&mut lines);
Ok(Chart::new(pgr.offset, lines, BpmList::new_time(bpm_values), ChartSettings::default(), extra,HashMap::new()))
}
9 changes: 2 additions & 7 deletions prpr/src/scene/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
fs::FileSystem,
info::{ChartFormat, ChartInfo},
judge::Judge,
parse::{parse_extra, parse_pec, parse_phigros, parse_phigros_fv1, parse_rpe},
parse::{parse_extra, parse_pec, parse_phigros, parse_rpe},
task::Task,
time::TimeManager,
ui::{RectButton, TextPainter, Ui},
Expand Down Expand Up @@ -191,11 +191,7 @@ impl GameScene {
if text.contains("\"META\"") {
ChartFormat::Rpe
} else {
if text.starts_with("{\"formatVersion\":3") {
ChartFormat::Pgr
} else {
ChartFormat::Pgr1
}
ChartFormat::Pgr
}
} else {
ChartFormat::Pec
Expand All @@ -207,7 +203,6 @@ impl GameScene {
let mut chart = match format {
ChartFormat::Rpe => parse_rpe(&String::from_utf8_lossy(&bytes), fs, extra).await,
ChartFormat::Pgr => parse_phigros(&String::from_utf8_lossy(&bytes), extra),
ChartFormat::Pgr1 => parse_phigros_fv1(&String::from_utf8_lossy(&bytes), extra),
ChartFormat::Pec => parse_pec(&String::from_utf8_lossy(&bytes), extra),
ChartFormat::Pbc => {
let mut r = BinaryReader::new(Cursor::new(&bytes));
Expand Down

0 comments on commit d842ff5

Please sign in to comment.