pub mod types;
pub use super::in_game::URL;
use crate::in_game::{self, GameClient};
use crate::replay::types::{Playback, RecordingState, Render, Sequence};
use std::borrow::Borrow;
use std::collections::HashMap;
use std::future::Future;
#[allow(clippy::module_name_repetitions)]
pub trait ReplayClient: in_game::GameClient {
fn game(&self) -> impl Future<Output = Result<types::Game, Self::Error>> + Send {
self.replay("/replay/game", "GET", None::<()>)
}
fn get_particles(
&self,
) -> impl Future<Output = Result<HashMap<String, bool>, Self::Error>> + Send {
self.replay("/replay/particles", "GET", None::<()>)
}
fn post_particles(
&self,
body: impl Borrow<HashMap<String, bool>> + Send,
) -> impl Future<Output = Result<HashMap<String, bool>, Self::Error>> + Send {
async move {
self.replay("/replay/particles", "POST", Some(body.borrow()))
.await
}
}
fn get_playback(&self) -> impl Future<Output = Result<Playback, Self::Error>> + Send {
self.replay("/replay/playback", "GET", None::<()>)
}
fn post_playback(
&self,
body: impl Borrow<Playback> + Send,
) -> impl Future<Output = Result<Playback, Self::Error>> + Send {
async move {
self.replay("/replay/playback", "POST", Some(body.borrow()))
.await
}
}
fn get_recording(&self) -> impl Future<Output = Result<RecordingState, Self::Error>> + Send {
self.replay("/replay/recording", "GET", None::<()>)
}
fn post_recording(
&self,
body: impl Borrow<RecordingState> + Send,
) -> impl Future<Output = Result<RecordingState, Self::Error>> + Send {
async move {
self.replay("/replay/recording", "POST", Some(body.borrow()))
.await
}
}
fn get_render(&self) -> impl Future<Output = Result<Render, Self::Error>> + Send {
self.replay("/replay/render", "GET", None::<()>)
}
fn post_render(
&self,
body: impl Borrow<Render> + Send,
) -> impl Future<Output = Result<Render, Self::Error>> + Send {
async move {
self.replay("/replay/render", "POST", Some(body.borrow()))
.await
}
}
fn get_sequence(&self) -> impl Future<Output = Result<Sequence, Self::Error>> + Send {
self.replay("/replay/sequence", "GET", None::<()>)
}
fn post_sequence(
&self,
body: impl Borrow<Sequence> + Send,
) -> impl Future<Output = Result<Sequence, Self::Error>> + Send {
async move {
self.replay("/replay/sequence", "POST", Some(body.borrow()))
.await
}
}
fn reset_sequence(&self) -> impl Future<Output = Result<Sequence, Self::Error>> + Send {
self.replay("/replay/sequence", "POST", Some(None::<Sequence>))
}
}
impl<T> ReplayClient for T where T: GameClient {}