mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Purely worked persistance
This commit is contained in:
+1
-1
@@ -32,7 +32,7 @@ web-sys = { version = "0.3.65", optional = true, features = [
|
||||
"HtmlElement",
|
||||
"Window",
|
||||
] }
|
||||
space_editor = {git = "https://github.com/rewin123/space_editor", rev = "f3e2e0de52540125b79dad98656382ff473dedc2"}
|
||||
space_editor = {git = "https://github.com/rewin123/space_editor", rev = "0c3a8eaf1acea181407c43b7226799b2d08b4c89"}
|
||||
|
||||
[features]
|
||||
wasm = [
|
||||
|
||||
+5
-2
@@ -4,7 +4,7 @@ use bevy::{app::PluginGroupBuilder, prelude::*};
|
||||
use bevy_mod_picking::DefaultPickingPlugins;
|
||||
|
||||
use space_editor::{
|
||||
prelude::space_undo::UndoPlugin,
|
||||
prelude::{space_undo::UndoPlugin, PersistencePlugin},
|
||||
space_editor_ui::{EditorPluginGroup, ext::{bevy_egui::EguiPlugin, bevy_inspector_egui::DefaultInspectorConfigPlugin}, EditorPickingPlugin},
|
||||
};
|
||||
#[cfg(feature = "wasm")]
|
||||
@@ -70,6 +70,7 @@ impl PluginGroup for CommonPlugins {
|
||||
.add(StudioInputPlugin)
|
||||
.add(UiLayerPlugin)
|
||||
.add(WorldGridPlugin)
|
||||
.add(persistance::PersistancePlugin)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +125,7 @@ pub fn init(viewport_size: ViewportSize) {
|
||||
SkyboxPlugin,
|
||||
UiLayerPlugin,
|
||||
WorldGridPlugin,
|
||||
persistance::PersistancePlugin
|
||||
))
|
||||
.add_systems(
|
||||
Startup,
|
||||
@@ -131,7 +133,8 @@ pub fn init(viewport_size: ViewportSize) {
|
||||
cmd.insert_resource(SkyboxId("gum_trees_4k".to_string()));
|
||||
ew.send(LoadSceneEvent("bookcase".to_string()));
|
||||
},
|
||||
);
|
||||
)
|
||||
.insert_resource(StudioMode::Editor);
|
||||
|
||||
// Only for registering components for undo
|
||||
use space_editor::prelude::space_undo::AppAutoUndo;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
use bevy::prelude::*;
|
||||
use space_editor::prelude::*;
|
||||
|
||||
pub struct PersistancePlugin;
|
||||
|
||||
impl Plugin for PersistancePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
info!("PersistancePlugin::build");
|
||||
app.editor_tab_by_trait(EditorTabName::Other("Persistance".to_string()), DebugPersistanceTab::default());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct DebugPersistanceTab {
|
||||
|
||||
}
|
||||
|
||||
impl EditorTab for DebugPersistanceTab {
|
||||
fn ui(&mut self, ui: &mut bevy_inspector_egui::egui::Ui, commands: &mut Commands, world: &mut World) {
|
||||
if ui.button("Save").clicked() {
|
||||
world.send_event(EditorEvent::Save(EditorPrefabPath::MemoryCahce));
|
||||
}
|
||||
|
||||
if ui.button("Load").clicked() {
|
||||
world.send_event(EditorEvent::Load(EditorPrefabPath::MemoryCahce));
|
||||
}
|
||||
|
||||
if ui.button("Clear level").clicked() {
|
||||
let mut query = world.query_filtered::<Entity, With<PrefabMarker>>();
|
||||
for e in query.iter(world) {
|
||||
commands.entity(e).despawn_recursive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> bevy_inspector_egui::egui::WidgetText {
|
||||
"Persistance".into()
|
||||
}
|
||||
}
|
||||
+32
-13
@@ -5,7 +5,7 @@ use bevy::{
|
||||
fxaa::Fxaa,
|
||||
tonemapping::Tonemapping,
|
||||
},
|
||||
gltf::Gltf,
|
||||
gltf::{Gltf, GltfLoader},
|
||||
math::{vec2, vec3},
|
||||
pbr::ShadowFilteringMethod,
|
||||
prelude::*,
|
||||
@@ -108,6 +108,12 @@ pub struct LoadSceneEvent(pub String);
|
||||
#[derive(Component)]
|
||||
pub struct SceneElement;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct SceneData {
|
||||
pub scene_path: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct SceneRoot;
|
||||
|
||||
@@ -150,20 +156,33 @@ fn init_scene_loading(
|
||||
mut st_next: ResMut<NextState<SceneState>>,
|
||||
) {
|
||||
if let Some(id) = er.read().last() {
|
||||
let name = &**id;
|
||||
let path = format!("gltf/{name}.gltf");
|
||||
// let name = &**id;
|
||||
// let path = format!("gltf/{name}.gltf");
|
||||
|
||||
// Avoid trying to re-load this scene if it's already active
|
||||
if let Some(active_scene_path) =
|
||||
r_active_scene.and_then(|scene| scene.source.path().cloned())
|
||||
{
|
||||
if active_scene_path == AssetPath::parse(&path) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// // Avoid trying to re-load this scene if it's already active
|
||||
// if let Some(active_scene_path) =
|
||||
// r_active_scene.and_then(|scene| scene.source.path().cloned())
|
||||
// {
|
||||
// if active_scene_path == AssetPath::parse(&path) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
cmd.insert_resource(PendingScene(assets.load(path)));
|
||||
st_next.set(SceneState::Loading);
|
||||
// cmd.insert_resource(PendingScene(assets.load(path)));
|
||||
// st_next.set(SceneState::Loading);
|
||||
|
||||
info!("Loading scene: {}", id.0);
|
||||
|
||||
cmd.spawn((
|
||||
SpatialBundle::default(),
|
||||
space_editor::prelude::GltfPrefab {
|
||||
path: format!("gltf/{}.gltf", id.0),
|
||||
scene: "Scene0".to_string(),
|
||||
},
|
||||
PrefabMarker,
|
||||
SceneElement
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user