Code cleanup

This commit is contained in:
Danny McGee
2023-11-14 20:40:07 -05:00
parent 03303720f6
commit a28297914e
2 changed files with 24 additions and 23 deletions
+7 -2
View File
@@ -44,8 +44,13 @@ impl Plugin for ScenePlugin {
.add_systems(PostUpdate, move_plane_with_camera.after(CameraMotionSystem));
#[cfg(feature = "wasm")]
app.add_systems(PostUpdate, wasm::notify_entity_spawn_changes.pipe(error))
.add_systems(Update, wasm::save_scene_system);
app.add_systems(
PostUpdate,
(
wasm::notify_entity_spawn_changes.pipe(error),
wasm::save_scene_system.pipe(error),
),
);
}
}
+17 -21
View File
@@ -17,7 +17,7 @@ pub fn save_scene() {
wasm::write_message!(SCENE_REQUEST, ());
}
pub(super) fn save_scene_system(world: &mut World) {
pub(super) fn save_scene_system(world: &mut World) -> Result<(), String> {
wasm::read_buffer!(SCENE_REQUEST, |_| {
let mut scene = DynamicScene::from_world(world);
let type_registry = world.resource::<AppTypeRegistry>();
@@ -48,29 +48,25 @@ pub(super) fn save_scene_system(world: &mut World) {
})
.collect();
match scene.serialize_ron(type_registry) {
Ok(serialized) => {
let Some(window) = world.iter_entities().find_map(|ent| {
if ent.contains::<PrimaryWindow>() {
ent.get::<Window>()
} else {
None
}
}) else {
warn!("Failed to get window from &mut World");
return;
};
let serialized = scene
.serialize_ron(type_registry)
.map_err(|err| format!("{err}"))?;
if let Err(err) = wasm::dispatch_to_js(window, "scene-download-ready", &serialized)
{
error!("{err}");
let window = world
.iter_entities()
.find_map(|ent| {
if ent.contains::<PrimaryWindow>() {
ent.get::<Window>()
} else {
None
}
}
Err(err) => {
error!("{err}");
}
}
})
.ok_or_else(|| "Failed to get Window from &mut World".to_string())?;
wasm::dispatch_to_js(window, "scene-download-ready", &serialized)?;
});
Ok(())
}
#[wasm_bindgen(typescript_custom_section)]