improve debug maps, add usable camera scrolling
Some checks failed
Some checks failed
This commit is contained in:
parent
ec9df9433c
commit
dffaadf7ec
1 changed files with 22 additions and 20 deletions
|
@ -75,24 +75,29 @@ fn pan_camera(
|
||||||
mut pan: ResMut<PanLevel>,
|
mut pan: ResMut<PanLevel>,
|
||||||
mouse_buttons: Res<ButtonInput<MouseButton>>,
|
mouse_buttons: Res<ButtonInput<MouseButton>>,
|
||||||
mouse_motion: Res<AccumulatedMouseMotion>,
|
mouse_motion: Res<AccumulatedMouseMotion>,
|
||||||
) {
|
mut camera: Query<&mut Transform, With<Camera>>,
|
||||||
|
) -> Result {
|
||||||
let delta = mouse_motion.delta;
|
let delta = mouse_motion.delta;
|
||||||
|
|
||||||
if mouse_buttons.pressed(MouseButton::Middle) {
|
if mouse_buttons.pressed(MouseButton::Middle) {
|
||||||
pan.offset += delta;
|
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(
|
fn translate_grid_coords_entities(
|
||||||
mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>,
|
mut grid_coords_entities: Query<(&mut Transform, &GridCoords), Changed<GridCoords>>,
|
||||||
pan: Res<PanLevel>,
|
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() {
|
for (mut transform, grid_coords) in grid_coords_entities.iter_mut() {
|
||||||
transform.translation = (
|
// info!("translated pan offset: {}", pan.offset);
|
||||||
//pan.offset +
|
transform.translation = (bevy_ecs_ldtk::utils::grid_coords_to_translation(
|
||||||
bevy_ecs_ldtk::utils::grid_coords_to_translation(*grid_coords, IVec2::splat(GRID_SIZE))
|
*grid_coords,
|
||||||
)
|
IVec2::splat(GRID_SIZE),
|
||||||
|
))
|
||||||
.extend(transform.translation.z);
|
.extend(transform.translation.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,21 +136,15 @@ impl TryFrom<&str> for Direction {
|
||||||
pub fn convert_neighbors(
|
pub fn convert_neighbors(
|
||||||
neighbors: &[NeighbourLevel],
|
neighbors: &[NeighbourLevel],
|
||||||
) -> Result<HashMap<Direction, LevelIid>, &'static str> {
|
) -> Result<HashMap<Direction, LevelIid>, &'static str> {
|
||||||
info!("got neighbors: {:?}", neighbors);
|
let neighbours = neighbors
|
||||||
let gino = neighbors
|
|
||||||
.iter()
|
.iter()
|
||||||
// .map(|neighbor| {
|
|
||||||
// let direction = Direction::try_from(neighbor.dir.as_str())?;
|
|
||||||
// Ok((direction, LevelIid::from(neighbor.level_iid.clone())))
|
|
||||||
// })
|
|
||||||
.filter_map(|neighbor| {
|
.filter_map(|neighbor| {
|
||||||
Direction::try_from(neighbor.dir.as_str())
|
Direction::try_from(neighbor.dir.as_str())
|
||||||
.ok()
|
.ok()
|
||||||
.map(|dir| (dir, LevelIid::from(neighbor.level_iid.clone())))
|
.map(|dir| (dir, LevelIid::new(neighbor.level_iid.clone())))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
info!("converted to: {:?}", gino);
|
Ok(neighbours)
|
||||||
Ok(gino)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Resource, Reflect)]
|
#[derive(Debug, Default, Resource, Reflect)]
|
||||||
|
@ -158,12 +157,15 @@ pub struct LevelWalls {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.x < 0
|
||||||
|| grid_coords.y < 0
|
|| grid_coords.y < 0
|
||||||
|| grid_coords.x >= self.level_width
|
|| grid_coords.x >= self.level_width
|
||||||
|| grid_coords.y >= self.level_height
|
|| 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) {
|
pub fn debug_collisions(&self, player_pos: &GridCoords) {
|
||||||
|
@ -182,7 +184,7 @@ impl LevelWalls {
|
||||||
print!("_");
|
print!("_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!();
|
println!(" [y: {y:02}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,7 +296,7 @@ fn cache_wall_locations(
|
||||||
info!("Trying to format it");
|
info!("Trying to format it");
|
||||||
// FIXME: a .rev() here? It doesn't look necessary from what gets printed
|
// FIXME: a .rev() here? It doesn't look necessary from what gets printed
|
||||||
// remember to fix the supposed "map dragging" too
|
// 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)) {
|
for x in (0..(level.px_wid / GRID_SIZE)) {
|
||||||
let index = (y * level.px_wid / GRID_SIZE + x) as usize;
|
let index = (y * level.px_wid / GRID_SIZE + x) as usize;
|
||||||
if let Some(value) = field.int_grid_csv.get(index) {
|
if let Some(value) = field.int_grid_csv.get(index) {
|
||||||
|
@ -306,7 +308,7 @@ fn cache_wall_locations(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!();
|
println!(" [y: {y:02}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue