From 7f0f6421d3e25d1b77cc90346905f0719743ab12 Mon Sep 17 00:00:00 2001 From: Chris Mounce Date: Fri, 23 Jan 2026 17:17:39 -0800 Subject: [PATCH] Use single params for stat coordinates, step vals - Combine `x` and `y` into `at` - Combine `x_step` and `y_step` into `step` --- src/zzt/text.rs | 56 ++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/zzt/text.rs b/src/zzt/text.rs index 8ab98ba..5450caf 100644 --- a/src/zzt/text.rs +++ b/src/zzt/text.rs @@ -198,12 +198,12 @@ fn write_stat(output: &mut String, index: usize, stat: &Stat, element: Option), Tuple2(u8, u8), + SignedTuple2(i16, i16), TripleQuotedString(String), } @@ -418,6 +419,26 @@ fn tuple2(input: &str) -> IResult<&str, (u8, u8)> { Ok((input, (element_id, color))) } +/// Parse a tuple of signed integers like (0, -1). +fn signed_tuple2(input: &str) -> IResult<&str, (i16, i16)> { + let (input, _) = char('(').parse(input)?; + let (input, _) = multispace0.parse(input)?; + let (input, a) = map_res(recognize(pair(opt(char('-')), digit1)), |s: &str| { + s.parse::() + }) + .parse(input)?; + let (input, _) = multispace0.parse(input)?; + let (input, _) = char(',').parse(input)?; + let (input, _) = multispace0.parse(input)?; + let (input, b) = map_res(recognize(pair(opt(char('-')), digit1)), |s: &str| { + s.parse::() + }) + .parse(input)?; + let (input, _) = multispace0.parse(input)?; + let (input, _) = char(')').parse(input)?; + Ok((input, (a, b))) +} + /// Parse a string array like ["foo", "bar", ""]. fn string_array(input: &str) -> IResult<&str, Vec> { let (input, _) = char('[').parse(input)?; @@ -456,6 +477,7 @@ fn parse_value(input: &str) -> IResult<&str, Value> { map(triple_quoted_string, Value::TripleQuotedString), map(string_array, Value::StringArray), map(quoted_string, Value::String), + map(signed_tuple2, |(a, b)| Value::SignedTuple2(a, b)), map(tuple2, |(a, b)| Value::Tuple2(a, b)), map(boolean, Value::Bool), map(integer, Value::Int), @@ -689,14 +711,10 @@ fn parse_stat_section<'a>( let mut y: u8 = 0; for (key, value) in &pairs { match *key { - "x" => { - if let Value::Int(n) = value { - x = *n as u8; - } - } - "y" => { - if let Value::Int(n) = value { - y = *n as u8; + "at" => { + if let Value::SignedTuple2(nx, ny) = value { + x = *nx as u8; + y = *ny as u8; } } _ => {} @@ -728,20 +746,16 @@ fn parse_stat_section<'a>( // Second pass: apply all properties for (key, value) in pairs { match key { - "x" | "y" => {} // Already handled + "at" => {} // Already handled "cycle" => { if let Value::Int(n) = value { stat.cycle = n as i16; } } - "x_step" => { - if let Value::Int(n) = value { - stat.x_step = n as i16; - } - } - "y_step" => { - if let Value::Int(n) = value { - stat.y_step = n as i16; + "step" => { + if let Value::SignedTuple2(xs, ys) = value { + stat.x_step = xs; + stat.y_step = ys; } } "under" => {