Fix social list having incorrect player count

This commit is contained in:
scott-c 2020-05-24 17:20:54 +08:00
parent c23183b1ca
commit 136bf271b8
5 changed files with 42 additions and 16 deletions

View File

@ -746,6 +746,23 @@ impl Client {
);
}
},
ServerMsg::PlayerListUpdate(PlayerListUpdate::SelectedCharacter(
uid,
char_info,
)) => {
warn!(
"ServerMsg::PlayerListUpdate PlayerListUpdate::LevelChange not \
implemented: {} {:?}",
uid, char_info
);
},
ServerMsg::PlayerListUpdate(PlayerListUpdate::LevelChange(uid, next_level)) => {
warn!(
"ServerMsg::PlayerListUpdate PlayerListUpdate::LevelChange not \
implemented: {} {}",
uid, next_level
);
},
ServerMsg::PlayerListUpdate(PlayerListUpdate::Remove(uid)) => {
if self.player_list.remove(&uid).is_none() {
warn!(

View File

@ -7,8 +7,8 @@ pub use self::{
client::ClientMsg,
ecs_packet::EcsCompPacket,
server::{
Notification, PlayerInfo, PlayerListUpdate, RegisterError, RequestStateError, ServerInfo,
ServerMsg,
CharacterInfo, Notification, PlayerInfo, PlayerListUpdate, RegisterError,
RequestStateError, ServerInfo, ServerMsg,
},
};

View File

@ -22,6 +22,8 @@ pub struct ServerInfo {
pub enum PlayerListUpdate {
Init(HashMap<u64, PlayerInfo>),
Add(u64, PlayerInfo),
SelectedCharacter(u64, CharacterInfo),
LevelChange(u64, u32),
Remove(u64),
Alias(u64, String),
}
@ -29,8 +31,13 @@ pub enum PlayerListUpdate {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PlayerInfo {
pub player_alias: String,
pub character_name: String,
pub character_level: u32,
pub character: Option<CharacterInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CharacterInfo {
pub name: String,
pub level: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]

View File

@ -10,8 +10,8 @@ use common::{
},
event::{EventBus, ServerEvent},
msg::{
validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, PlayerInfo,
PlayerListUpdate, RequestStateError, ServerMsg, MAX_BYTES_CHAT_MSG,
validate_chat_msg, CharacterInfo, ChatMsgValidationError, ClientMsg, ClientState,
PlayerInfo, PlayerListUpdate, RequestStateError, ServerMsg, MAX_BYTES_CHAT_MSG,
},
state::{BlockChange, Time},
sync::Uid,
@ -88,8 +88,11 @@ impl<'a> System<'a> for Sys {
.map(|(uid, player, stats)| {
((*uid).into(), PlayerInfo {
player_alias: player.alias.clone(),
character_name: stats.name.clone(),
character_level: stats.level.level(),
// TODO: player might not have a character selected
character: Some(CharacterInfo {
name: stats.name.clone(),
level: stats.level.level(),
}),
})
})
.collect::<HashMap<_, _>>();
@ -388,14 +391,11 @@ impl<'a> System<'a> for Sys {
// Handle new players.
// Tell all clients to add them to the player list.
for entity in new_players {
if let (Some(uid), Some(player), Some(stats)) =
(uids.get(entity), players.get(entity), stats.get(entity))
{
if let (Some(uid), Some(player)) = (uids.get(entity), players.get(entity)) {
let msg =
ServerMsg::PlayerListUpdate(PlayerListUpdate::Add((*uid).into(), PlayerInfo {
player_alias: player.alias.clone(),
character_name: stats.name.clone(),
character_level: stats.level.level(), // TODO: stats.level.amount,
character: None, // new players will be on character select.
}));
for client in (&mut clients).join().filter(|c| c.is_registered()) {
client.notify(msg.clone())

View File

@ -194,10 +194,12 @@ impl<'a> Widget for Social<'a> {
.set(ids.online_title, ui);
for (i, (_, player_info)) in self.client.player_list.iter().enumerate() {
Text::new(&format!(
"[{}] {} Lvl {}",
"[{}] {}",
player_info.player_alias,
player_info.character_name,
player_info.character_level
match &player_info.character {
Some(character) => format!("{} Lvl {}", &character.name, &character.level),
None => "<None>".to_string(), // character select or spectating
}
))
.down(3.0)
.font_size(self.fonts.cyri.scale(15))