#[derive(Component)]
struct LoadingScreenBar;
fn create_loading_screen_bar(mut commands: Commands) {
    commands
        .spawn((
            LoadingScreenBar,
            ShapeBundle {
                path: GeometryBuilder::build_as(&shapes::Rectangle {
                    origin: shapes::RectangleOrigin::TopLeft,
                    extents: Vec2::new(LOGICAL_WIDTH as f32, 40.0),
                }),
                spatial: SpatialBundle {
                    transform: Transform::default()
                        .with_translation(Vec3::new(
                            LOGICAL_WIDTH as f32 / -2.0,
                            // LOGICAL_HEIGHT as f32 / 2.0,
                            LOGICAL_HEIGHT as f32 / -2.0 + 80.0 * 1.5,
                            -1.0,
                        ))
                        .with_scale(Vec3::ONE - Vec3::X),
                    ..default()
                },
                ..default()
            },
            Fill::color(Color::ANTIQUE_WHITE),
        ))
        .with_children(|cb| {
            cb.spawn(Text2dBundle {
                text: Text::from_section(
                    "Loading...",
                    TextStyle {
                        font_size: 30.0,
                        color: Color::BLACK,
                        ..default()
                    },
                ),
                text_anchor: Anchor::CenterLeft,
                transform: Transform::from_translation(Vec3::Z + Vec3::NEG_Y * 20.0),
                ..default()
            });
        });
}
fn clean_loading_screen_bar(mut commands: Commands, bar: Query<Entity, With<LoadingScreenBar>>) {
    let entity = bar.single();
    commands.entity(entity).despawn_recursive();
}
fn loading_screen_progress(
    progress: Option<Res<ProgressCounter>>,
    mut last_done: Local<u32>,
    mut lb: Query<&mut Transform, With<LoadingScreenBar>>,
) {
    if let Some(progress) = progress.map(|counter| counter.progress()) {
        if progress.done > *last_done {
            let mut lbt = lb.single_mut();
            *last_done = progress.done;
            info!("Changed progress: {:?}", progress);
            lbt.scale.x = progress.done as f32 / progress.total as f32;
        }
    }
}