rename ChatManager to ChatHistory

This commit is contained in:
griffi-gh 2024-04-25 17:49:12 +02:00
parent 907a5845fa
commit e373aa758c
4 changed files with 10 additions and 10 deletions

View file

@ -19,11 +19,11 @@ pub enum ChatMessage {
}
#[derive(Unique, Default)]
pub struct ChatManager {
pub struct ChatHistory {
pub messages: Vec<ChatMessage>,
}
impl ChatManager {
impl ChatHistory {
pub fn add_message(&mut self, message: ChatMessage) {
self.messages.push(message);
}
@ -52,7 +52,7 @@ impl ChatManager {
pub fn init_chat_manager(
storages: AllStoragesView,
) {
let mut chat_manager = ChatManager::default();
let mut chat_manager = ChatHistory::default();
chat_manager.add_system_message("Welcome to Kubi! Chat messages will appear here".to_string());
storages.add_unique(chat_manager);
}

View file

@ -6,7 +6,7 @@ use kubi_shared::networking::{
channels::Channel,
};
use rand::prelude::*;
use crate::{chat::ChatManager, player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}};
use crate::{chat::ChatHistory, player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}};
use super::{UdpClient, NetworkEvent};
const USERNAME_BANK: &[&str] = &[
@ -96,7 +96,7 @@ pub fn check_server_hello_response(
log::info!("Joined the server!");
// Send chat message
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
chat.add_player_join(client_id, username);
}

View file

@ -10,7 +10,7 @@ use kubi_shared::{
},
};
use crate::{
chat::ChatManager,
chat::ChatHistory,
events::player_actions::PlayerActionEvent,
player::spawn_remote_player_multiplayer,
};
@ -97,7 +97,7 @@ pub fn receive_player_connect_events(
for message in messages {
let ServerToClientMessage::PlayerConnected { init } = message else { unreachable!() };
log::info!("player connected: {} (id {})", init.username, init.client_id);
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
chat.add_player_join(init.client_id, init.username.clone());
drop(chat);
spawn_remote_player_multiplayer(&mut storages, init);
@ -132,7 +132,7 @@ pub fn receive_player_disconnect_events(
};
let username = storages.get::<&Username>(ent_id).unwrap();
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
let mut chat = storages.borrow::<UniqueViewMut<ChatHistory>>().unwrap();
chat.add_player_leave(id, username.0.to_string());
drop(chat);

View file

@ -1,11 +1,11 @@
use hui::{color, element::{container::Container, text::Text, UiElementExt}, layout::Alignment, size};
use shipyard::{NonSendSync, UniqueView, UniqueViewMut};
use crate::{chat::{ChatManager, ChatMessage}, hui_integration::UiState, rendering::WindowSize};
use crate::{chat::{ChatHistory, ChatMessage}, hui_integration::UiState, rendering::WindowSize};
pub fn render_chat(
mut hui: NonSendSync<UniqueViewMut<UiState>>,
size: UniqueView<WindowSize>,
chat: UniqueView<ChatManager>,
chat: UniqueView<ChatHistory>,
) {
let messages = chat.get_messages();
if messages.is_empty() { return }