mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-29 09:08:58 +00:00
Code cleanup
This commit is contained in:
@@ -44,8 +44,13 @@ impl Plugin for ScenePlugin {
|
|||||||
.add_systems(PostUpdate, move_plane_with_camera.after(CameraMotionSystem));
|
.add_systems(PostUpdate, move_plane_with_camera.after(CameraMotionSystem));
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
app.add_systems(PostUpdate, wasm::notify_entity_spawn_changes.pipe(error))
|
app.add_systems(
|
||||||
.add_systems(Update, wasm::save_scene_system);
|
PostUpdate,
|
||||||
|
(
|
||||||
|
wasm::notify_entity_spawn_changes.pipe(error),
|
||||||
|
wasm::save_scene_system.pipe(error),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-21
@@ -17,7 +17,7 @@ pub fn save_scene() {
|
|||||||
wasm::write_message!(SCENE_REQUEST, ());
|
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, |_| {
|
wasm::read_buffer!(SCENE_REQUEST, |_| {
|
||||||
let mut scene = DynamicScene::from_world(world);
|
let mut scene = DynamicScene::from_world(world);
|
||||||
let type_registry = world.resource::<AppTypeRegistry>();
|
let type_registry = world.resource::<AppTypeRegistry>();
|
||||||
@@ -48,29 +48,25 @@ pub(super) fn save_scene_system(world: &mut World) {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
match scene.serialize_ron(type_registry) {
|
let serialized = scene
|
||||||
Ok(serialized) => {
|
.serialize_ron(type_registry)
|
||||||
let Some(window) = world.iter_entities().find_map(|ent| {
|
.map_err(|err| format!("{err}"))?;
|
||||||
if ent.contains::<PrimaryWindow>() {
|
|
||||||
ent.get::<Window>()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}) else {
|
|
||||||
warn!("Failed to get window from &mut World");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(err) = wasm::dispatch_to_js(window, "scene-download-ready", &serialized)
|
let window = world
|
||||||
{
|
.iter_entities()
|
||||||
error!("{err}");
|
.find_map(|ent| {
|
||||||
|
if ent.contains::<PrimaryWindow>() {
|
||||||
|
ent.get::<Window>()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
Err(err) => {
|
.ok_or_else(|| "Failed to get Window from &mut World".to_string())?;
|
||||||
error!("{err}");
|
|
||||||
}
|
wasm::dispatch_to_js(window, "scene-download-ready", &serialized)?;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(typescript_custom_section)]
|
#[wasm_bindgen(typescript_custom_section)]
|
||||||
|
|||||||
Reference in New Issue
Block a user