forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.rs
More file actions
25 lines (20 loc) · 701 Bytes
/
time.rs
File metadata and controls
25 lines (20 loc) · 701 Bytes
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
//! Handles world time.
use feather_core::network::packets::TimeUpdate;
use feather_server_types::{Game, Network, PlayerPreJoinEvent};
use fecs::World;
/// System for incrementing time each tick.
#[fecs::system]
pub fn increment_time(game: &mut Game) {
game.time.0 += 1;
}
/// Event handler for sending world time to players.
#[fecs::event_handler]
pub fn on_player_join_send_time(event: &PlayerPreJoinEvent, game: &Game, world: &mut World) {
let network = world.get::<Network>(event.player);
// Send time to player.
let packet = TimeUpdate {
world_age: game.time.world_age() as i64,
time_of_day: game.time.time_of_day() as i64,
};
network.send(packet);
}