space-game-tm/server/src/main.rs

45 lines
1.3 KiB
Rust

use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
use libspace::datetime::DateTime;
// TODO: Workout a proper TPS for the server.
pub const TICKS_PER_SECOND: u32 = 1;
fn main() {
App::new()
.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / TICKS_PER_SECOND as f64,
)))
.insert_resource(DateTime::default())
.add_plugins(MinimalPlugins)
.add_system(tick_system)
.run();
}
fn tick_system(mut state: ResMut<DateTime>) {
// This is an example time system
// TODO: Work out a proper time system for the game
if state.second % TICKS_PER_SECOND == 0 {
state.second = 0;
state.minute += 1;
if state.minute % 60 == 0 {
state.minute = 0;
state.hour += 1;
if state.hour % 24 == 0 {
state.hour = 0;
state.day += 1;
if state.day % 30 == 0 {
state.day = 0;
state.month += 1;
if state.month % 12 == 0 {
state.month = 0;
state.year += 1;
}
}
}
}
}
// }
state.second += 1;
println!("{}", state.format());
}