DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

640a3e9a168df2322ac522c4242d377bb5d0d44f — Jonni Liljamo 1 year, 10 months ago 6022bb9
feat!(sdbclient): scrap game management UIs
8 files changed, 85 insertions(+), 236 deletions(-)

D sdbclient/src/plugins/menu/play/browsegames.rs
D sdbclient/src/plugins/menu/play/creategame.rs
D sdbclient/src/plugins/menu/play/inlobbyguest.rs
D sdbclient/src/plugins/menu/play/inlobbyhost.rs
D sdbclient/src/plugins/menu/play/main.rs
M sdbclient/src/plugins/menu/play/mod.rs
A sdbclient/src/plugins/menu/play/ui.rs
M sdbclient/src/runtime/menu/mod.rs
D sdbclient/src/plugins/menu/play/browsegames.rs => sdbclient/src/plugins/menu/play/browsegames.rs +0 -31
@@ 1,31 0,0 @@
/*
 * 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::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use super::PlayMenuState;

pub(super) fn setup(mut commands: Commands) {
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Browse"
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::Main))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

D sdbclient/src/plugins/menu/play/creategame.rs => sdbclient/src/plugins/menu/play/creategame.rs +0 -74
@@ 1,74 0,0 @@
/*
 * 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::*,
    tasks::{AsyncComputeTaskPool, Task},
};
use futures_lite::future;
use iyes_loopless::prelude::*;

use belly::prelude::*;
use bevy_console::PrintConsoleLine;

use crate::{
    api::{self, game::ResponseCreateGame},
    cfg::{CfgDev, CfgUser},
};

use super::PlayMenuState;

pub(super) fn setup(mut commands: Commands) {
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Create"
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::Main))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

struct CreateGameCallResponse {
    game: ResponseCreateGame,
}

#[derive(Component)]
struct CreateGameCall(Task<CreateGameCallResponse>);

fn start_create_game_call(mut commands: Commands, cfg_dev: Res<CfgDev>, cfg_user: Res<CfgUser>) {
    let api_address = cfg_dev.api_server.clone();
    let token = cfg_user.user_token.clone();

    let thread_pool = AsyncComputeTaskPool::get();
    let task = thread_pool.spawn(async move {
        let create_game_response = api::game::creategame(api_address.clone(), token.clone());

        CreateGameCallResponse {
            game: create_game_response,
        }
    });
    commands.spawn(CreateGameCall(task));
}

fn handle_create_game_call(
    mut commands: Commands,
    mut create_game_tasks: Query<(Entity, &mut CreateGameCall)>,
    mut console: EventWriter<PrintConsoleLine>,
) {
    let (entity, mut task) = create_game_tasks.single_mut();
    if let Some(create_game_call_response) = future::block_on(future::poll_once(&mut task.0)) {
        todo!();
    }
}

D sdbclient/src/plugins/menu/play/inlobbyguest.rs => sdbclient/src/plugins/menu/play/inlobbyguest.rs +0 -31
@@ 1,31 0,0 @@
/*
 * 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::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use super::PlayMenuState;

pub(super) fn setup(mut commands: Commands) {
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Lobby (Guest)"
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::BrowseGames))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

D sdbclient/src/plugins/menu/play/inlobbyhost.rs => sdbclient/src/plugins/menu/play/inlobbyhost.rs +0 -31
@@ 1,31 0,0 @@
/*
 * 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::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use super::PlayMenuState;

pub(super) fn setup(mut commands: Commands) {
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Lobby (Host)"
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::BrowseGames))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

D sdbclient/src/plugins/menu/play/main.rs => sdbclient/src/plugins/menu/play/main.rs +0 -41
@@ 1,41 0,0 @@
/*
 * 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::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use super::{MenuState, PlayMenuState};

pub(super) fn setup(mut commands: Commands) {
    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Play"
                </span>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::CreateGame))
                })>
                    "Create"
                </button>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(PlayMenuState::BrowseGames))
                })>
                    "Join"
                </button>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(MenuState::Main))
                })>
                    "Back"
                </button>
            </div>
        </body>
    });
}

M sdbclient/src/plugins/menu/play/mod.rs => sdbclient/src/plugins/menu/play/mod.rs +9 -28
@@ 9,15 9,9 @@
use bevy::prelude::*;
use iyes_loopless::prelude::*;

use crate::remove_ui;

use super::MenuState;

mod browsegames;
mod creategame;
mod inlobbyguest;
mod inlobbyhost;
mod main;
mod ui;

pub(super) struct PlayMenuPlugin;



@@ 25,21 19,12 @@ impl Plugin for PlayMenuPlugin {
    fn build(&self, app: &mut App) {
        app.add_loopless_state(PlayMenuState::None)
            .add_enter_system(MenuState::Play, play_menu_setup)
            // Systems for main play menu
            .add_enter_system(PlayMenuState::Main, main::setup)
            .add_exit_system(PlayMenuState::Main, remove_ui)
            // Systems for create game menu
            .add_enter_system(PlayMenuState::CreateGame, creategame::setup)
            .add_exit_system(PlayMenuState::CreateGame, remove_ui)
            // Systems for browse games menu
            .add_enter_system(PlayMenuState::BrowseGames, browsegames::setup)
            .add_exit_system(PlayMenuState::BrowseGames, remove_ui)
            // Systems for in lobby host menu
            .add_enter_system(PlayMenuState::InLobbyHost, inlobbyhost::setup)
            .add_exit_system(PlayMenuState::InLobbyHost, remove_ui)
            // Systems for in lobby guest menu
            .add_enter_system(PlayMenuState::InLobbyGuest, inlobbyguest::setup)
            .add_exit_system(PlayMenuState::InLobbyGuest, remove_ui);
            .add_system_set(
                ConditionSet::new()
                    .run_in_state(PlayMenuState::Visible)
                    .with_system(ui::show)
                    .into(),
            );
    }
}



@@ 47,13 32,9 @@ impl Plugin for PlayMenuPlugin {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(super) enum PlayMenuState {
    None,
    Main,
    CreateGame,
    BrowseGames,
    InLobbyHost,
    InLobbyGuest,
    Visible,
}

fn play_menu_setup(mut commands: Commands) {
    commands.insert_resource(NextState(PlayMenuState::Main))
    commands.insert_resource(NextState(PlayMenuState::Visible))
}

A sdbclient/src/plugins/menu/play/ui.rs => sdbclient/src/plugins/menu/play/ui.rs +66 -0
@@ 0,0 1,66 @@
/*
 * 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::*;
use bevy_inspector_egui::bevy_egui::{egui, EguiContext};
use iyes_loopless::prelude::*;

use crate::{
    plugins::menu::MenuState,
    runtime::menu::{PlayMenuUIState, RTDMenu},
};

pub(super) fn show(
    mut commands: Commands,
    mut egui_context: ResMut<EguiContext>,
    mut rtdmenu: ResMut<RTDMenu>,
) {
    egui::Window::new("Play")
        .resizable(false)
        .collapsible(false)
        .anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
        .show(egui_context.ctx_mut(), |ui| {
            ui.label("fuck");

            match rtdmenu.play_menu_ui_state {
                PlayMenuUIState::Main => {
                    if ui.button("Create").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::CreateGame
                    }

                    if ui.button("Browse").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::BrowseGames
                    }

                    if ui.button("Back").clicked() {
                        commands.insert_resource(NextState(MenuState::Main))
                    }
                }
                PlayMenuUIState::CreateGame => {
                    if ui.button("Back").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::Main
                    }
                }
                PlayMenuUIState::BrowseGames => {
                    if ui.button("Back").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::Main
                    }
                }
                PlayMenuUIState::InLobbyHost => {
                    if ui.button("Back").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::Main
                    }
                }
                PlayMenuUIState::InLobbyGuest => {
                    if ui.button("Back").clicked() {
                        rtdmenu.play_menu_ui_state = PlayMenuUIState::Main
                    }
                }
            }
        });
}

M sdbclient/src/runtime/menu/mod.rs => sdbclient/src/runtime/menu/mod.rs +10 -0
@@ 11,6 11,7 @@ use bevy::prelude::Resource;
/// Runtime data for use in the menu
#[derive(Resource)]
pub(crate) struct RTDMenu {
    pub play_menu_ui_state: PlayMenuUIState,
    /// Current game ID, for showing lobby data etc
    pub cur_game_id: String,
}


@@ 18,7 19,16 @@ pub(crate) struct RTDMenu {
impl Default for RTDMenu {
    fn default() -> Self {
        Self {
            play_menu_ui_state: PlayMenuUIState::Main,
            cur_game_id: String::from(""),
        }
    }
}

pub(crate) enum PlayMenuUIState {
    Main,
    CreateGame,
    BrowseGames,
    InLobbyHost,
    InLobbyGuest,
}