You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.4 KiB

use libpso::packet::ship::*;
use networking::serverstate::ClientId;
use crate::{SendShipPacket, Clients};
use entity::gateway::EntityGateway;
pub async fn update_config<EG>(id: ClientId,
update_config: UpdateConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.config.update(&update_config);
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}
pub async fn save_options<EG>(id: ClientId,
save_options: SaveOptions,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.option_flags = save_options.options;
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}
pub async fn keyboard_config<EG>(id: ClientId,
keyboard_config: KeyboardConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.settings.settings.keyboard_config = keyboard_config.keyboard_config;
entity_gateway.save_user_settings(&client.settings).await
})}).await??;
Ok(Vec::new())
}
pub async fn gamepad_config<EG>(id: ClientId,
gamepad_config: GamepadConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.settings.settings.gamepad_config = gamepad_config.gamepad_config;
entity_gateway.save_user_settings(&client.settings).await
})}).await??;
Ok(Vec::new())
}
pub async fn update_tech_menu<EG>(id: ClientId,
update_tech_menu: UpdateTechMenu,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.tech_menu.tech_menu = update_tech_menu.config;
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}