Skip to content

Commit 050fea0

Browse files
Basic Chat impl (#23)
* Update add plugin script * Add boilerplate for chat * Implement data types, server side message receiving * Update serverside impl * Remove chat systems * Create client chat plugin * Work on client impl * Fix server * Update client impl * wip * Update client system impl * Update colors * Update system * Refactor colors * Fix linter * Attempt send messages * Update system frequency * Introduce input element * Implement kbd input * Update chat impl * Implement space appending * Implement blank messages * Attempt impl timestamp * Implement chrono timestamps * Update chat state * Update chat events * Refactor * Update mods * Refactor event * Fix chat systems * Fix linter * Refactor * Refactor server messages * Introduce server messages * Fix linter * Update message fmt * Fix linter * Refactor * Attempt refactor styles? * Refactor client * wip * wip * Reformat / Refactor (gud) * Fix linter * Fix chat state * Final touches * Rename * Rename * Rename * Rename * Fix linter
1 parent 33465e0 commit 050fea0

File tree

23 files changed

+722
-96
lines changed

23 files changed

+722
-96
lines changed

Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rand = "0.8.5"
1818
renet = "0.0.15"
1919
serde = { version = "1.0.203", features = ["derive"] }
2020
serde-big-array = "0.5.1"
21+
chrono = "0.4.38"
2122

2223
[profile.dev.package."*"]
2324
opt-level = 3

bin/add_plugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if [ "$TARGET" != "server" ] && [ "$TARGET" != "client" ]; then
6161
exit 1
6262
fi
6363

64-
PLUGIN_DIR="./$TARGET/$(pascal_to_snake_case $PLUGIN_NAME)"
64+
PLUGIN_DIR="./src/$TARGET/$(pascal_to_snake_case $PLUGIN_NAME)"
6565

6666
# Create the directory structure
6767
mkdir -p $PLUGIN_DIR || { echo "Error: Failed to create directory $PLUGIN_DIR"; exit 1; }

src/client/chat/components.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use crate::prelude::*;
2+
3+
#[derive(Component)]
4+
pub struct ChatMessageContainer {
5+
pub focused: bool,
6+
}
7+
8+
#[derive(Component)]
9+
pub struct ChatMessageInputElement {
10+
pub focused: bool,
11+
}
12+
13+
#[derive(Component)]
14+
pub struct ChatMessageElement;

src/client/chat/events.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::prelude::*;
2+
3+
#[derive(Event)]
4+
pub struct ChatSyncEvent(pub Vec<lib::ChatMessage>);
5+
6+
#[derive(Event)]
7+
pub struct SingleChatSendEvent(pub lib::ChatMessage);
8+
9+
#[derive(Event)]
10+
pub struct ChatMessageSendEvent(pub String);
11+
12+
pub enum FocusState {
13+
Focus,
14+
Unfocus,
15+
}
16+
17+
#[derive(Event)]
18+
pub struct ChatFocusStateChangeEvent {
19+
pub state: FocusState,
20+
}

src/client/chat/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::prelude::*;
2+
3+
pub mod components;
4+
pub mod events;
5+
pub mod resources;
6+
pub mod systems;
7+
8+
pub struct ChatPlugin;
9+
10+
impl Plugin for ChatPlugin {
11+
fn build(&self, app: &mut App) {
12+
info!("Building ChatPlugin");
13+
14+
app.add_systems(Startup, systems::setup_chat_container);
15+
app.add_systems(
16+
Update,
17+
(
18+
systems::process_chat_input_system,
19+
systems::handle_chat_focus_player_controller_events,
20+
systems::handle_window_focus_events,
21+
systems::focus_chat_input_system,
22+
systems::send_messages_system,
23+
systems::handle_focus_events,
24+
systems::handle_chat_message_sync_event,
25+
systems::add_message_to_chat_container_system,
26+
),
27+
);
28+
app.insert_resource(resources::ChatHistory::default());
29+
app.insert_resource(resources::ChatState::default());
30+
app.add_event::<events::ChatSyncEvent>();
31+
app.add_event::<events::ChatFocusStateChangeEvent>();
32+
app.add_event::<events::ChatMessageSendEvent>();
33+
app.add_event::<events::SingleChatSendEvent>();
34+
}
35+
}

src/client/chat/resources.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::prelude::*;
2+
3+
#[derive(Resource, Default, Debug)]
4+
pub struct ChatHistory {
5+
pub messages: Vec<lib::ChatMessage>,
6+
}
7+
8+
#[derive(Resource, Default)]
9+
pub struct ChatState {
10+
pub just_focused: bool,
11+
}

0 commit comments

Comments
 (0)