mirror of
https://github.com/maciejpedzich/f1-game-packet-parser.git
synced 2025-04-12 00:21:11 +02:00
refactor: replace SessionType enum with session_type submodule of constants
This commit is contained in:
parent
46d81ac97e
commit
ac9408f720
@ -2,6 +2,7 @@ pub mod driver_id;
|
||||
pub mod team_id;
|
||||
/// The wheel order is: `REAR_LEFT`, `REAR_RIGHT`, `FRONT_LEFT`, `FRONT_RIGHT`.
|
||||
pub mod wheel_index;
|
||||
pub mod session_type;
|
||||
|
||||
use binrw::BinRead;
|
||||
use bitflags::bitflags;
|
||||
@ -90,38 +91,6 @@ pub enum Weather {
|
||||
Storm = 5,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(
|
||||
BinRead,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
Copy,
|
||||
Clone,
|
||||
Debug,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[br(little, repr(u8))]
|
||||
pub enum SessionType {
|
||||
Unknown = 0,
|
||||
Practice1 = 1,
|
||||
Practice2 = 2,
|
||||
Practice3 = 3,
|
||||
ShortPractice = 4,
|
||||
Qualifying1 = 5,
|
||||
Qualifying2 = 6,
|
||||
Qualifying3 = 7,
|
||||
ShortQualifying = 8,
|
||||
OneShotQualifying = 9,
|
||||
Race = 10,
|
||||
Race2 = 11,
|
||||
Race3 = 12,
|
||||
TimeTrial = 13,
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(
|
||||
BinRead,
|
||||
|
23
src/constants/session_type.rs
Normal file
23
src/constants/session_type.rs
Normal file
@ -0,0 +1,23 @@
|
||||
pub const UNKNOWN: u8 = 0;
|
||||
pub const PRACTICE_1: u8 = 1;
|
||||
pub const PRACTICE_2: u8 = 2;
|
||||
pub const PRACTICE_3: u8 = 3;
|
||||
pub const SHORT_PRACTICE: u8 = 4;
|
||||
pub const QUALIFYING_1: u8 = 5;
|
||||
pub const QUALIFYING_2: u8 = 6;
|
||||
pub const QUALIFYING_3: u8 = 7;
|
||||
pub const SHORT_QUALIFYING: u8 = 8;
|
||||
pub const ONE_SHOT_QUALIFYING: u8 = 9;
|
||||
pub const SPRINT_1: u8 = 10;
|
||||
pub const SPRINT_2: u8 = 11;
|
||||
pub const SPRINT_3: u8 = 12;
|
||||
pub const SHORT_SPRINT: u8 = 13;
|
||||
pub const ONE_SHOT_SPRINT: u8 = 14;
|
||||
pub const RACE_2024: u8 = 15;
|
||||
pub const RACE_2_2024: u8 = 16;
|
||||
pub const RACE_3_2024: u8 = 17;
|
||||
pub const RACE: u8 = 10;
|
||||
pub const RACE_2: u8 = 11;
|
||||
pub const RACE_3: u8 = 12;
|
||||
pub const TIME_TRIAL: u8 = 13;
|
||||
pub const TIME_TRIAL_2024: u8 = 18;
|
@ -18,7 +18,7 @@ use crate::constants::{
|
||||
DynamicRacingLine, DynamicRacingLineType, FlashbackLimit, ForecastAccuracy,
|
||||
FormationLapExperience, Formula, GameMode, GearboxAssist, LowFuelMode, MfdPanelIndex,
|
||||
PitStopExperience, RaceStarts, RecoveryMode, RedFlags, RuleSet, SafetyCar,
|
||||
SafetyCarExperience, SafetyCarStatus, SessionLength, SessionType, SpeedUnit,
|
||||
SafetyCarExperience, SafetyCarStatus, SessionLength, SpeedUnit,
|
||||
SurfaceType, TemperatureUnit, TrackId, TyreTemperature, Weather, MAX_NUM_CARS,
|
||||
};
|
||||
use crate::packets::car_damage::CarDamageData;
|
||||
@ -79,7 +79,9 @@ pub struct F1PacketSession {
|
||||
/// Track's length in metres.
|
||||
pub track_length: u16,
|
||||
/// Session's type.
|
||||
pub session_type: SessionType,
|
||||
/// See [`session_type`](mod@crate::constants::session_type)
|
||||
/// for possible values.
|
||||
pub session_type: u8,
|
||||
/// Unique identifier of the track.
|
||||
pub track_id: TrackId,
|
||||
/// Formula of cars being raced.
|
||||
@ -347,7 +349,7 @@ pub struct F1PacketSession {
|
||||
count(num_sessions_in_weekend),
|
||||
pad_after(MAX_NUM_SESSIONS - num_sessions_in_weekend)
|
||||
)]
|
||||
pub weekend_structure: Vec<SessionType>,
|
||||
pub weekend_structure: Vec<u8>,
|
||||
/// Distance (in metres) around the track where sector 2 starts.
|
||||
/// Available from the 2024 format onwards.
|
||||
#[br(if(packet_format >= 2024))]
|
||||
@ -716,19 +718,19 @@ pub struct F1PacketTimeTrial {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct InvalidBool(u8);
|
||||
pub(crate) struct InvalidBoolValue(u8);
|
||||
|
||||
impl fmt::Display for InvalidBool {
|
||||
impl fmt::Display for InvalidBoolValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Invalid bool value: {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn u8_to_bool(value: u8) -> Result<bool, InvalidBool> {
|
||||
pub(crate) fn u8_to_bool(value: u8) -> Result<bool, InvalidBoolValue> {
|
||||
match value {
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
_ => Err(InvalidBool(value)),
|
||||
_ => Err(InvalidBoolValue(value)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::constants::{MarshalZoneFlag, SessionType, TemperatureChange, Weather};
|
||||
use crate::constants::{MarshalZoneFlag, TemperatureChange, Weather};
|
||||
use binrw::BinRead;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -43,7 +43,9 @@ pub struct MarshalZone {
|
||||
)]
|
||||
pub struct WeatherForecastSample {
|
||||
/// Session's type.
|
||||
pub session_type: SessionType,
|
||||
/// See [`session_type`](mod@crate::constants::session_type)
|
||||
/// for possible values.
|
||||
pub session_type: u8,
|
||||
/// Time in minutes the forecast is for.
|
||||
pub time_offset: u8,
|
||||
/// Forecasted weather.
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::u8_to_bool;
|
||||
use crate::constants::{ActualTyreCompound, SessionType, VisualTyreCompound};
|
||||
use crate::constants::{ActualTyreCompound, VisualTyreCompound};
|
||||
|
||||
use binrw::BinRead;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -30,7 +30,9 @@ pub struct TyreSetData {
|
||||
#[br(try_map(u8_to_bool))]
|
||||
pub available: bool,
|
||||
/// Recommended session for this tyre set.
|
||||
pub recommended_session: SessionType,
|
||||
/// See [`session_type`](mod@crate::constants::session_type)
|
||||
/// for possible values.
|
||||
pub recommended_session: u8,
|
||||
/// Laps left in this set.
|
||||
pub life_span: u8,
|
||||
/// Max number of laps recommended for this compound.
|
||||
|
Loading…
x
Reference in New Issue
Block a user