DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 28b4857811c0346607df4f70e0da51c7dab7d3fe deck-builder/sdbclient/src/main.rs -rw-r--r-- 3.7 KiB
28b48578Jonni Liljamo chore(sdbclient): disable lua things 1 year, 8 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * This file is part of sdbclient
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy::{
    prelude::*,
    window::{CompositeAlphaMode, CursorGrabMode, PresentMode, WindowResizeConstraints},
};

use bevy_console::{ConsoleConfiguration, ConsolePlugin, ToggleConsoleKey};
use bevy_inspector_egui::quick::WorldInspectorPlugin;

//use bevy_mod_scripting::prelude::*;

use iyes_loopless::prelude::*;

use belly::prelude::{BellyPlugin, StyleSheet};

mod api;
mod cfg;
mod constants;
//mod lua;
mod plugins;
mod util;

/// Used to control the state of the game
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum GameState {
    Splash,
    Loading,
    MainMenu,
    Game,
}

fn main() {
    let mut app = App::new();

    app.add_plugins(DefaultPlugins.set(WindowPlugin {
        window: WindowDescriptor {
            width: 1280.,
            height: 720.,
            position: WindowPosition::Centered,
            monitor: MonitorSelection::Primary,
            resize_constraints: WindowResizeConstraints {
                min_width: 1280.,
                min_height: 720.,
                max_width: 3840.,
                max_height: 2160.,
            },
            scale_factor_override: Some(1.),
            title: "Deck Builder".to_string(),
            present_mode: PresentMode::Fifo,
            resizable: false,
            decorations: true,
            cursor_visible: true,
            cursor_grab_mode: CursorGrabMode::None,
            mode: WindowMode::Windowed,
            transparent: false,
            canvas: None,
            fit_canvas_to_parent: false,
            alpha_mode: CompositeAlphaMode::Auto,
        },
        ..Default::default()
    }));

    app.add_plugin(WorldInspectorPlugin);
    app.add_plugin(ConsolePlugin);
    app.insert_resource(ConsoleConfiguration {
        keys: vec![
            ToggleConsoleKey::KeyCode(KeyCode::F1),
            ToggleConsoleKey::KeyCode(KeyCode::F13),
        ],
        ..Default::default()
    });

    //app.add_plugin(ScriptingPlugin).add_plugin(lua::LuaPlugin);

    app.add_plugin(BellyPlugin);

    app.insert_resource(cfg::CfgDirs(
        directories::ProjectDirs::from("com", "liljamo", "deckbuilder")
            .expect("failed to get project directories"),
    ));

    app.insert_resource(cfg::CfgSettings::default())
        .insert_resource(cfg::CfgUser::default())
        .insert_resource(cfg::CfgDev::default());

    app.add_startup_system(setup)
        .add_loopless_state(GameState::Splash);

    app.add_plugin(plugins::config::ConfigPlugin)
        .add_plugin(plugins::connection_check::ConnectionCheckPlugin)
        .add_plugin(plugins::phases::splash::SplashPlugin)
        .add_plugin(plugins::phases::loading::LoadingPlugin)
        .add_plugin(plugins::menu::MenuPlugin);

    app.run();
}

fn setup(mut commands: Commands) {
    // Spawn a camera
    commands.spawn(Camera3dBundle::default());

    // Load in a stylesheet for the UI
    commands.add(StyleSheet::load("ui.ess"));
}

/// Utility function do despawn an entity and all its children
pub fn despawn_screen<T: Component>(to_despawn: Query<Entity, With<T>>, mut commands: Commands) {
    for entity in &to_despawn {
        commands.entity(entity).despawn_recursive();
    }
}

/// Utility function to remove UI nodes, which is usually just one node
/// NOTE: So, UI shows up as just nodes that don't have parents, so this
///       works mighty fine, at least for now.
///       MAY break something in the future, but that's why this note is here.
pub fn remove_ui(mut commands: Commands, nodes: Query<Entity, (With<Node>, Without<Parent>)>) {
    for node in &nodes {
        commands.entity(node).despawn_recursive();
    }
}