Add command line arg
This commit is contained in:
parent
924df55e18
commit
639be88ce1
27
src/ui.rs
27
src/ui.rs
@ -2,11 +2,25 @@ use std::default::Default;
|
||||
use std::error::Error;
|
||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
||||
use csv::{Position, Reader, ReaderBuilder};
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Resource)] // requires `derive` feature
|
||||
enum UICli {
|
||||
CSV(CSVArgs)
|
||||
}
|
||||
|
||||
#[derive(clap::Args)]
|
||||
struct CSVArgs {
|
||||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
struct Position2D(i32, i32);
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let cli = UICli::parse();
|
||||
|
||||
App::new()
|
||||
.insert_resource(cli)
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
title: "DLA Static 2D Render".to_string(),
|
||||
@ -24,9 +38,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
fn read_csv(
|
||||
cli: Res<UICli>,
|
||||
mut commands: Commands
|
||||
) {
|
||||
let csv_path = "/Users/joshuacoles/Developer/checkouts/jc3091/CompB DLA/data-analysis/data/stick-probability/0.6/1.csv";
|
||||
let csv_path = match &cli.into_inner() {
|
||||
UICli::CSV(CSVArgs { path }) => path,
|
||||
_ => panic!("Ahh"),
|
||||
};
|
||||
|
||||
let mut reader = ReaderBuilder::new()
|
||||
.has_headers(true)
|
||||
.from_path(csv_path)
|
||||
@ -35,8 +54,6 @@ fn read_csv(
|
||||
let headers = reader.headers()
|
||||
.expect("Failed to read headers");
|
||||
|
||||
dbg!(headers);
|
||||
|
||||
let x_column = headers.iter().position(|name| name.trim() == "x")
|
||||
.expect("Failed to find x column");
|
||||
|
||||
@ -54,9 +71,7 @@ fn read_csv(
|
||||
});
|
||||
|
||||
for Position2D(x, y) in positions {
|
||||
// Rectangle
|
||||
let rect_size = 5.0;
|
||||
println!("{} {}", x, y);
|
||||
|
||||
commands.spawn(SpriteBundle {
|
||||
sprite: Sprite {
|
||||
@ -72,8 +87,6 @@ fn read_csv(
|
||||
|
||||
fn setup_ui(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
commands.spawn(Camera2dBundle::default());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user