Stash
This commit is contained in:
parent
2bd51ef53c
commit
717b3172e7
32
src/ui.rs
32
src/ui.rs
@ -1,10 +1,14 @@
|
|||||||
#![feature(array_zip)]
|
#![feature(array_zip)]
|
||||||
|
|
||||||
|
mod system;
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
|
||||||
use csv::{Position, Reader, ReaderBuilder};
|
use csv::{Position, Reader, ReaderBuilder};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use itertools::Itertools;
|
||||||
|
use crate::system::spaces::square_grid::Grid2D;
|
||||||
|
|
||||||
#[derive(Parser, Resource)] // requires `derive` feature
|
#[derive(Parser, Resource)] // requires `derive` feature
|
||||||
enum UICli {
|
enum UICli {
|
||||||
@ -16,8 +20,6 @@ struct CSVArgs {
|
|||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Position2D(i32, i32);
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let cli = UICli::parse();
|
let cli = UICli::parse();
|
||||||
|
|
||||||
@ -53,27 +55,13 @@ fn read_csv(
|
|||||||
.from_path(csv_path)
|
.from_path(csv_path)
|
||||||
.expect("Failed to read csv");
|
.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
|
let positions = reader
|
||||||
.records()
|
.deserialize()
|
||||||
.map(|record| {
|
.collect::<Result<Vec<Grid2D>, _>>()
|
||||||
let record = record.expect("Failed to read position");
|
.expect("Failed to parse csv");
|
||||||
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");
|
|
||||||
|
|
||||||
Position2D(x, y)
|
for Grid2D { x, y } in positions {
|
||||||
});
|
let rect_size = 2.0;
|
||||||
|
|
||||||
for Position2D(x, y) in positions {
|
|
||||||
let rect_size = 5.0;
|
|
||||||
|
|
||||||
commands.spawn(SpriteBundle {
|
commands.spawn(SpriteBundle {
|
||||||
sprite: Sprite {
|
sprite: Sprite {
|
||||||
@ -90,5 +78,5 @@ fn read_csv(
|
|||||||
fn setup_ui(
|
fn setup_ui(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
) {
|
) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::new_with_far(1000.0));
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user