bevy/crates/bevy_scene/src/loaded_scenes.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

use crate::{serde::SceneDeserializer, Scene};
use anyhow::Result;
use bevy_asset::AssetLoader;
2020-07-10 08:37:06 +00:00
use bevy_ecs::{FromResources, Resources};
use bevy_property::PropertyTypeRegistry;
2020-06-04 03:08:20 +00:00
use bevy_type_registry::TypeRegistry;
use parking_lot::RwLock;
use serde::de::DeserializeSeed;
use std::{path::Path, sync::Arc};
pub struct SceneLoader {
property_type_registry: Arc<RwLock<PropertyTypeRegistry>>,
}
impl FromResources for SceneLoader {
fn from_resources(resources: &Resources) -> Self {
let type_registry = resources.get::<TypeRegistry>().unwrap();
SceneLoader {
property_type_registry: type_registry.property.clone(),
}
}
}
impl AssetLoader<Scene> for SceneLoader {
fn from_bytes(&self, _asset_path: &Path, bytes: Vec<u8>) -> Result<Scene> {
let registry = self.property_type_registry.read();
let mut deserializer = bevy_ron::de::Deserializer::from_bytes(&bytes)?;
let scene_deserializer = SceneDeserializer {
property_type_registry: &registry,
};
let scene = scene_deserializer.deserialize(&mut deserializer)?;
Ok(scene)
}
2020-07-28 21:24:03 +00:00
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["scn"];
EXTENSIONS
}
}