forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchat.rs
More file actions
45 lines (38 loc) · 1.11 KB
/
chat.rs
File metadata and controls
45 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::entity::Name;
use crate::game::Game;
use feather_core::text::{Color, TextRoot, Translate};
use fecs::{Entity, World};
/// Event triggered when a chat message is sent out
#[derive(Debug, Clone)]
pub struct ChatEvent {
/// The JSON-formatted message
pub message: String,
/// The position of the message
pub position: ChatPosition,
}
/// Different positions a chat message can be displayed
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChatPosition {
/// Simple message displayed in the chat box
Chat,
/// System message displayed in the chat box
SystemMessage,
/// A text displayed above the hotbar
GameInfo,
}
pub fn on_player_join_broadcast_join_message(game: &mut Game, world: &mut World, player: Entity) {
let message: String = {
let name = world.get::<Name>(player);
TextRoot::from(
Translate::MultiplayerPlayerJoined * vec![name.0.to_string()] * Color::Yellow,
)
.into()
};
game.on_chat(
world,
ChatEvent {
message,
position: ChatPosition::Chat,
},
);
}