diff options
| author | troido <troido@protonmail.com> | 2020-02-14 14:36:32 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-14 14:36:32 +0100 |
| commit | 4a4cdf7d148be0a2a756f323d27c0ee5b7976438 (patch) | |
| tree | 7add0a0d735f93cb1fce6ae4f0c476a0d550a3ee /src/systems/save.rs | |
| parent | 7821febc8ee4c89ca1825054e0baf39eea3a0380 (diff) | |
extract the state to save
Diffstat (limited to 'src/systems/save.rs')
| -rw-r--r-- | src/systems/save.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/systems/save.rs b/src/systems/save.rs new file mode 100644 index 0000000..924533a --- /dev/null +++ b/src/systems/save.rs @@ -0,0 +1,43 @@ + +use std::collections::HashMap; + +use specs::{ + Entities, + ReadStorage, + System, + Join, + Read +}; + +use crate::pos::Pos; + +use crate::components::{ + Position, + Serialise +}; + +use crate::savestate::SaveState; + +const INTERVAL: i32 = 20; + +pub struct Save(pub i32); +impl <'a> System<'a> for Save { + type SystemData = ( + Entities<'a>, + ReadStorage<'a, Position>, + ReadStorage<'a, Serialise>, + ); + + fn run(&mut self, (entities, positions, serialisers): Self::SystemData) { + self.0 -= 1; + if self.0 > 0 { + return + } + self.0 = INTERVAL; + let mut state = SaveState::new(); + for (pos, serialiser) in (&positions, &serialisers).join() { + state.changes.entry(pos.pos).or_insert(Vec::new()).push(serialiser.template.clone()); + } + println!("save {}", state.to_json().to_string()); + } +} |
