From 717b3172e7ec856528e4695be436ef045fd56498 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Fri, 10 Mar 2023 21:12:50 +0000 Subject: [PATCH] Stash --- src/ui.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 8c312da..54872f0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,10 +1,14 @@ #![feature(array_zip)] +mod system; + use std::default::Default; use std::error::Error; use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; use csv::{Position, Reader, ReaderBuilder}; use clap::Parser; +use itertools::Itertools; +use crate::system::spaces::square_grid::Grid2D; #[derive(Parser, Resource)] // requires `derive` feature enum UICli { @@ -16,8 +20,6 @@ struct CSVArgs { path: std::path::PathBuf, } -struct Position2D(i32, i32); - fn main() -> Result<(), Box> { let cli = UICli::parse(); @@ -53,27 +55,13 @@ fn read_csv( .from_path(csv_path) .expect("Failed to read csv"); - let headers = reader.headers() - .expect("Failed to read headers"); - - let x_column = headers.iter().position(|name| name.trim() == "x") - .expect("Failed to find x column"); - - let y_column = headers.iter().position(|name| name.trim() == "y") - .expect("Failed to find x column"); - let positions = reader - .records() - .map(|record| { - let record = record.expect("Failed to read position"); - let x: i32 = record[x_column].trim().parse::().expect("Failed to read x"); - let y: i32 = record[y_column].trim().parse::().expect("Failed to read y"); + .deserialize() + .collect::, _>>() + .expect("Failed to parse csv"); - Position2D(x, y) - }); - - for Position2D(x, y) in positions { - let rect_size = 5.0; + for Grid2D { x, y } in positions { + let rect_size = 2.0; commands.spawn(SpriteBundle { sprite: Sprite { @@ -90,5 +78,5 @@ fn read_csv( fn setup_ui( mut commands: Commands, ) { - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2dBundle::new_with_far(1000.0)); } \ No newline at end of file