veloren/server/src/sys/persistence/stats.rs

34 lines
872 B
Rust
Raw Normal View History

use crate::{
persistence::stats,
sys::{SysScheduler, SysTimer},
};
use common::comp::{Player, Stats};
use specs::{Join, ReadExpect, ReadStorage, System, Write};
pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
ReadStorage<'a, Player>,
ReadStorage<'a, Stats>,
2020-05-15 20:03:51 +00:00
ReadExpect<'a, stats::Updater>,
Write<'a, SysScheduler<Self>>,
Write<'a, SysTimer<Self>>,
);
fn run(
&mut self,
2020-05-15 20:03:51 +00:00
(players, player_stats, updater, mut scheduler, mut timer): Self::SystemData,
) {
if scheduler.should_run() {
timer.start();
2020-05-15 20:03:51 +00:00
updater.batch_update(
(&players, &player_stats)
.join()
.filter_map(|(player, stats)| player.character_id.map(|id| (id, stats))),
);
timer.end();
}
}
}