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
use crate::*;
use unwrap::unwrap;
use dodrio::{Node, Render, RenderContext};
use web_sys::WebSocket;
pub struct RootRenderingComponent {
pub local_route: String,
pub html_template: String,
pub game_data: gamedatamod::GameData,
}
impl RootRenderingComponent {
pub fn new(ws: WebSocket, my_ws_uid: usize) -> Self {
let game_data = gamedatamod::GameData::new(ws, my_ws_uid);
RootRenderingComponent {
local_route: "".to_owned(),
html_template: "".to_owned(),
game_data,
}
}
pub fn reset_for_play_again(&mut self) {
self.game_data.card_index_of_first_click = 0;
self.game_data.card_index_of_second_click = 0;
for x in &mut self.game_data.players {
x.points = 0;
}
}
}
impl Render for RootRenderingComponent {
fn render<'a>(&self, cx: &mut RenderContext<'a>) -> Node<'a> {
let bump = cx.bump;
if self.html_template.is_empty() {
htmltemplatemod::empty_div(cx)
} else {
unwrap!(htmltemplatemod::get_root_element(
self,
bump,
&self.html_template,
htmltemplatemod::HtmlOrSvg::Html
))
}
}
}