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
46
47
48
49
50
51
52
53
54
55
#![allow(clippy::panic)]
use crate::*;
use mem6_common::*;
use unwrap::unwrap;
pub fn on_load_joined(rrc: &mut RootRenderingComponent) {
rrc.game_data.game_status = GameStatus::StatusJoined;
let _group_id = format!("{}", unwrap!(rrc.game_data.players.get(0)).ws_uid);
logmod::debug_write(&format!(
"StatusJoined send {}",
rrc.game_data.players_ws_uid
));
websocketcommunicationmod::ws_send_msg(
&rrc.game_data.ws,
&WsMessage::MsgJoin {
my_ws_uid: rrc.game_data.my_ws_uid,
players_ws_uid: rrc.game_data.players_ws_uid.to_string(),
my_nickname: rrc.game_data.my_nickname.clone(),
},
);
}
pub fn on_msg_joined(rrc: &mut RootRenderingComponent, his_ws_uid: usize, his_nickname: String) {
if rrc.game_data.my_player_number == 1 {
let mut ws_uid_exists = false;
for x in &rrc.game_data.players {
if x.ws_uid == his_ws_uid {
ws_uid_exists = true;
break;
}
}
if !ws_uid_exists {
rrc.game_data.players.push(Player {
ws_uid: his_ws_uid,
nickname: his_nickname,
points: 0,
});
rrc.game_data.players_ws_uid =
gamedatamod::prepare_players_ws_uid(&rrc.game_data.players);
}
}
}