2020-05-11 10:06:53 +00:00
|
|
|
use crate::{
|
|
|
|
persistence::stats,
|
|
|
|
sys::{SysScheduler, SysTimer},
|
|
|
|
};
|
2020-04-25 13:41:27 +00:00
|
|
|
use common::comp::{Player, Stats};
|
|
|
|
use specs::{Join, ReadStorage, System, Write};
|
|
|
|
|
|
|
|
pub struct Sys;
|
|
|
|
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
|
|
type SystemData = (
|
|
|
|
ReadStorage<'a, Player>,
|
|
|
|
ReadStorage<'a, Stats>,
|
|
|
|
Write<'a, SysScheduler<Self>>,
|
2020-05-11 10:06:53 +00:00
|
|
|
Write<'a, SysTimer<Self>>,
|
2020-04-25 13:41:27 +00:00
|
|
|
);
|
|
|
|
|
2020-05-11 10:06:53 +00:00
|
|
|
fn run(&mut self, (players, player_stats, mut scheduler, mut timer): Self::SystemData) {
|
2020-04-25 13:41:27 +00:00
|
|
|
if scheduler.should_run() {
|
2020-05-11 10:06:53 +00:00
|
|
|
timer.start();
|
2020-05-10 16:28:11 +00:00
|
|
|
|
2020-05-11 10:06:53 +00:00
|
|
|
stats::update(
|
|
|
|
(&players, &player_stats)
|
|
|
|
.join()
|
|
|
|
.filter_map(|(player, stats)| player.character_id.map(|id| (id, stats))),
|
|
|
|
);
|
|
|
|
|
|
|
|
timer.end();
|
2020-04-25 13:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|