improve debug maps, add usable camera scrolling
Some checks failed
CI / Format (push) Has been cancelled
CI / Docs (push) Has been cancelled
CI / Clippy lints (push) Has been cancelled
CI / Bevy lints (push) Has been cancelled
CI / Tests (push) Has been cancelled
CI / Check web (push) Has been cancelled

This commit is contained in:
Roberto Maurizzi 2025-07-07 21:51:06 +08:00
parent ec9df9433c
commit dffaadf7ec
Signed by: robm
GPG key ID: F26E59AFAAADEA55

View file

@ -75,24 +75,29 @@ fn pan_camera(
mut pan: ResMut<PanLevel>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
mouse_motion: Res<AccumulatedMouseMotion>,
) {
mut camera: Query<&mut Transform, With<Camera>>,
) -> 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<GridCoords>>,
pan: Res<PanLevel>,
) {
// 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<HashMap<Direction, LevelIid>, &'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}]");
}
}
});