|
|
|
|
@ -12,6 +12,7 @@ struct WorldPluginState
|
|
|
|
|
window_height: f32,
|
|
|
|
|
grid_width: f32,
|
|
|
|
|
grid_height: f32,
|
|
|
|
|
top_margin: f32,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -19,6 +20,7 @@ pub struct WorldPlugin
|
|
|
|
|
{
|
|
|
|
|
pub grid_width: f32,
|
|
|
|
|
pub grid_height: f32,
|
|
|
|
|
pub top_margin: f32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Plugin for WorldPlugin
|
|
|
|
|
@ -36,7 +38,8 @@ impl Plugin for WorldPlugin
|
|
|
|
|
window_width: window.resolution.width(),
|
|
|
|
|
window_height: window.resolution.height(),
|
|
|
|
|
grid_width: self.grid_width,
|
|
|
|
|
grid_height: self.grid_height
|
|
|
|
|
grid_height: self.grid_height,
|
|
|
|
|
top_margin: self.top_margin,
|
|
|
|
|
})
|
|
|
|
|
.add_systems(Startup, setup);
|
|
|
|
|
}
|
|
|
|
|
@ -47,22 +50,22 @@ fn setup(mut commands: Commands, settings: Res<WorldPluginState>)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Add Grid
|
|
|
|
|
let cell_width = settings.window_width / settings.grid_width;
|
|
|
|
|
let cell_height = settings.window_height / settings.grid_height;
|
|
|
|
|
let cell_width = settings.window_width / (settings.grid_width - 1.0);
|
|
|
|
|
let cell_height = (settings.window_height - settings.top_margin) / (settings.grid_height - 1.0);
|
|
|
|
|
let line_size = 2.0;
|
|
|
|
|
let half_screen_width = settings.window_width / 2.0;
|
|
|
|
|
let half_screen_height = settings.window_height / 2.0;
|
|
|
|
|
let half_screen_height = (settings.window_height - settings.top_margin) / 2.0;
|
|
|
|
|
for i in 0..settings.grid_width as i32
|
|
|
|
|
{
|
|
|
|
|
let point_a = Vec2::new(i as f32 * cell_width - half_screen_width, -half_screen_height);
|
|
|
|
|
let point_b = Vec2::new(i as f32 * cell_width - half_screen_width, half_screen_height);
|
|
|
|
|
let point_a = Vec2::new(i as f32 * cell_width - half_screen_width, -half_screen_height - settings.top_margin);
|
|
|
|
|
let point_b = Vec2::new(i as f32 * cell_width - half_screen_width, half_screen_height - settings.top_margin);
|
|
|
|
|
add_line(&mut commands, point_a, point_b, line_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i in 0..settings.grid_height as i32
|
|
|
|
|
{
|
|
|
|
|
let point_a = Vec2::new(-half_screen_width, i as f32 * cell_height - half_screen_height);
|
|
|
|
|
let point_b = Vec2::new(half_screen_width, i as f32 * cell_height - half_screen_height);
|
|
|
|
|
let point_a = Vec2::new(-half_screen_width, i as f32 * cell_height - half_screen_height - settings.top_margin);
|
|
|
|
|
let point_b = Vec2::new(half_screen_width, i as f32 * cell_height - half_screen_height - settings.top_margin);
|
|
|
|
|
add_line(&mut commands, point_a, point_b, line_size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|