/* * This file is part of laurelin/client * Copyright (C) 2023 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ // FIXME: I hate this. Need to rework whole loading system at some point with a real loading state and screen. use bevy::{ prelude::*, ui::{JustifyContent, Size, Style, Val}, }; use crate::{ constants::TEXT_COLOR, despawn_screen, plugins::config::{LoadEvent, LoadEventValue}, GameState, }; /// This plugin is used to load all configs during startup pub struct LoadingPlugin; impl Plugin for LoadingPlugin { fn build(&self, app: &mut App) { app // Load the loading screen when we enter the Loading state .add_system(loading_setup.in_schedule(OnEnter(GameState::Loading))) // Despawn when we exit the Loading state .add_system(despawn_screen::.in_schedule(OnExit(GameState::Loading))); } } /// Tag component for tagging entities on the loading screen #[derive(Component)] struct OnLoadingScreen; fn loading_setup( mut commands: Commands, asset_server: Res, mut load_event_writer: EventWriter, ) { let font = asset_server.load("fonts/FiraMono-Regular.ttf"); commands .spawn(( NodeBundle { style: Style { align_items: AlignItems::Center, justify_content: JustifyContent::Center, size: Size::new(Val::Percent(100.), Val::Percent(100.)), ..Default::default() }, ..Default::default() }, OnLoadingScreen, )) .with_children(|parent| { parent.spawn(TextBundle { text: Text::from_section( "...", TextStyle { font: font.clone(), font_size: 80.0, color: TEXT_COLOR, }, ), style: Style { size: Size::new(Val::Px(1000.), Val::Auto), align_self: AlignSelf::Center, ..Default::default() }, ..Default::default() }); }); // Queue up load events for all configs load_event_writer.send(LoadEvent { value: LoadEventValue::Settings, }); load_event_writer.send(LoadEvent { value: LoadEventValue::User, }); load_event_writer.send(LoadEvent { value: LoadEventValue::Dev, }); commands.insert_resource(NextState(Some(GameState::MainMenu))); }