|
|
|
@ -48,8 +48,6 @@ impl Plugin for BaseGamePlugin {
|
|
|
|
.add_plugins(LoadingPlugin)
|
|
|
|
.add_plugins(LoadingPlugin)
|
|
|
|
.add_plugins(BaseUiPlugin)
|
|
|
|
.add_plugins(BaseUiPlugin)
|
|
|
|
.add_plugins(ParallaxPlugin)
|
|
|
|
.add_plugins(ParallaxPlugin)
|
|
|
|
// .add_systems(Update, scale_game.run_if(any_component_changed::<Window>))
|
|
|
|
|
|
|
|
.insert_resource(TargetResolution(self.target_resolution.clone()))
|
|
|
|
|
|
|
|
.init_resource::<Rand>();
|
|
|
|
.init_resource::<Rand>();
|
|
|
|
|
|
|
|
|
|
|
|
match self.game_type {
|
|
|
|
match self.game_type {
|
|
|
|
@ -59,9 +57,6 @@ impl Plugin for BaseGamePlugin {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Resource)]
|
|
|
|
|
|
|
|
struct TargetResolution(WindowResolution);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// System to toggle the visibility of entities based on their state
|
|
|
|
/// System to toggle the visibility of entities based on their state
|
|
|
|
pub fn toggle_state_visibility<S: States + Component>(
|
|
|
|
pub fn toggle_state_visibility<S: States + Component>(
|
|
|
|
mut q: Query<(Entity, &mut Visibility, &S)>,
|
|
|
|
mut q: Query<(Entity, &mut Visibility, &S)>,
|
|
|
|
@ -84,6 +79,7 @@ pub fn create_camera_3d(mut commands: Commands) {
|
|
|
|
Camera3d { ..default() },
|
|
|
|
Camera3d { ..default() },
|
|
|
|
Camera { ..default() },
|
|
|
|
Camera { ..default() },
|
|
|
|
AmbientLight::default(),
|
|
|
|
AmbientLight::default(),
|
|
|
|
|
|
|
|
Transform::default(),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -95,22 +91,3 @@ pub fn create_camera_2d(mut commands: Commands) {
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default, Resource)]
|
|
|
|
#[derive(Default, Resource)]
|
|
|
|
pub struct Rand(pub RandomState);
|
|
|
|
pub struct Rand(pub RandomState);
|
|
|
|
|
|
|
|
|
|
|
|
/// Scale the game based on the difference between the target and real resolution
|
|
|
|
|
|
|
|
fn scale_game(
|
|
|
|
|
|
|
|
mut window: Single<&mut Window>,
|
|
|
|
|
|
|
|
target_resolution: Res<TargetResolution>,
|
|
|
|
|
|
|
|
mut last_scale_factor: Local<f32>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
let current_resolution: Vec2 = window.resolution.size();
|
|
|
|
|
|
|
|
let scale_width = current_resolution.x.round() / target_resolution.0.width().round();
|
|
|
|
|
|
|
|
let scale_height = current_resolution.y.round() / target_resolution.0.height().round();
|
|
|
|
|
|
|
|
let scale_factor = f32::min(scale_width, scale_height);
|
|
|
|
|
|
|
|
if window.resolution.scale_factor() != scale_factor {
|
|
|
|
|
|
|
|
// Need to check the previously set scale factor because the system can flip-flop otherwise
|
|
|
|
|
|
|
|
if scale_factor != *last_scale_factor {
|
|
|
|
|
|
|
|
*last_scale_factor = window.resolution.scale_factor();
|
|
|
|
|
|
|
|
window.resolution.set_scale_factor(scale_factor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|