mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 11:50:53 +00:00
feat(examples:Save_load): created much simpler example for save load
* removed old assets & co * fresh blend with Blenvy logic * generated assets (wip) * started updating code (wip)
This commit is contained in:
parent
171ec7490a
commit
d08c235122
BIN
examples/save_load/art/save_load.blend
Normal file
BIN
examples/save_load/art/save_load.blend
Normal file
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
({})
|
|
@ -1,8 +0,0 @@
|
|||||||
({
|
|
||||||
"world":File (path: "models/World.glb"),
|
|
||||||
"world_dynamic":File (path: "models/World_dynamic.glb"),
|
|
||||||
|
|
||||||
"models": Folder (
|
|
||||||
path: "models/library",
|
|
||||||
),
|
|
||||||
})
|
|
Binary file not shown.
BIN
examples/save_load/assets/blueprints/Mover.glb
Normal file
BIN
examples/save_load/assets/blueprints/Mover.glb
Normal file
Binary file not shown.
5
examples/save_load/assets/blueprints/Mover.meta.ron
Normal file
5
examples/save_load/assets/blueprints/Mover.meta.ron
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(
|
||||||
|
assets:
|
||||||
|
[
|
||||||
|
]
|
||||||
|
)
|
BIN
examples/save_load/assets/blueprints/Pillar.glb
Normal file
BIN
examples/save_load/assets/blueprints/Pillar.glb
Normal file
Binary file not shown.
5
examples/save_load/assets/blueprints/Pillar.meta.ron
Normal file
5
examples/save_load/assets/blueprints/Pillar.meta.ron
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
(
|
||||||
|
assets:
|
||||||
|
[
|
||||||
|
]
|
||||||
|
)
|
BIN
examples/save_load/assets/levels/World.glb
Normal file
BIN
examples/save_load/assets/levels/World.glb
Normal file
Binary file not shown.
9
examples/save_load/assets/levels/World.meta.ron
Normal file
9
examples/save_load/assets/levels/World.meta.ron
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
(
|
||||||
|
assets:
|
||||||
|
[
|
||||||
|
("Pillar", File ( path: "blueprints/Pillar.glb" )),
|
||||||
|
("Stone", File ( path: "materials/Stone.glb" )),
|
||||||
|
("Mover", File ( path: "blueprints/Mover.glb" )),
|
||||||
|
("Material.001", File ( path: "materials/Material.001.glb" )),
|
||||||
|
]
|
||||||
|
)
|
BIN
examples/save_load/assets/levels/World_dynamic.glb
Normal file
BIN
examples/save_load/assets/levels/World_dynamic.glb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14228
examples/save_load/assets/registry.json
Normal file
14228
examples/save_load/assets/registry.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,11 @@
|
|||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
|
|
||||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||||
use blenvy::{AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SpawnBlueprint};
|
use blenvy::{AddToGameWorld, BlenvyPlugin, BluePrintBundle, BlueprintInfo, Dynamic, DynamicBlueprintInstance, GameWorldTag, HideUntilReady, SaveRequest, SpawnBlueprint};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
mod core;
|
// mod game;
|
||||||
use crate::core::*;
|
// use game::*;
|
||||||
|
|
||||||
mod game;
|
|
||||||
use game::*;
|
|
||||||
|
|
||||||
mod component_examples;
|
mod component_examples;
|
||||||
use component_examples::*;
|
use component_examples::*;
|
||||||
@ -37,13 +34,12 @@ fn main() {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
// our custom plugins
|
// our custom plugins
|
||||||
CorePlugin, // reusable plugins
|
// GamePlugin, // specific to our game
|
||||||
GamePlugin, // specific to our game
|
|
||||||
ComponentsExamplesPlugin, // Showcases different type of components /structs
|
ComponentsExamplesPlugin, // Showcases different type of components /structs
|
||||||
))
|
))
|
||||||
|
|
||||||
.add_systems(Startup, setup_game)
|
.add_systems(Startup, setup_game)
|
||||||
.add_systems(Update, (spawn_blueprint_instance, save_game, load_game))
|
.add_systems(Update, (spawn_blueprint_instance, move_movers, save_game, load_game))
|
||||||
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@ -60,6 +56,13 @@ fn setup_game(
|
|||||||
HideUntilReady, // only reveal the level once it is ready
|
HideUntilReady, // only reveal the level once it is ready
|
||||||
GameWorldTag,
|
GameWorldTag,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// here we spawn our game world/level, which is also a blueprint !
|
||||||
|
commands.spawn((
|
||||||
|
BlueprintInfo::from_path("levels/World_dynamic.glb"), // all we need is a Blueprint info...
|
||||||
|
SpawnBlueprint, // and spawnblueprint to tell blenvy to spawn the blueprint now
|
||||||
|
HideUntilReady, // only reveal the level once it is ready
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// you can also spawn blueprint instances at runtime
|
// you can also spawn blueprint instances at runtime
|
||||||
@ -90,15 +93,47 @@ fn spawn_blueprint_instance(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_game(
|
fn move_movers(
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
mut movers: Query<(&mut Transform), With<Dynamic>>
|
||||||
|
|
||||||
) {
|
) {
|
||||||
if keycode.just_pressed(KeyCode::KeyS) {
|
for mut transform in movers.iter_mut(){
|
||||||
|
println!("moving dynamic entity");
|
||||||
|
transform.translation.x += 0.01;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn save_game(
|
||||||
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
|
mut save_requests: EventWriter<SaveRequest>,
|
||||||
|
) {
|
||||||
|
if keycode.just_pressed(KeyCode::KeyS) {
|
||||||
|
save_requests.send(SaveRequest {
|
||||||
|
path: "scenes/save.scn.ron".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn request_save(
|
||||||
|
mut save_requests: EventWriter<SaveRequest>,
|
||||||
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
|
|
||||||
|
current_state: Res<State<GameState>>,
|
||||||
|
mut next_game_state: ResMut<NextState<GameState>>,
|
||||||
|
) {
|
||||||
|
if keycode.just_pressed(KeyCode::KeyS)
|
||||||
|
&& (current_state.get() != &GameState::InLoading)
|
||||||
|
&& (current_state.get() != &GameState::InSaving)
|
||||||
|
{
|
||||||
|
next_game_state.set(GameState::InSaving);
|
||||||
|
save_requests.send(SaveRequest {
|
||||||
|
path: "save.scn.ron".into(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn load_game(
|
fn load_game(
|
||||||
keycode: Res<ButtonInput<KeyCode>>,
|
keycode: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user