Add a program that generates an empty map
This commit is contained in:
parent
f17dd5b89d
commit
c5721c1e87
|
@ -0,0 +1,32 @@
|
||||||
|
use coordinates::hex_map;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct MapVal;
|
||||||
|
|
||||||
|
impl Default for MapVal {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MapVal> for String {
|
||||||
|
fn from(_val: MapVal) -> Self {
|
||||||
|
".".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = std::env::args().skip(1);
|
||||||
|
|
||||||
|
let filename = args
|
||||||
|
.next()
|
||||||
|
.map(|p| PathBuf::from(p))
|
||||||
|
.expect("A filename is required");
|
||||||
|
let size = args
|
||||||
|
.next()
|
||||||
|
.and_then(|s| s.parse::<usize>().ok())
|
||||||
|
.unwrap_or(3);
|
||||||
|
let map: hex_map::Map<MapVal> = hex_map::Map::new_hexagonal(size);
|
||||||
|
hex_map::write_file(filename, map);
|
||||||
|
}
|
|
@ -67,7 +67,9 @@ where
|
||||||
std::fs::write(path, write_data(map).join("\n")).map_err(Error::from)
|
std::fs::write(path, write_data(map).join("\n")).map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_data<'a, A: Default + From<String>>(data: impl Iterator<Item = &'a str> + 'a) -> Map<A> {
|
pub fn parse_data<'a, A: Default + From<String>>(
|
||||||
|
data: impl Iterator<Item = &'a str> + 'a,
|
||||||
|
) -> Map<A> {
|
||||||
fn parse_line<A: From<String>>(input: &str) -> Result<(AxialAddr, A), nom::error::Error<&str>> {
|
fn parse_line<A: From<String>>(input: &str) -> Result<(AxialAddr, A), nom::error::Error<&str>> {
|
||||||
fn parse<A: From<String>>(input: &str) -> IResult<&str, (AxialAddr, A)> {
|
fn parse<A: From<String>>(input: &str) -> IResult<&str, (AxialAddr, A)> {
|
||||||
let (input, addr) = parse_address(input)?;
|
let (input, addr) = parse_address(input)?;
|
||||||
|
|
Loading…
Reference in New Issue