From 0f9d9b27ea758021ecce1327467e1fb17b777f05 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Wed, 14 Feb 2024 20:14:10 -0800 Subject: [PATCH] cargo fmt --- src/intro.rs | 4 +- src/tutorial.rs | 122 +++++++++++++++++++++++++----------------------- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/src/intro.rs b/src/intro.rs index ba85624..7220ce9 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -85,7 +85,7 @@ fn init_intro_text( padding: UiRect::all(Val::Px(25.0)), ..default() }, - background_color: Color::BLACK.with_a(0.9).into(), + background_color: Color::BLACK.with_a(1.0).into(), ..default() }, )) @@ -96,7 +96,7 @@ fn init_intro_text( value: c.to_string(), style: TextStyle { font_size: 16.0, - color: Color::WHITE.with_a(0.0), + color: Color::WHITE.with_a(0.2), ..default() }, })) diff --git a/src/tutorial.rs b/src/tutorial.rs index c0a84fa..b01eda6 100644 --- a/src/tutorial.rs +++ b/src/tutorial.rs @@ -21,15 +21,21 @@ impl Plugin for TutorialPlugin { Update, ( // Run if we have a TutorialState *and* it is not TutorialState::None *and* we get a return keypress - transition - .run_if(state_exists::()) - .run_if(not(in_state(TutorialState::None))), - transition - .run_if(state_exists::()) + step.run_if(state_exists::()) + .run_if(not(in_state(TutorialState::None))) + .run_if(|keys: Res>| -> bool { + keys.just_pressed(KeyCode::Return) + }), + // Evaluate if a piece is selected + step.run_if(state_exists::()) .run_if(not(in_state(TutorialState::None))) .run_if(any_component_added::), - transition - .run_if(state_exists::()) + // Evaluate if a piece is selected + step.run_if(state_exists::()) + .run_if(not(in_state(TutorialState::None))) + .run_if(any_component_removed::()), + // Evaluate if a piece's side changes + step.run_if(state_exists::()) .run_if(not(in_state(TutorialState::None))) .run_if(any_component_changed::), ), @@ -178,7 +184,7 @@ fn initialize_tutorial( padding: UiRect::all(Val::Px(25.0)), ..default() }, - background_color: Color::BLACK.with_a(0.9).into(), + background_color: Color::BLACK.with_a(1.0).into(), ..default() }, )) @@ -209,20 +215,14 @@ fn initialize_tutorial( }) } -fn transition( - pieces: Query<&game::Piece, With>, +fn step( + pieces: Query<&game::Piece, Added>, transitions: Query>, curr_state: Res>, mut next_state: ResMut>, - keys: Res>, mut seen: Local>, ) { - // TEMP: Early out, only handle Return keys - if !keys.just_pressed(KeyCode::Return) { - return; - } - - info!("Transitioning tutorial state"); + info!("Evalute tutorial state"); // Store the current state // Used to avoid doing a prevoius state again @@ -245,50 +245,56 @@ fn transition( | TutorialState::PieceJump | TutorialState::Empty | TutorialState::Ownership => { - // When a queen is selected for the first time... - if pieces.iter().filter(|&p| *p == game::Piece::Queen).count() > 0 - && !(*seen).contains(&TutorialState::PieceQueen) - { - TutorialState::PieceQueen - // When a drone is selected for the first time... - } else if pieces.iter().filter(|&p| *p == game::Piece::Drone).count() > 0 - && !(*seen).contains(&TutorialState::PieceDrone) - { - TutorialState::PieceDrone - // When a pawn is selected for the first time... - } else if pieces.iter().filter(|&p| *p == game::Piece::Pawn).count() > 0 - && !(*seen).contains(&TutorialState::PiecePawn) - { - TutorialState::PiecePawn - // All pieces have been selected - } else if (*seen).contains(&TutorialState::PieceIntro) - && (*seen).contains(&TutorialState::PieceQueen) - && (*seen).contains(&TutorialState::PieceDrone) - && (*seen).contains(&TutorialState::PiecePawn) - { - // And we have touched on jumping - if (*seen).contains(&TutorialState::PieceJump) { - TutorialState::PieceEnd - // We have not touched on jumping + // There are no pieces selected + if pieces.is_empty() { + if (*seen).contains(&TutorialState::PieceIntro) + && (*seen).contains(&TutorialState::PieceQueen) + && (*seen).contains(&TutorialState::PieceDrone) + && (*seen).contains(&TutorialState::PiecePawn) + { + // And we have not touched on jumping yet + if !(*seen).contains(&TutorialState::PieceJump) { + TutorialState::PieceJump + } + // A piece moves sides, so talk about ownership + else if !(*seen).contains(&TutorialState::Ownership) + && transitions.iter().count() > 0 + { + TutorialState::Ownership + // We have visited all relevant tutorial points, say goodbye + } else if (*seen).contains(&TutorialState::PieceJump) + && (*seen).contains(&TutorialState::Ownership) + { + TutorialState::Outro + } + // We have not touched on jumping + else { + TutorialState::PieceEnd + } + // Default, empty (tutorial doesn't always need to show something) } else { - TutorialState::PieceJump + TutorialState::Empty } - // A piece moves sides, so talk about ownership - } else if !(*seen).contains(&TutorialState::Ownership) && transitions.iter().count() > 0 - { - TutorialState::Ownership - // We have visited all relevant tutorial points, say goodbye - } else if (*seen).contains(&TutorialState::PieceIntro) - && (*seen).contains(&TutorialState::PieceQueen) - && (*seen).contains(&TutorialState::PieceDrone) - && (*seen).contains(&TutorialState::PiecePawn) - && (*seen).contains(&TutorialState::PieceJump) - && (*seen).contains(&TutorialState::Ownership) - { - TutorialState::Outro - // Default, empty (tutorial doesn't always need to show something) + // One piece is selected } else { - TutorialState::Empty + // When a queen is selected for the first time... + if pieces.iter().filter(|&p| *p == game::Piece::Queen).count() > 0 + && !(*seen).contains(&TutorialState::PieceQueen) + { + TutorialState::PieceQueen + // When a drone is selected for the first time... + } else if pieces.iter().filter(|&p| *p == game::Piece::Drone).count() > 0 + && !(*seen).contains(&TutorialState::PieceDrone) + { + TutorialState::PieceDrone + // When a pawn is selected for the first time... + } else if pieces.iter().filter(|&p| *p == game::Piece::Pawn).count() > 0 + && !(*seen).contains(&TutorialState::PiecePawn) + { + TutorialState::PiecePawn + } else { + panic!("This shouldn't be possible...!") + } } } // After the outro, we exit the tutorial