Starting on the world mod
parent
09f8c2a49d
commit
cbba37a993
@ -0,0 +1,72 @@
|
||||
|
||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
||||
|
||||
#[derive(Resource)]
|
||||
struct WorldPluginState
|
||||
{
|
||||
window_width: f32,
|
||||
window_height: f32,
|
||||
grid_width: f32,
|
||||
grid_height: f32,
|
||||
|
||||
}
|
||||
|
||||
pub struct WorldPlugin
|
||||
{
|
||||
pub grid_width: f32,
|
||||
pub grid_height: f32,
|
||||
}
|
||||
|
||||
impl Plugin for WorldPlugin
|
||||
{
|
||||
fn build(&self, app: &mut App)
|
||||
{
|
||||
let window_plugin = app.get_added_plugins::<WindowPlugin>()[0];
|
||||
if let Some(window) = &window_plugin.primary_window
|
||||
{
|
||||
println!("WorldPlugin: Window resolution is: ({}, {})", window.resolution.width(), window.resolution.height());
|
||||
|
||||
|
||||
app.insert_resource(WorldPluginState
|
||||
{
|
||||
window_width: window.resolution.width(),
|
||||
window_height: window.resolution.height(),
|
||||
grid_width: self.grid_width,
|
||||
grid_height: self.grid_height
|
||||
})
|
||||
.add_systems(Startup, setup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
let cell_width = settings.window_width / settings.grid_width;
|
||||
let cell_height = settings.window_height / settings.grid_height;
|
||||
let line_size = 2;
|
||||
for i in 0..settings.grid_width as i32
|
||||
{
|
||||
for j in 0..settings.grid_height as i32
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn add_line(mut commands: Commands, point_a: Vec2, point_b: Vec2, line_size: i32)
|
||||
// {
|
||||
|
||||
|
||||
// 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…
Reference in New Issue