diff options
Diffstat (limited to 'src/cache')
-rw-r--r-- | src/cache/mod.rs | 3 | ||||
-rw-r--r-- | src/cache/resources.rs | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/cache/mod.rs b/src/cache/mod.rs new file mode 100644 index 0000000..19c3a6f --- /dev/null +++ b/src/cache/mod.rs @@ -0,0 +1,3 @@ +mod resources; +pub use resources::DirworldCache; + diff --git a/src/cache/resources.rs b/src/cache/resources.rs new file mode 100644 index 0000000..6aba61a --- /dev/null +++ b/src/cache/resources.rs @@ -0,0 +1,22 @@ +use std::{collections::HashMap, path::PathBuf}; + +use bevy::prelude::*; + +use crate::{components::DirworldEntity, payload::DirworldEntityPayload}; + +/// Structure containing payload data for cached (non-current) rooms +#[derive(Resource, Default, Debug, Deref, DerefMut)] +pub struct DirworldCache(pub HashMap<PathBuf, DirworldEntityPayload>); + +impl DirworldCache { + /// Stores an entity's payload in the cache, if it exists + pub fn cache_entity(&mut self, dirworld_entity: &DirworldEntity) { + if let Some(payload) = &dirworld_entity.payload { + self.insert(dirworld_entity.path.clone(), payload.clone()); + } + } + + pub fn get_entity_cache(&mut self, path: impl Into<PathBuf>) -> Option<DirworldEntityPayload> { + self.remove(&path.into()) + } +} |