Merge initial implementation of Pedal and Leader Board widgets #3
5 changed files with 92 additions and 16 deletions
|
@ -8,7 +8,10 @@ use rfactor_sm_reader::{rF2VehicleTelemetry, VehicleScoringInfoV01};
|
|||
use ui::prelude::*;
|
||||
use utilities::prelude::Color;
|
||||
|
||||
use crate::overlay::{rfactor_data::DataReceiver, UiOverlay};
|
||||
use crate::overlay::{
|
||||
rfactor_data::{DataReceiver, GamePhase},
|
||||
UiOverlay,
|
||||
};
|
||||
use crate::write_log;
|
||||
|
||||
pub struct LeaderBoard {
|
||||
|
@ -49,14 +52,8 @@ impl LeaderBoard {
|
|||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl UiOverlay for LeaderBoard {}
|
||||
|
||||
impl DataReceiver for LeaderBoard {
|
||||
fn scoring_update(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> {
|
||||
write_log!("=================== leader board: scoring update ===================");
|
||||
|
||||
fn race_leaderboard(&mut self, vehicle_scorings: &[VehicleScoringInfoV01]) -> Result<()> {
|
||||
for vehicle_scoring in vehicle_scorings {
|
||||
let driver_name = Self::c_char_to_string(vehicle_scoring.mDriverName);
|
||||
|
||||
|
@ -129,6 +126,30 @@ impl DataReceiver for LeaderBoard {
|
|||
self.gui.enable()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl UiOverlay for LeaderBoard {}
|
||||
|
||||
impl DataReceiver for LeaderBoard {
|
||||
fn scoring_update(
|
||||
&mut self,
|
||||
phase: GamePhase,
|
||||
vehicle_scorings: &[VehicleScoringInfoV01],
|
||||
) -> Result<()> {
|
||||
write_log!("=================== leader board: scoring update ===================");
|
||||
|
||||
match phase {
|
||||
GamePhase::TestDay => self.gui.disable()?,
|
||||
GamePhase::Practice => self.gui.disable()?,
|
||||
GamePhase::Qualifying => self.gui.disable()?,
|
||||
GamePhase::Warmup => self.gui.disable()?,
|
||||
GamePhase::Race => {
|
||||
self.race_leaderboard(vehicle_scorings)?;
|
||||
}
|
||||
}
|
||||
|
||||
write_log!("leader board update finished");
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -4,7 +4,10 @@ use anyhow::Result;
|
|||
use rfactor_sm_reader::{rF2VehicleTelemetry, VehicleScoringInfoV01};
|
||||
use ui::prelude::*;
|
||||
|
||||
use crate::overlay::{rfactor_data::DataReceiver, UiOverlay};
|
||||
use crate::overlay::{
|
||||
rfactor_data::{DataReceiver, GamePhase},
|
||||
UiOverlay,
|
||||
};
|
||||
|
||||
pub struct Pedals {
|
||||
gui: Arc<GuiBuilder>,
|
||||
|
@ -39,7 +42,11 @@ impl Pedals {
|
|||
impl UiOverlay for Pedals {}
|
||||
|
||||
impl DataReceiver for Pedals {
|
||||
fn scoring_update(&mut self, _vehicle_scoring: &[VehicleScoringInfoV01]) -> Result<()> {
|
||||
fn scoring_update(
|
||||
&mut self,
|
||||
_phase: GamePhase,
|
||||
_vehicle_scoring: &[VehicleScoringInfoV01],
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,11 @@ use std::sync::{Arc, Mutex};
|
|||
use super::pipeline::SingleColorPipeline;
|
||||
|
||||
use crate::{
|
||||
overlay::{rendering::Rendering, rfactor_data::DataReceiver, UiOverlay},
|
||||
overlay::{
|
||||
rendering::Rendering,
|
||||
rfactor_data::{DataReceiver, GamePhase},
|
||||
UiOverlay,
|
||||
},
|
||||
write_log,
|
||||
};
|
||||
|
||||
|
@ -296,7 +300,11 @@ impl Radar {
|
|||
impl UiOverlay for Radar {}
|
||||
|
||||
impl DataReceiver for Radar {
|
||||
fn scoring_update(&mut self, _vehicle_scoring: &[VehicleScoringInfoV01]) -> Result<()> {
|
||||
fn scoring_update(
|
||||
&mut self,
|
||||
_phase: GamePhase,
|
||||
_vehicle_scoring: &[VehicleScoringInfoV01],
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@ use anyhow::Result;
|
|||
use rfactor_sm_reader::{rF2VehicleTelemetry, VehicleScoringInfoV01};
|
||||
use ui::prelude::*;
|
||||
|
||||
use crate::overlay::{rfactor_data::DataReceiver, UiOverlay};
|
||||
use crate::overlay::{
|
||||
rfactor_data::{DataReceiver, GamePhase},
|
||||
UiOverlay,
|
||||
};
|
||||
|
||||
pub struct Watermark {
|
||||
_gui: Arc<GuiBuilder>,
|
||||
|
@ -25,7 +28,11 @@ impl Watermark {
|
|||
impl UiOverlay for Watermark {}
|
||||
|
||||
impl DataReceiver for Watermark {
|
||||
fn scoring_update(&mut self, _vehicle_scoring: &[VehicleScoringInfoV01]) -> Result<()> {
|
||||
fn scoring_update(
|
||||
&mut self,
|
||||
_phase: GamePhase,
|
||||
_vehicle_scoring: &[VehicleScoringInfoV01],
|
||||
) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,11 @@ use crate::write_log;
|
|||
use super::UiOverlay;
|
||||
|
||||
pub trait DataReceiver {
|
||||
fn scoring_update(&mut self, vehicle_scoring: &[VehicleScoringInfoV01]) -> Result<()>;
|
||||
fn scoring_update(
|
||||
&mut self,
|
||||
phase: GamePhase,
|
||||
vehicle_scoring: &[VehicleScoringInfoV01],
|
||||
) -> Result<()>;
|
||||
|
||||
fn telemetry_update(
|
||||
&mut self,
|
||||
|
@ -17,6 +21,31 @@ pub trait DataReceiver {
|
|||
) -> Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum GamePhase {
|
||||
TestDay,
|
||||
Practice,
|
||||
Qualifying,
|
||||
Warmup,
|
||||
Race,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for GamePhase {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: i32) -> Result<Self> {
|
||||
Ok(match value {
|
||||
0 => Self::TestDay,
|
||||
1..=4 => Self::Practice,
|
||||
5..=8 => Self::Qualifying,
|
||||
9 => Self::Warmup,
|
||||
10..=13 => Self::Race,
|
||||
|
||||
_ => return Err(anyhow::anyhow!("Failed to parse GamePhase from: {}", value)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RFactorData {
|
||||
// rf2 memory mapped data
|
||||
telemetry_reader: TelemetryReader,
|
||||
|
@ -78,8 +107,12 @@ impl RFactorData {
|
|||
}
|
||||
}
|
||||
|
||||
let phase = GamePhase::try_from(scoring_info.mSession)?;
|
||||
|
||||
for receiver in self.receivers.iter() {
|
||||
receiver.borrow_mut().scoring_update(&vehicle_scorings)?;
|
||||
receiver
|
||||
.borrow_mut()
|
||||
.scoring_update(phase, &vehicle_scorings)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue