DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: e09fcc3b0fe1575540988ea9672edaa0a1d90aa7 deck-builder/client/src/plugins/menu/mod.rs -rw-r--r-- 2.1 KiB
e09fcc3bJonni Liljamo feat(client): sane-ish supply pile spawning 1 year, 5 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
92
93
94
95
96
97
98
/*
 * 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::*;

use crate::{AppState, api::game::Game};

mod ui;

pub struct MenuPlugin;

impl Plugin for MenuPlugin {
    fn build(&self, app: &mut App) {
        app.add_state::<MenuState>()
            .insert_resource(MenuData::default())
            .add_system(menu_setup.in_schedule(OnEnter(AppState::Menu)))
            .add_system(ui::ui.run_if(not(in_state(MenuState::None))));
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, States)]
enum MenuState {
    #[default]
    None,
    Visible,
}

#[derive(Resource)]
pub struct MenuData {
    pub ui_state: MenuUIState,
    pub browse_state: BrowseState,

    /// true if waiting on some request
    pub waiting: bool,

    pub forming_games: Vec<Game>,
    pub my_games: Vec<Game>,

    error: String,

    login_email: String,
    login_password: String,

    register_username: String,
    register_email: String,
    register_password: String,
    register_password_confirm: String,
}

impl Default for MenuData {
    fn default() -> Self {
        Self {
            ui_state: MenuUIState::Login,
            browse_state: BrowseState::Forming,

            waiting: false,

            forming_games: vec![],
            my_games: vec![],

            error: String::from(""),

            login_email: String::from(""),
            login_password: String::from(""),

            register_username: String::from(""),
            register_email: String::from(""),
            register_password: String::from(""),
            register_password_confirm: String::from(""),
        }
    }
}

#[derive(Debug)]
pub enum MenuUIState {
    Loading, // for waiting for requests to finish
    Login,
    Register,
    Main,
    Browse,

}

#[derive(Debug, PartialEq)]
pub enum BrowseState {
    Forming,
    InProgress,
    Finished,
}

fn menu_setup(mut commands: Commands) {
    commands.insert_resource(NextState(Some(MenuState::Visible)));
}