Skip to content

Commit

Permalink
Adjust scale plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu committed Sep 20, 2024
1 parent 076d858 commit 8302418
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/scale/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ use crate::{

pub fn setup(app: &mut App) {
app.insert_resource(ScaleFactor::default())
.add_systems(Startup, init_scale_system)
.add_systems(OnEnter(AppState::ChangeScale), change_scale_system);
.add_systems(Startup, change_scale_system)
.add_systems(
Update,
(change_scale_system, restore_app_state_system)
.chain()
.run_if(in_state(AppState::ChangeScale)),
);
}

#[derive(Default, Clone, Copy, FromPrimitive, Resource)]
Expand Down Expand Up @@ -49,31 +54,19 @@ impl ScaleFactor {
}
}

fn init_scale_system(
scale_factor: Res<ScaleFactor>,
mut splash_transform: ResMut<SplashTransform>,
mut game_option_menu_transform: ResMut<GameOptionMenuTransform>,
mut level_menu_transform: ResMut<LevelMenuTransform>,
mut game_transform: ResMut<GameTransform>,
) {
*splash_transform = SplashTransform::new(scale_factor.mul());
*game_option_menu_transform = GameOptionMenuTransform::new(scale_factor.mul());
*level_menu_transform = LevelMenuTransform::new(scale_factor.mul());
*game_transform = GameTransform::new(scale_factor.mul());
}

fn change_scale_system(
scale_factor: Res<ScaleFactor>,
mut splash_transform: ResMut<SplashTransform>,
mut game_option_menu_transform: ResMut<GameOptionMenuTransform>,
mut level_menu_transform: ResMut<LevelMenuTransform>,
mut game_transform: ResMut<GameTransform>,
mut app_state: ResMut<NextState<AppState>>,
) {
*splash_transform = SplashTransform::new(scale_factor.mul());
*game_option_menu_transform = GameOptionMenuTransform::new(scale_factor.mul());
*level_menu_transform = LevelMenuTransform::new(scale_factor.mul());
*game_transform = GameTransform::new(scale_factor.mul());
}

fn restore_app_state_system(mut app_state: ResMut<NextState<AppState>>) {
app_state.set(AppState::GameModeMenu);
}

0 comments on commit 8302418

Please sign in to comment.