use fmod_sys::*;
use lanyard::{Utf8CStr, Utf8CString};
use std::{
ffi::{c_char, c_float, c_int},
mem::MaybeUninit,
};
use crate::{FmodResultExt, Result};
use crate::{
get_string,
studio::{CommandInfo, CommandReplay, System},
};
impl CommandReplay {
pub fn set_bank_path(&self, path: &Utf8CStr) -> Result<()> {
unsafe {
FMOD_Studio_CommandReplay_SetBankPath(self.inner.as_ptr(), path.as_ptr()).to_result()
}
}
pub fn command_at_time(&self, time: c_float) -> Result<c_int> {
let mut index = 0;
unsafe {
FMOD_Studio_CommandReplay_GetCommandAtTime(self.inner.as_ptr(), time, &raw mut index)
.to_result()?;
}
Ok(index)
}
pub fn get_command_count(&self) -> Result<c_int> {
let mut count = 0;
unsafe {
FMOD_Studio_CommandReplay_GetCommandCount(self.inner.as_ptr(), &raw mut count)
.to_result()?;
}
Ok(count)
}
pub fn get_command_info(&self, index: c_int) -> Result<CommandInfo> {
let mut info = MaybeUninit::zeroed();
unsafe {
FMOD_Studio_CommandReplay_GetCommandInfo(self.inner.as_ptr(), index, info.as_mut_ptr())
.to_result()?;
let info = CommandInfo::from_ffi(info.assume_init());
Ok(info)
}
}
pub fn get_command_string(&self, index: c_int) -> Result<Utf8CString> {
let string = get_string(|buffer| unsafe {
FMOD_Studio_CommandReplay_GetCommandString(
self.inner.as_ptr(),
index,
buffer.as_mut_ptr().cast::<c_char>(),
buffer.len() as c_int,
)
})?;
Ok(string)
}
pub fn get_length(&self) -> Result<c_float> {
let mut length = 0.0;
unsafe {
FMOD_Studio_CommandReplay_GetLength(self.inner.as_ptr(), &raw mut length)
.to_result()?;
}
Ok(length)
}
pub fn get_system(&self) -> Result<System> {
let mut system = std::ptr::null_mut();
unsafe {
FMOD_Studio_CommandReplay_GetSystem(self.inner.as_ptr(), &raw mut system)
.to_result()?;
Ok(System::from_ffi(system))
}
}
pub fn is_valid(&self) -> bool {
unsafe { FMOD_Studio_CommandReplay_IsValid(self.inner.as_ptr()).into() }
}
}