Compare commits

..

No commits in common. '9d5cb8d2432865e23921df61557adcbb1e05e7c2' and 'a14dcff8f975836afc01d351f16f8febc5e0d502' have entirely different histories.

@ -59,8 +59,7 @@ fn main()
WorldPlugin { WorldPlugin {
grid_width: 100., grid_width: 100.,
grid_height: 100., grid_height: 100.
top_margin: 50.0
}, },
ShapePlugin ShapePlugin
)) ))
@ -88,6 +87,18 @@ fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials
Agent Agent
)); ));
// Line test
let line = shapes::Line(Vec2::ZERO, Vec2::new(100.0, 100.0));
commands.spawn((
ShapeBundle {
path: GeometryBuilder::build_as(&line),
..default()
},
Stroke::new(Color::ORANGE_RED, 5.0),
//Fill::color(Color::ORANGE_RED),
));
// UI // UI
// Text with multiple sections // Text with multiple sections
commands.spawn(( commands.spawn((

@ -1,10 +1,7 @@
use bevy::{prelude::*, window::WindowResized}; use bevy::prelude::*;
use bevy_prototype_lyon::prelude::*; use bevy_prototype_lyon::prelude::*;
#[derive(Component)]
struct GridLine;
#[derive(Resource)] #[derive(Resource)]
struct WorldPluginState struct WorldPluginState
{ {
@ -12,7 +9,6 @@ struct WorldPluginState
window_height: f32, window_height: f32,
grid_width: f32, grid_width: f32,
grid_height: f32, grid_height: f32,
top_margin: f32,
} }
@ -20,7 +16,6 @@ pub struct WorldPlugin
{ {
pub grid_width: f32, pub grid_width: f32,
pub grid_height: f32, pub grid_height: f32,
pub top_margin: f32,
} }
impl Plugin for WorldPlugin impl Plugin for WorldPlugin
@ -38,67 +33,41 @@ impl Plugin for WorldPlugin
window_width: window.resolution.width(), window_width: window.resolution.width(),
window_height: window.resolution.height(), window_height: window.resolution.height(),
grid_width: self.grid_width, grid_width: self.grid_width,
grid_height: self.grid_height, grid_height: self.grid_height
top_margin: self.top_margin,
}) })
.add_systems(Update, on_resize)
.add_systems(Startup, setup); .add_systems(Startup, setup);
} }
} }
} }
fn setup(mut commands: Commands, settings: Res<WorldPluginState>) fn setup(mut commands: Commands, settings: Res<WorldPluginState>, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<ColorMaterial>>)
{ {
// Camera
//commands.spawn(Camera2dBundle::default());
// Add Grid // Add Grid
let cell_width = settings.window_width / (settings.grid_width - 1.0); // let cell_width = settings.window_width / settings.grid_width;
let cell_height = (settings.window_height - settings.top_margin) / (settings.grid_height - 1.0); // let cell_height = settings.window_height / settings.grid_height;
let line_size = 2.0; // let line_size = 2;
let half_screen_width = settings.window_width / 2.0; // for i in 0..settings.grid_width as i32
let half_screen_height = (settings.window_height - settings.top_margin) / 2.0; // {
for i in 0..settings.grid_width as i32 // for j in 0..settings.grid_height as i32
{ // {
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 - 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);
}
}
fn add_line(commands: &mut Commands, point_a: Vec2, point_b: Vec2, line_size: f32)
{
let line = shapes::Line(point_a, point_b);
commands.spawn((
ShapeBundle {
path: GeometryBuilder::build_as(&line),
..default()
},
Stroke::new(Color::BLACK, line_size),
GridLine,
));
} }
fn on_resize(mut commands: Commands, mut settings: ResMut<WorldPluginState>, mut resize_reader: EventReader<WindowResized>, mut grid: Query<(Entity, &GridLine)> ) // fn add_line(mut commands: Commands, point_a: Vec2, point_b: Vec2, line_size: i32)
{ // {
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()); // commands.spawn(MaterialMesh2dBundle {
} // mesh: meshes
// .add(shape::Quad::new(Vec2::new(cell_width * i, cell_height * j)).into())
// .into(),
// material: materials.add(ColorMaterial::from(Color::BLACK)),
// transform: Transform::from_translation(Vec3::new(50., 0., 0.)),
// ..default()
// });
// }
Loading…
Cancel
Save