use nightshade::ecs::scene::commands::save_scene_binary_to_bytes;
use nightshade::ecs::scene::{
SceneError, SceneSettings, apply_scene_settings, capture_scene_settings,
embed_referenced_meshes, embed_referenced_textures, load_scene_binary_from_bytes, spawn_scene,
spawn_scene_with_deserializer, world_to_scene, world_to_scene_with_serializer,
};
use nightshade::prelude::*;
pub use nightshade::ecs::scene::{
ComponentDescriptor, ComponentTypeRegistry, FieldDescriptor, FieldKind, Persistence,
SceneDeserializer, SceneSerializer, TypedComponent, TypedPayload,
register_component_descriptor,
};
pub fn save_scene(world: &World, name: &str) -> Result<Vec<u8>, SceneError> {
let mut scene = world_to_scene(world, name);
embed_referenced_meshes(world, &mut scene);
embed_referenced_textures(world, &mut scene);
save_scene_binary_to_bytes(&mut scene)
}
pub fn load_scene(world: &mut World, bytes: &[u8]) -> Result<Vec<Entity>, SceneError> {
let scene = load_scene_binary_from_bytes(bytes)?;
let result = spawn_scene(world, &scene, None)?;
Ok(result.root_entities)
}
pub fn save_scene_with(
world: &World,
name: &str,
serializer: &dyn SceneSerializer,
) -> Result<Vec<u8>, SceneError> {
let mut scene = world_to_scene_with_serializer(world, name, Some(serializer));
embed_referenced_meshes(world, &mut scene);
embed_referenced_textures(world, &mut scene);
save_scene_binary_to_bytes(&mut scene)
}
pub fn load_scene_with(
world: &mut World,
bytes: &[u8],
deserializer: &mut dyn SceneDeserializer,
) -> Result<Vec<Entity>, SceneError> {
let scene = load_scene_binary_from_bytes(bytes)?;
let result = spawn_scene_with_deserializer(world, &scene, None, Some(deserializer))?;
Ok(result.root_entities)
}
pub fn capture_settings(world: &World) -> SceneSettings {
capture_scene_settings(world)
}
pub fn apply_settings(world: &mut World, settings: &SceneSettings) {
apply_scene_settings(world, settings);
}