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 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)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct LogFile(Vec<GameRecord>);
|
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)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct GameRecord {
|
struct GameRecord {
|
||||||
version: semver::Version,
|
version: semver::Version,
|
||||||
@@ -35,16 +52,16 @@ enum Quarter {
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
enum TerrainState {
|
enum TerrainState {
|
||||||
Distance(u8),
|
Yards(u8),
|
||||||
GoalLine,
|
GoalLine,
|
||||||
In,
|
Inches,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Play {
|
struct Play {
|
||||||
action: Option<Action>,
|
action: Option<Action>,
|
||||||
down: Down,
|
down: Down,
|
||||||
terrain: u8,
|
terrain: TerrainState,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DownError {
|
enum DownError {
|
||||||
|
|||||||
18
src/main.rs
18
src/main.rs
@@ -2,7 +2,7 @@ mod calculator;
|
|||||||
mod gamelog;
|
mod gamelog;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use gamelog::LogFile;
|
use gamelog::{GAMELOG_MIN_VER, LogFile};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
@@ -12,9 +12,9 @@ struct Args {
|
|||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
value_hint = clap::ValueHint::DirPath,
|
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.")
|
.expect("Failed to get current working dir.")
|
||||||
.into_os_string()
|
.into_os_string().to_str().unwrap()))
|
||||||
)]
|
)]
|
||||||
logfile_path: PathBuf,
|
logfile_path: PathBuf,
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ struct Args {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let config = Args::parse();
|
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.
|
match std::fs::OpenOptions::new() // Defaults to setting all options false.
|
||||||
.read(true) // Only need ensure that reading is possible.
|
.read(true) // Only need ensure that reading is possible.
|
||||||
.open(&config.logfile_path.as_path())
|
.open(&config.logfile_path.as_path())
|
||||||
@@ -32,4 +32,14 @@ fn main() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.expect("Failed to open game log file");
|
.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()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
down: Kickoff(
|
down: Kickoff(
|
||||||
offence: Nebraska
|
offence: Nebraska
|
||||||
),
|
),
|
||||||
terrain: Distance(10)
|
terrain: Yards(10)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user