DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: c4efcc1a742f98aa11e4a80b78afea3cac639bd2 deck-builder/client-old-for-ref/src/plugins/phases/loading/mod.rs -rw-r--r-- 2.6 KiB
c4efcc1aJonni Liljamo fix(client): check deck len in MarkCardInDeckToBeTrashed 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * This file is part of laurelin_client
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * 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::<OnLoadingScreen>.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<AssetServer>,
    mut load_event_writer: EventWriter<LoadEvent>,
) {
    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)));
}