Add support for recording "TerrainState::In" and GameRecord version support system.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
use semver;
|
||||
use serde::Deserialize;
|
||||
use std::{fmt, fs::File};
|
||||
use std::{fmt, fs::File, u64};
|
||||
|
||||
pub const GAMELOG_MIN_VER: semver::Version = semver::Version::new(0, 2, 0);
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct LogFile(Vec<GameRecord>);
|
||||
@@ -12,6 +15,20 @@ impl TryFrom<File> for LogFile {
|
||||
}
|
||||
}
|
||||
|
||||
impl LogFile {
|
||||
pub fn get_min_ver(&mut self) -> semver::Version {
|
||||
let mut lowest = semver::Version::new(u64::MAX, u64::MAX, u64::MAX);
|
||||
|
||||
self.0.iter().for_each(|x| {
|
||||
if x.version.cmp_precedence(&lowest).is_lt() {
|
||||
lowest = x.version.clone()
|
||||
}
|
||||
});
|
||||
|
||||
lowest
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct GameRecord {
|
||||
version: semver::Version,
|
||||
@@ -35,16 +52,16 @@ enum Quarter {
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
enum TerrainState {
|
||||
Distance(u8),
|
||||
Yards(u8),
|
||||
GoalLine,
|
||||
In,
|
||||
Inches,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Play {
|
||||
action: Option<Action>,
|
||||
down: Down,
|
||||
terrain: u8,
|
||||
terrain: TerrainState,
|
||||
}
|
||||
|
||||
enum DownError {
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -2,7 +2,7 @@ mod calculator;
|
||||
mod gamelog;
|
||||
|
||||
use clap::Parser;
|
||||
use gamelog::LogFile;
|
||||
use gamelog::{GAMELOG_MIN_VER, LogFile};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
@@ -12,9 +12,9 @@ struct Args {
|
||||
short,
|
||||
long,
|
||||
value_hint = clap::ValueHint::DirPath,
|
||||
default_value = std::env::current_dir()
|
||||
default_value = dbg!(format!("{}/templates/logfile.ron", std::env::current_dir()
|
||||
.expect("Failed to get current working dir.")
|
||||
.into_os_string()
|
||||
.into_os_string().to_str().unwrap()))
|
||||
)]
|
||||
logfile_path: PathBuf,
|
||||
}
|
||||
@@ -22,7 +22,7 @@ struct Args {
|
||||
fn main() {
|
||||
let config = Args::parse();
|
||||
|
||||
let log: LogFile = LogFile::try_from(
|
||||
let mut log: LogFile = LogFile::try_from(
|
||||
match std::fs::OpenOptions::new() // Defaults to setting all options false.
|
||||
.read(true) // Only need ensure that reading is possible.
|
||||
.open(&config.logfile_path.as_path())
|
||||
@@ -32,4 +32,14 @@ fn main() {
|
||||
},
|
||||
)
|
||||
.expect("Failed to open game log file");
|
||||
|
||||
let log_ver = dbg!(log.get_min_ver());
|
||||
|
||||
if log_ver.cmp_precedence(&GAMELOG_MIN_VER).is_lt() {
|
||||
panic!(
|
||||
"Error: Log file GameRecord version deviates as low as {:?}, while minimum {:?} is required",
|
||||
log_ver.to_string(),
|
||||
GAMELOG_MIN_VER.to_string()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user