Skip to content

Commit

Permalink
Init scale to 720p.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramirisu committed Sep 20, 2024
1 parent 542e9b5 commit c4459af
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::prelude::*;
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, States)]
pub enum AppState {
#[default]
Startup,
Splash,
GameModeMenu,
LevelMenu,
Expand Down
3 changes: 2 additions & 1 deletion src/game_option_menu/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use bevy::window::WindowMode;
use super::{fps_limiter::FPSLimiter, transform::GameOptionMenuTransform};

pub fn setup(app: &mut App) {
app.add_systems(Startup, init_framepace_settings)
app.add_plugins(bevy_framepace::FramepacePlugin)
.add_systems(Startup, init_framepace_settings)
.insert_resource(GameOptionMenuTransform::default())
.insert_resource(GameOptionMenuData::default())
.add_systems(OnEnter(AppState::GameModeMenu), setup_screen)
Expand Down
1 change: 1 addition & 0 deletions src/init/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod plugin;
14 changes: 14 additions & 0 deletions src/init/plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use bevy::prelude::*;

use crate::app_state::AppState;

pub fn setup(app: &mut App) {
app.add_systems(
Update,
enter_splash_system.run_if(in_state(AppState::Startup)),
);
}

fn enter_splash_system(mut app_state: ResMut<NextState<AppState>>) {
app_state.set(AppState::Splash);
}
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod audio;
mod controller;
mod game;
mod game_option_menu;
mod init;
mod inputs;
mod level_menu;
mod logo;
Expand All @@ -29,8 +30,14 @@ fn main() {
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(1440.0, 1080.0)
resolution: WindowResolution::new(960.0, 720.0)
.with_scale_factor_override(1.0),
resize_constraints: WindowResizeConstraints {
min_width: 960.0,
min_height: 720.0,
max_width: f32::INFINITY,
max_height: f32::INFINITY,
},
present_mode: PresentMode::AutoNoVsync,
position: WindowPosition::Centered(MonitorSelection::Primary),
cursor: Cursor {
Expand All @@ -53,19 +60,19 @@ fn main() {
},
},
})
.add_plugins(bevy_framepace::FramepacePlugin)
.insert_resource(ClearColor(Color::BLACK)) // application background color
.init_state::<AppState>()
.add_systems(Startup, setup_camera)
.add_plugins((
controller::setup,
inputs::setup,
scale::plugin::setup,
audio::plugin::setup,
init::plugin::setup,
splash::plugin::setup,
game_option_menu::plugin::setup,
level_menu::plugin::setup,
game::plugin::setup,
scale::plugin::setup,
))
.run();
}
Expand Down
16 changes: 15 additions & 1 deletion src/scale/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ 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);
}

#[derive(Default, Clone, Copy, FromPrimitive, Resource)]
pub enum ScaleFactor {
S720 = 0,
#[default]
S720 = 0,
S1080,
S1440,
S1800,
Expand Down Expand Up @@ -48,6 +49,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>,
Expand Down

0 comments on commit c4459af

Please sign in to comment.