DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 77d69bb2897192b87480515379d699ad87b852cc deck-builder/client/src/plugins/phases/splash/mod.rs -rw-r--r-- 2.4 KiB
77d69bb2Jonni Liljamo feat(server): recieve tick buffer messages 1 year, 9 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
/*
 * 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.
 */

use bevy::{
    prelude::*,
    ui::{JustifyContent, Size, Style, Val},
};
use iyes_loopless::prelude::*;

use crate::{despawn_screen, GameState};

/// This plugin will display a splsh logo on startup
pub struct SplashPlugin;

impl Plugin for SplashPlugin {
    fn build(&self, app: &mut App) {
        app
            // Load the splash when we enter the Splash state
            .add_enter_system(GameState::Splash, splash_setup)
            // Run a timer for a few seconds
            .add_system_set(
                ConditionSet::new()
                    .run_in_state(GameState::Splash)
                    .with_system(splash_timer)
                    .into(),
            )
            // Despawn when we exit the Splash state
            .add_exit_system(GameState::Splash, despawn_screen::<OnSplashScreen>);
    }
}

/// Tag component for tagging entities on the splash screen
#[derive(Component)]
struct OnSplashScreen;

/// Timer resource
#[derive(Resource, Deref, DerefMut)]
struct SplashTimer(Timer);

fn splash_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let logo = asset_server.load("branding/logo.png");

    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()
            },
            OnSplashScreen,
        ))
        .with_children(|parent| {
            parent.spawn(ImageBundle {
                style: Style {
                    size: Size::new(Val::Px(1000.), Val::Auto),
                    ..Default::default()
                },
                image: UiImage(logo),
                ..Default::default()
            });
        });

    // Insert the timer resource
    commands.insert_resource(SplashTimer(Timer::from_seconds(2., TimerMode::Once)));
}

fn splash_timer(mut commands: Commands, time: Res<Time>, mut timer: ResMut<SplashTimer>) {
    if timer.tick(time.delta()).finished() {
        commands.insert_resource(NextState(GameState::Loading))
    }
}