|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::{prelude::*, window::WindowResized};
|
|
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
use bevy_prototype_lyon::prelude::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
struct IsLine;
|
|
|
|
struct GridLine;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
#[derive(Resource)]
|
|
|
|
struct WorldPluginState
|
|
|
|
struct WorldPluginState
|
|
|
|
@ -41,6 +41,7 @@ impl Plugin for WorldPlugin
|
|
|
|
grid_height: self.grid_height,
|
|
|
|
grid_height: self.grid_height,
|
|
|
|
top_margin: self.top_margin,
|
|
|
|
top_margin: self.top_margin,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
.add_systems(Update, on_resize)
|
|
|
|
.add_systems(Startup, setup);
|
|
|
|
.add_systems(Startup, setup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -80,6 +81,24 @@ fn add_line(commands: &mut Commands, point_a: Vec2, point_b: Vec2, line_size: f3
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Stroke::new(Color::BLACK, line_size),
|
|
|
|
Stroke::new(Color::BLACK, line_size),
|
|
|
|
IsLine,
|
|
|
|
GridLine,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn on_resize(mut commands: Commands, mut settings: ResMut<WorldPluginState>, mut resize_reader: EventReader<WindowResized>, mut grid: Query<(Entity, &GridLine)> )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for e in resize_reader.iter()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// When resolution is being changed
|
|
|
|
|
|
|
|
// info!("new window size: {:.1} x {:.1}", e.width, e.height);
|
|
|
|
|
|
|
|
settings.window_width = e.width;
|
|
|
|
|
|
|
|
settings.window_height = e.height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (entity, line) in &grid
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
commands.entity(entity).despawn();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setup(commands, settings.into());
|
|
|
|
|
|
|
|
}
|