blob: 6aba61a685c9ac2d65c76469074998aa0aa267e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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())
}
}
|