Browse Source

start setting up keyboard config stuff

pull/104/head
andy 4 years ago
parent
commit
0b8aef3b8c
  1. 26
      src/entity/character.rs
  2. 13
      src/ship/packet/handler/settings.rs
  3. 2
      src/ship/ship.rs

26
src/entity/character.rs

@ -2,8 +2,8 @@ use std::convert::{From, Into};
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use libpso::packet::ship::{UpdateConfig, WriteInfoboard};
use libpso::character::character::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU};
use libpso::packet::ship::{UpdateConfig, WriteInfoboard, KeyboardConfig};
use libpso::character::character::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU, DEFAULT_KEYBOARD_CONFIG1};
use crate::entity::item::tech::Technique;
use crate::entity::account::UserAccountId;
@ -264,6 +264,28 @@ pub struct CharacterMaterials {
pub tp: u32,
}
#[derive(Clone)]
pub struct CharacterKeyboardConfig {
pub keyboard: [u8; 0x16C],
}
impl CharacterKeyboardConfig {
fn new() -> CharacterKeyboardConfig {
CharacterKeyboardConfig {
keyboard: DEFAULT_KEYBOARD_CONFIG1,
}
}
pub fn update(&mut self, new_config: &KeyboardConfig) {
self.keyboard = new_config.keyboard_config;
}
pub fn as_bytes(&self) -> [u8; 0x16C] {
self.keyboard
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default, derive_more::Display)]
pub struct CharacterEntityId(pub u32);

13
src/ship/packet/handler/settings.rs

@ -19,9 +19,20 @@ pub async fn save_options<EG: EntityGateway>(id: ClientId,
clients: &mut Clients,
entity_gateway: &mut EG)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
// // TODO: don't unwrap?
// TODO: don't unwrap?
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
client.character.option_flags = save_options.options;
entity_gateway.save_character(&client.character).await.unwrap();
Box::new(None.into_iter())
}
// pub async fn keyboard_config<EG: EntityGateway>(id: ClientId,
// keyboard_config: &KeyboardConfig,
// clients: &mut Clients,
// entity_gateway: &mut EG)
// -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
// let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
// client.character.option_flags = save_options.options;
// entity_gateway.save_character(&client.character).await.unwrap();
// Box::new(None.into_iter())
// }

2
src/ship/ship.rs

@ -115,6 +115,7 @@ pub enum RecvShipPacket {
RequestShipBlockList(RequestShipBlockList),
ItemsToTrade(ItemsToTrade),
TradeConfirmed(TradeConfirmed),
KeyboardConfig(KeyboardConfig),
}
impl RecvServerPacket for RecvShipPacket {
@ -156,6 +157,7 @@ impl RecvServerPacket for RecvShipPacket {
0xD2 => Ok(RecvShipPacket::TradeConfirmed(TradeConfirmed::from_bytes(data)?)),
0xE7 => Ok(RecvShipPacket::FullCharacterData(Box::new(FullCharacterData::from_bytes(data)?))),
0x1ED => Ok(RecvShipPacket::SaveOptions(SaveOptions::from_bytes(data)?)),
0x4ED => Ok(RecvShipPacket::KeyboardConfig(KeyboardConfig::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
}
}

Loading…
Cancel
Save