From dd43024e95734d8dd3c4d251f4b010d08e27f106 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 14 May 2022 14:02:59 +0100 Subject: [PATCH] otterlib: Plumb gpc through from load to render Some magical pieces require their xdata (which they set in load) for rendering. And now we can have library pieces which contain magical pieces which otterlib must therefore handle. Signed-off-by: Ian Jackson --- src/bin/otterlib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 5258be87..54167c10 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -92,7 +92,7 @@ fn preview(items: Vec) { } } - let mut pieces: Vec = items.into_iter().map(|it| { + let mut pieces: Vec<(Prep, GPiece)> = items.into_iter().map(|it| { let spec = ItemSpec::from(&it); let sortkey = it.sortkey; (||{ @@ -124,20 +124,20 @@ fn preview(items: Vec) { .map(|(min,max)| max-min) .collect::>(); - Ok::<_,AE>(Prep { spec, p, sortkey, uos, bbox, size }) + Ok::<_,AE>((Prep { spec, p, sortkey, uos, bbox, size }, gpc )) })().with_context(|| format!("{:?}", &spec)) }).collect::,_>>()?; // clones as a bodge for https://github.com/rust-lang/rust/issues/34162 - pieces.sort_by_key(|p| (p.spec.item.clone(), p.spec.lib.clone())); + pieces.sort_by_key(|(p,_)| (p.spec.item.clone(), p.spec.lib.clone())); - let max_facecols = pieces.iter().map(|s| s.face_cols()).max().unwrap_or(1); - let max_uos = pieces.iter().map(|s| s.uos.len()).max().unwrap_or(0); + let max_facecols = pieces.iter().map(|s| s.0.face_cols()).max().unwrap_or(1); + let max_uos = pieces.iter().map(|s| s.0.uos.len()).max().unwrap_or(0); println!("{}", &HTML_PRELUDE); println!(r#""#); - for s in &pieces { - let Prep { spec, sortkey, p, uos, bbox, size } = s; + for (s, gpc) in &mut pieces { + let Prep { spec, sortkey, p, uos, bbox, size } = &*s; macro_rules! println { ($($x:tt)*) => ({ @@ -198,7 +198,7 @@ fn preview(items: Vec) { &surround, &dasharray, HELD_SURROUND_COLOUR); } let mut html = Html::lit("").into(); - let gpc = GPiece { face: face.into(), ..GPiece::dummy() }; + gpc.face = face.into(); p.svg_piece(&mut html, &gpc, &GameState::dummy(), default())?; println!("{}", html); } -- 2.30.2