diff options
author | 2024-12-24 00:54:31 -0500 | |
---|---|---|
committer | 2024-12-24 00:54:31 -0500 | |
commit | a1e9304dc31980703446bdb33246e314bafd3b15 (patch) | |
tree | 47c9dd32398a6d84050f39fac17d52d0a5d9ad4e /src/cache/resources.rs | |
parent | f3a7c2139cb3f9074d28dd99fa1bbd10d752547e (diff) |
Switched to bevy_mod_scripting, bevy 0.15 updatev0.4.0
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()) + } +} |