diff options
Diffstat (limited to 'src/cache/resources.rs')
-rw-r--r-- | src/cache/resources.rs | 22 |
1 files changed, 22 insertions, 0 deletions
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()) + } +} |