This commit is contained in:
Joshua Coles 2023-03-10 21:12:50 +00:00
parent 2bd51ef53c
commit 717b3172e7

View File

@ -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<dyn Error>> {
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::<i32>().expect("Failed to read x");
let y: i32 = record[y_column].trim().parse::<i32>().expect("Failed to read y");
.deserialize()
.collect::<Result<Vec<Grid2D>, _>>()
.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));
}