Skip to content

Commit

Permalink
fix scene switch problem and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceNerde committed Dec 10, 2023
1 parent d667de9 commit 11ef396
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/menu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::core_components::ChangeState;
use crate::loading::TextureAssets;
use crate::GameState;
use crate::scene_handler::MenuCamera;
use bevy::prelude::*;
use bevy_voxel_world::prelude::*;

pub struct MenuPlugin;

Expand Down Expand Up @@ -38,7 +36,6 @@ struct Menu;
fn setup_menu(
mut commands: Commands,
textures: Res<TextureAssets>,
mut game_camera_query: Query<&mut Camera, With<VoxelWorldCamera>>,
) {
info!("menu");
commands
Expand Down Expand Up @@ -196,14 +193,14 @@ fn click_play_button(
),
(Changed<Interaction>, With<Button>),
>,
mut menu_camera_query: Query<&mut Camera, With<MenuCamera>>,
mut game_camera_query: Query<&mut Camera, (With<VoxelWorldCamera>, Without<MenuCamera>)>,
mut commands: Commands,
) {
for (interaction, mut color, button_colors, change_state, open_link) in &mut interaction_query {
match *interaction {
Interaction::Pressed => {
if let Some(state) = change_state {
next_state.set(state.0.clone());
commands.spawn(ChangeState(GameState::Playing));
} else if let Some(link) = open_link {
if let Err(error) = webbrowser::open(link.0) {
warn!("Failed to open link {error:?}");
Expand Down
7 changes: 3 additions & 4 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ fn open_menu(
}
}

fn cleanup(mut game_camera_query: Query<&mut Camera, With<VoxelWorldCamera>>, mut windows: Query<&mut Window>) {
let mut camera = game_camera_query.single_mut();
camera.is_active = false;

fn cleanup(
mut windows: Query<&mut Window>
) {
let mut window = windows.single_mut();

window.cursor.visible = true;
Expand Down
6 changes: 0 additions & 6 deletions src/scene_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ pub struct MenuCamera;

fn setup_cameras(
mut commands: Commands,
//mut menu_camera_query: Query<&mut Camera, With<MenuCamera>>,
//mut game_camera_query: Query<&mut Camera, (With<VoxelWorldCamera>, Without<MenuCamera>)>,
){
// Spawn Cameras

// Menu Camera
commands.spawn((Camera2dBundle::default(), MenuCamera));
//let mut menu_camera = menu_camera_query.single_mut();
//menu_camera.is_active = false;

// Game Camera
commands.spawn((
Expand All @@ -37,8 +33,6 @@ fn setup_cameras(
// This tells bevy_voxel_world tos use this cameras transform to calculate spawning area
VoxelWorldCamera,
));
//let mut game_camera = game_camera_query.single_mut();
//game_camera.is_active = false;
}

fn enter_playing(
Expand Down

0 comments on commit 11ef396

Please sign in to comment.