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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#![allow(clippy::panic)]
use crate::*;
use mem6_common::*;
use unwrap::unwrap;
use dodrio::{
builder::text,
bumpalo::{self, Bump},
Node,
};
use typed_html::dodrio;
pub fn on_click_1st_card(
rrc: &mut RootRenderingComponent,
vdom: &dodrio::VdomWeak,
this_click_card_index: usize,
) {
flip_back(rrc);
rrc.game_data.card_index_of_first_click = this_click_card_index;
let msg_id = ackmsgmod::prepare_for_ack_msg_waiting(rrc, vdom);
let msg = WsMessage::MsgClick1stCard {
my_ws_uid: rrc.game_data.my_ws_uid,
players_ws_uid: rrc.game_data.players_ws_uid.to_string(),
card_index_of_first_click: this_click_card_index,
msg_id,
};
ackmsgmod::send_msg_and_write_in_queue(rrc, &msg, msg_id);
divgridcontainermod::play_sound(rrc, this_click_card_index);
}
pub fn flip_back(rrc: &mut RootRenderingComponent) {
for x in &mut rrc.game_data.card_grid_data {
if let CardStatusCardFace::UpTemporary = x.status {
x.status = CardStatusCardFace::Down;
}
}
rrc.game_data.card_index_of_first_click = 0;
rrc.game_data.card_index_of_second_click = 0;
}
pub fn on_msg_click_1st_card(
rrc: &mut RootRenderingComponent,
vdom: &dodrio::VdomWeak,
msg_sender_ws_uid: usize,
card_index_of_first_click: usize,
msg_id: usize,
) {
flip_back(rrc);
ackmsgmod::send_ack(rrc, msg_sender_ws_uid, msg_id, MsgAckKind::MsgClick1stCard);
if rrc.game_data.my_player_number == 1 && GameStatus::Status1stCard != rrc.game_data.game_status
{
logmod::debug_write("CONFLICT on_msg_click_1st_card");
on_click_1st_card(rrc, vdom, rrc.game_data.card_index_of_first_click);
status2ndcardmod::on_click_2nd_card(rrc, vdom, card_index_of_first_click)
} else {
rrc.game_data.card_index_of_first_click = card_index_of_first_click;
update_on_1st_card(rrc);
}
}
pub fn on_msg_ack_click_1st_card(
rrc: &mut RootRenderingComponent,
player_ws_uid: usize,
msg_id: usize,
) {
if ackmsgmod::remove_ack_msg_from_queue(rrc, player_ws_uid, msg_id) {
update_on_1st_card(rrc);
}
}
pub fn update_on_1st_card(rrc: &mut RootRenderingComponent) {
logmod::debug_write("update_on_1st_card");
unwrap!(rrc
.game_data
.card_grid_data
.get_mut(rrc.game_data.card_index_of_first_click))
.status = CardStatusCardFace::UpTemporary;
rrc.game_data.game_status = GameStatus::Status2ndCard;
}
#[allow(clippy::integer_arithmetic)]
pub fn div_on_1st_card<'a>(rrc: &RootRenderingComponent, bump: &'a Bump) -> Node<'a> {
if rrc.game_data.my_player_number == rrc.game_data.player_turn {
dodrio!(bump,
<div >
<h2 class="h2_must_do_something">
{vec![text(bumpalo::format!(in bump, "Play {}",
unwrap!(rrc.game_data.players.get(rrc.game_data.player_turn-1)).nickname)
.into_bump_str())]}
</h2>
</div>
)
} else {
dodrio!(bump,
<h2 class="h2_user_must_wait">
{vec![text(bumpalo::format!(in bump, "Wait for {}",
unwrap!(rrc.game_data.players.get(rrc.game_data.player_turn-1)).nickname
).into_bump_str())]}
</h2>
)
}
}