use std::{num::ParseIntError, str::FromStr};
use crate::OPointFacingDir;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct OPointFacing {
pub count: u32,
pub direction: OPointFacingDir,
}
impl FromStr for OPointFacing {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<OPointFacing, ParseIntError> {
s.parse::<u32>().map(|value| match value {
0 => OPointFacing {
count: 1,
direction: OPointFacingDir::ParentSame,
},
1 => OPointFacing {
count: 1,
direction: OPointFacingDir::ParentOpposite,
},
10 => OPointFacing {
count: 1,
direction: OPointFacingDir::Right,
},
_ => {
let count = value / 10;
let direction = if value & 1 == 0 {
OPointFacingDir::ParentSame
} else {
OPointFacingDir::ParentOpposite
};
OPointFacing { count, direction }
}
})
}
}