Building LogFile Format

This commit is contained in:
Cutieguwu
2025-03-24 21:58:41 -04:00
parent 483d31cc36
commit a0c587d222
7 changed files with 368 additions and 2 deletions

0
src/calculator.rs Normal file
View File

100
src/gamelog.rs Normal file
View File

@@ -0,0 +1,100 @@
use ron::de::{SpannedError, from_reader};
use serde::Deserialize;
use std::{fmt, fs::File};
#[derive(Debug, Deserialize)]
pub struct LogFile(Vec<GameRecord>);
impl TryFrom<File> for LogFile {
type Error = SpannedError;
fn try_from(file: File) -> Result<Self, Self::Error> {
from_reader(file)
}
}
#[derive(Debug, Deserialize)]
struct GameRecord([Option<Period>; 4]);
#[derive(Debug, Deserialize)]
struct Period {
start: Quarter,
end: Option<Quarter>,
plays: Vec<Play>,
}
#[derive(Debug, Deserialize)]
enum Quarter {
First,
Second,
Third,
Fourth,
}
#[derive(Debug, Deserialize)]
struct Play {
action: Option<Action>,
down: Down,
terrain: u8,
}
enum DownError {
NotKickoff,
}
impl fmt::Display for DownError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::NotKickoff => write!(f, "Variant was not Down::Kickoff."),
}
}
}
#[derive(Debug, Deserialize)]
enum Down {
Kickoff { offence: Team },
First,
Second,
Third,
Fourth,
Pat,
}
impl Down {
fn get_offence(&self) -> Result<&Team, DownError> {
match self {
Self::Kickoff { offence } => Ok(offence),
_ => Err(DownError::NotKickoff),
}
}
}
#[derive(Debug, Deserialize)]
enum Action {
CrackStudentBodyRightTackle,
Curls,
FleaFlicker,
HalfbackSlam,
HalfbackSlipScreen,
HalfbackSweep,
Mesh,
PlayActionBoot,
PlayActionComebacks,
PlayActionPowerZero,
PowerZero,
SlantBubble,
SlotOut,
SpeedOption,
StrongFlood,
}
#[derive(Debug, Deserialize, Clone)]
enum Team {
ArizonaState,
Colorado,
Iowa,
Nebraska,
SouthCarolina,
Syracuse,
TexasAnM,
}

View File

@@ -1,3 +1,33 @@
fn main() {
println!("Hello, world!");
mod calculator;
mod gamelog;
use clap::Parser;
use gamelog::LogFile;
use std::{fs::OpenOptions, path::PathBuf};
#[derive(Debug, Parser)]
struct Args {
/// Path to source file or block device
#[arg(
short,
long,
value_hint = clap::ValueHint::DirPath,
default_value = std::env::current_dir().expect("Failed to get current working dir.").into_os_string()
)]
logfile_path: PathBuf,
}
fn main() {
let config = Args::parse();
let log: LogFile = LogFile::try_from(
match OpenOptions::new() // Defaults to setting all options false.
.read(true)
.open(&config.logfile_path.as_path())
{
Ok(f) => f,
Err(err) => panic!("Failed to open log file: {:?}", err),
},
)
.expect("Failed to open game log file");
}