2020-05-11 10:06:53 +00:00
|
|
|
use crate::{
|
|
|
|
persistence::stats,
|
2020-05-12 23:58:15 +00:00
|
|
|
settings::PersistenceDBDir,
|
2020-05-11 10:06:53 +00:00
|
|
|
sys::{SysScheduler, SysTimer},
|
|
|
|
};
|
2020-04-25 13:41:27 +00:00
|
|
|
use common::comp::{Player, Stats};
|
2020-05-12 23:58:15 +00:00
|
|
|
use specs::{Join, ReadExpect, ReadStorage, System, Write};
|
2020-04-25 13:41:27 +00:00
|
|
|
|
|
|
|
pub struct Sys;
|
|
|
|
|
|
|
|
impl<'a> System<'a> for Sys {
|
|
|
|
type SystemData = (
|
|
|
|
ReadStorage<'a, Player>,
|
|
|
|
ReadStorage<'a, Stats>,
|
2020-05-12 23:58:15 +00:00
|
|
|
ReadExpect<'a, PersistenceDBDir>,
|
2020-04-25 13:41:27 +00:00
|
|
|
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-12 23:58:15 +00:00
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
(players, player_stats, persistence_db_dir, 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-13 12:08:26 +00:00
|
|
|
stats::batch_update(
|
2020-05-11 10:06:53 +00:00
|
|
|
(&players, &player_stats)
|
|
|
|
.join()
|
|
|
|
.filter_map(|(player, stats)| player.character_id.map(|id| (id, stats))),
|
2020-05-12 23:58:15 +00:00
|
|
|
&persistence_db_dir.0,
|
2020-05-11 10:06:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
timer.end();
|
2020-04-25 13:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|