From ba9313d5856c68505ad0d28964abc7b9c34a1ac9 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sat, 11 Feb 2023 21:55:58 -0500 Subject: [PATCH] Render the tiles in the correct space --- hex-grid/src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/hex-grid/src/main.rs b/hex-grid/src/main.rs index c093726..7d62cc2 100644 --- a/hex-grid/src/main.rs +++ b/hex-grid/src/main.rs @@ -201,6 +201,7 @@ impl ObjectImpl for HexGridWindowPrivate { context.set_line_width(2.); + /* deep_water.render_on_context(&context, 0., 0.); shallow_water.render_on_context(&context, 150., 0.); grasslands.render_on_context(&context, 300., 0.); @@ -208,8 +209,8 @@ impl ObjectImpl for HexGridWindowPrivate { mountain.render_on_context(&context, 0., 100.); badlands.render_on_context(&context, 150., 100.); swamp.render_on_context(&context, 0., 200.); + */ - /* for coordinate in vec![AxialAddr::origin()] .into_iter() .chain(AxialAddr::origin().addresses(MAP_RADIUS)) @@ -220,15 +221,22 @@ impl ObjectImpl for HexGridWindowPrivate { + HEX_RADIUS * ((3. as f64).sqrt() / 2. * (coordinate.q() as f64) + (3. as f64).sqrt() * (coordinate.r() as f64)); + let translate_x = center_x - HEX_RADIUS; + let translate_y = center_y - (3. as f64).sqrt() * HEX_RADIUS / 2.; - let tile = hex_map.get(&coordinate).unwrap(); - let color = tile.color(); - context.set_source_rgb(color.0, color.1, color.2); - - draw_hexagon(context, center_x, center_y, HEX_RADIUS); - let _ = context.fill(); + let tile = match hex_map.get(&coordinate).unwrap() { + Terrain::Mountain => &mountain, + Terrain::Grasslands => &grasslands, + Terrain::ShallowWater => &shallow_water, + Terrain::DeepWater => &deep_water, + Terrain::Badlands => &badlands, + Terrain::Desert => &desert, + Terrain::Swamp => &swamp, + _ => panic!("unhandled terrain type"), + }; + tile.render_on_context(context, translate_x, translate_y); + // draw_hexagon(context, center_x, center_y, HEX_RADIUS); } - */ }); } self.drawing_area.add_controller(&motion_controller);