Skip to content

Commit f11ae5d

Browse files
feat: add flight functions (#27)
This adds three functions: - `load_flight` - `SimConnect_FlightLoad` - `save_flight` - `SimConnect_FlightSave` - `load_flight_plan` - `SimConnect_FlightPlanLoad` The functions are documented here https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/SimConnect_API_Reference.htm#:~:text=AI%20controlled%20aircraft.-,Flights,-Function --------- Co-authored-by: Pascal Störzbach <[email protected]>
1 parent 599c75c commit f11ae5d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

msfs/src/sim_connect.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,61 @@ impl<'a> SimConnect<'a> {
534534
}
535535
Ok(())
536536
}
537+
538+
/// Load a .FLT file from disk
539+
pub fn load_flight(&mut self, flight_file_path: &str) -> Result<()> {
540+
let flight_file_path = std::ffi::CString::new(flight_file_path).unwrap();
541+
542+
unsafe {
543+
map_err(sys::SimConnect_FlightLoad(
544+
self.handle,
545+
flight_file_path.as_ptr(),
546+
))?;
547+
}
548+
Ok(())
549+
}
550+
551+
/// Save the current sim state to a .FLT file
552+
pub fn save_flight(
553+
&mut self,
554+
flight_file_path: &str,
555+
title: Option<&str>,
556+
description: Option<&str>,
557+
) -> Result<()> {
558+
let flight_file_path = std::ffi::CString::new(flight_file_path).unwrap();
559+
let title = title.map(|x| std::ffi::CString::new(x).unwrap());
560+
let description = description.map(|x| std::ffi::CString::new(x).unwrap());
561+
562+
unsafe {
563+
map_err(sys::SimConnect_FlightSave(
564+
self.handle,
565+
flight_file_path.as_ptr(),
566+
title
567+
.as_ref()
568+
.map(|x| x.as_ptr())
569+
.unwrap_or(std::ptr::null()),
570+
description
571+
.as_ref()
572+
.map(|x| x.as_ptr())
573+
.unwrap_or(std::ptr::null()),
574+
0,
575+
))?;
576+
}
577+
Ok(())
578+
}
579+
580+
/// Load a .PLN file from disk
581+
pub fn load_flight_plan(&mut self, flight_plan_file_path: &str) -> Result<()> {
582+
let flight_plan_file_path = std::ffi::CString::new(flight_plan_file_path).unwrap();
583+
584+
unsafe {
585+
map_err(sys::SimConnect_FlightPlanLoad(
586+
self.handle,
587+
flight_plan_file_path.as_ptr(),
588+
))?;
589+
}
590+
Ok(())
591+
}
537592
}
538593

539594
impl Drop for SimConnect<'_> {

0 commit comments

Comments
 (0)