From dffaadf7ecb86c58312d500c0410f8f21ee89325 Mon Sep 17 00:00:00 2001 From: RobertoMaurizzi Date: Mon, 7 Jul 2025 21:51:06 +0800 Subject: [PATCH] improve debug maps, add usable camera scrolling --- src/demo/level.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/demo/level.rs b/src/demo/level.rs index 0947bcb..0ca5670 100644 --- a/src/demo/level.rs +++ b/src/demo/level.rs @@ -75,24 +75,29 @@ fn pan_camera( mut pan: ResMut, mouse_buttons: Res>, mouse_motion: Res, -) { + mut camera: Query<&mut Transform, With>, +) -> Result { let delta = mouse_motion.delta; if mouse_buttons.pressed(MouseButton::Middle) { pan.offset += delta; - info!("pan offset: {}", pan.offset); + let mut gino = camera.single_mut()?; + gino.translation += Vec3::new(-delta.x, delta.y, 0.0) / 5.0; } + Ok(()) } fn translate_grid_coords_entities( mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed>, pan: Res, ) { + // TODO: what is this used for? Why it doesn't work for a moving Player? for (mut transform, grid_coords) in grid_coords_entities.iter_mut() { - transform.translation = ( - //pan.offset + - bevy_ecs_ldtk::utils::grid_coords_to_translation(*grid_coords, IVec2::splat(GRID_SIZE)) - ) + // info!("translated pan offset: {}", pan.offset); + transform.translation = (bevy_ecs_ldtk::utils::grid_coords_to_translation( + *grid_coords, + IVec2::splat(GRID_SIZE), + )) .extend(transform.translation.z); } } @@ -131,21 +136,15 @@ impl TryFrom<&str> for Direction { pub fn convert_neighbors( neighbors: &[NeighbourLevel], ) -> Result, &'static str> { - info!("got neighbors: {:?}", neighbors); - let gino = neighbors + let neighbours = neighbors .iter() - // .map(|neighbor| { - // let direction = Direction::try_from(neighbor.dir.as_str())?; - // Ok((direction, LevelIid::from(neighbor.level_iid.clone()))) - // }) .filter_map(|neighbor| { Direction::try_from(neighbor.dir.as_str()) .ok() - .map(|dir| (dir, LevelIid::from(neighbor.level_iid.clone()))) + .map(|dir| (dir, LevelIid::new(neighbor.level_iid.clone()))) }) .collect(); - info!("converted to: {:?}", gino); - Ok(gino) + Ok(neighbours) } #[derive(Debug, Default, Resource, Reflect)] @@ -158,12 +157,15 @@ pub struct LevelWalls { } impl LevelWalls { - pub fn in_wall(&self, grid_coords: &GridCoords) -> bool { + pub fn leave_level(&self, grid_coords: &GridCoords) -> bool { grid_coords.x < 0 || grid_coords.y < 0 || grid_coords.x >= self.level_width || grid_coords.y >= self.level_height - || self.wall_locations.contains(grid_coords) + } + + pub fn in_wall(&self, grid_coords: &GridCoords) -> bool { + self.wall_locations.contains(grid_coords) } pub fn debug_collisions(&self, player_pos: &GridCoords) { @@ -182,7 +184,7 @@ impl LevelWalls { print!("_"); } } - println!(); + println!(" [y: {y:02}]"); } } } @@ -294,7 +296,7 @@ fn cache_wall_locations( info!("Trying to format it"); // FIXME: a .rev() here? It doesn't look necessary from what gets printed // remember to fix the supposed "map dragging" too - for y in (0..(level.px_hei / GRID_SIZE)).rev() { + for y in (0..(level.px_hei / GRID_SIZE)) { for x in (0..(level.px_wid / GRID_SIZE)) { let index = (y * level.px_wid / GRID_SIZE + x) as usize; if let Some(value) = field.int_grid_csv.get(index) { @@ -306,7 +308,7 @@ fn cache_wall_locations( } } } - println!(); + println!(" [y: {y:02}]"); } } });