Skip to content

Commit

Permalink
fix: reset state on new chart
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Feb 13, 2025
1 parent 978e4d2 commit 06e595d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tja"
version = "0.3.3"
version = "0.3.4"
edition = "2021"
description = "TJA file parser written in Rust, working in Rust, Python, and WebAssembly."
license = "MIT"
Expand Down
22 changes: 22 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct TJAParser {
metadata: Option<Metadata>,
charts: Vec<Chart>,
state: Option<ParserState>,
state_internal: Option<ParserState>,
inherited_headers: HashMap<String, String>,
current_headers: HashMap<String, String>,
metadata_keys: HashSet<String>,
Expand Down Expand Up @@ -120,6 +121,7 @@ impl TJAParser {
metadata: None,
charts: Vec::new(),
state: None,
state_internal: None,
inherited_headers: HashMap::new(),
current_headers: HashMap::new(),
metadata_keys,
Expand All @@ -140,6 +142,7 @@ impl TJAParser {
let mut notes_buffer = Vec::new();

self.state = Some(ParserState::new(120.0));
self.state_internal = Some(ParserState::new(120.0));

for line in content.lines() {
if let Some(line) = normalize_line(line) {
Expand All @@ -151,6 +154,7 @@ impl TJAParser {
if key == "BPM" {
if let Ok(bpm) = value.parse::<f64>() {
state.bpm = bpm;
self.state_internal.as_mut().unwrap().bpm = bpm;
}
}
metadata_dict.insert(key, value.clone());
Expand Down Expand Up @@ -289,6 +293,24 @@ impl TJAParser {
self.charts.push(chart);
state.parsing_chart = true;
state.timestamp = -self.metadata.as_ref().unwrap().offset;
state.bpm = self.state_internal.as_ref().unwrap().bpm;
state.scroll = self.state_internal.as_ref().unwrap().scroll;
state.gogo = self.state_internal.as_ref().unwrap().gogo;
state.barline = self.state_internal.as_ref().unwrap().barline;
state.measure_num = self.state_internal.as_ref().unwrap().measure_num;
state.measure_den = self.state_internal.as_ref().unwrap().measure_den;
state.branch_condition = self
.state_internal
.as_ref()
.unwrap()
.branch_condition
.clone();
state.current_branch =
self.state_internal.as_ref().unwrap().current_branch.clone();
state.delay = self.state_internal.as_ref().unwrap().delay;
state.timestamp_branch_start =
self.state_internal.as_ref().unwrap().timestamp_branch_start;
state.current_segment = None;
}
Directive::End => {
if let Some(mut segment) = state.current_segment.take() {
Expand Down

0 comments on commit 06e595d

Please sign in to comment.