forked from valence-rs/valence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.rs
164 lines (128 loc) · 3.63 KB
/
weather.rs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use crate::protocol::packets::play::GameStateChangeS2c;
use crate::testing::*;
use crate::weather::{Rain, Thunder, WeatherBundle};
#[test]
fn test_client_initialization_on_join() {
let ScenarioSingleClient {
mut app,
client: _,
mut helper,
layer: _,
} = prepare(true);
app.update();
// Check if two game state change packets were sent, one for rain and one for
// thunder
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(2);
}
#[test]
fn test_chunk_layer_initialization_on_join() {
let ScenarioSingleClient {
mut app,
client: _,
mut helper,
layer: _,
} = prepare(false);
app.update();
// Check if two game state change packets were sent, one for rain and one for
// thunder
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(2);
}
#[test]
fn test_client_rain_change() {
let ScenarioSingleClient {
mut app,
client,
mut helper,
layer: _,
} = prepare(true);
app.update();
helper.clear_received();
// Change the rain value
let mut rain = app.world.get_mut::<Rain>(client).unwrap();
rain.0 = 1.0;
app.update();
// Check if a game state change packet was sent
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(1);
}
#[test]
fn test_client_thunder_change() {
let ScenarioSingleClient {
mut app,
client,
mut helper,
layer: _,
} = prepare(true);
app.update();
helper.clear_received();
// Change the thunder value
let mut thunder = app.world.get_mut::<Thunder>(client).unwrap();
thunder.0 = 1.0;
app.update();
// Check if a game state change packet was sent
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(1);
}
#[test]
fn test_chunk_layer_rain_change() {
let ScenarioSingleClient {
mut app,
client: _,
mut helper,
layer,
} = prepare(false);
app.update();
helper.clear_received();
// Change the rain value
let mut rain = app.world.get_mut::<Rain>(layer).unwrap();
rain.0 = 1.0;
app.update();
// Check if a game state change packet was sent
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(1);
}
#[test]
fn test_chunk_layer_thunder_change() {
let ScenarioSingleClient {
mut app,
client: _,
mut helper,
layer,
} = prepare(false);
app.update();
helper.clear_received();
// Change the thunder value
let mut thunder = app.world.get_mut::<Thunder>(layer).unwrap();
thunder.0 = 1.0;
app.update();
// Check if a game state change packet was sent
let frames = helper.collect_received();
frames.assert_count::<GameStateChangeS2c>(1);
}
fn prepare(client_weather: bool) -> ScenarioSingleClient {
let mut s = ScenarioSingleClient::new();
// Process a tick to get past the "on join" logic.
s.app.update();
// Add weather to either the client or the chunk layer depending on the
// parameter
if client_weather {
add_weather_to_client(&mut s);
} else {
add_weather_to_chunk_layer(&mut s);
}
s
}
fn add_weather_to_client(s: &mut ScenarioSingleClient) {
s.app.world.entity_mut(s.client).insert(WeatherBundle {
rain: Rain(0.5),
thunder: Thunder(0.5),
});
}
fn add_weather_to_chunk_layer(s: &mut ScenarioSingleClient) {
s.app.world.entity_mut(s.layer).insert(WeatherBundle {
rain: Rain(0.5),
thunder: Thunder(0.5),
});
}