use games::*;

fn main() {
    App::new()
        .add_plugins(BaseGamePlugin {
            target_resolution: (360, 640).into(),
            ..default()
        })
        .add_systems(Startup, init_window_info)
        .add_systems(
            Update,
            update_window_info.run_if(any_component_changed::<Window>),
        )
        .run();
}

#[derive(Component)]
struct WindowInfo;

fn init_window_info(mut commands: Commands) {
    commands.spawn((
        Node {
            align_self: AlignSelf::Center,
            justify_self: JustifySelf::Center,
            ..default()
        },
        children![(Text::new("Placeholder"), WindowInfo,)],
    ));
}

fn update_window_info(mut text: Single<&mut Text, With<WindowInfo>>, window: Single<&Window>) {
    text.0 = format!(
        "Logical: {}x{}\nPhysical: {}x{}\nScale Factor: {}",
        window.resolution.physical_width(),
        window.resolution.physical_height(),
        window.resolution.width(),
        window.resolution.height(),
        window.resolution.scale_factor(),
    );
}
