DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

506419d0e21bb692061a0b992e9484bccf915e0f — Jonni Liljamo 1 year, 9 months ago dcccd66
feat!(client, shared): move api calls to shared, dep shuffle,
and remove connection check stage
21 files changed, 46 insertions(+), 124 deletions(-)

M Cargo.lock
M client/Cargo.toml
M client/src/main.rs
D client/src/plugins/connection_check/mod.rs
M client/src/plugins/menu/mod.rs
M client/src/plugins/mod.rs
M client/src/runtime/game/mod.rs
M client/src/runtime/menu/mod.rs
M shared/Cargo.toml
R client/src/api/game/all_forming.rs => shared/src/api/game/all_forming.rs
R client/src/api/game/create.rs => shared/src/api/game/create.rs
R client/src/api/game/info.rs => shared/src/api/game/info.rs
R client/src/api/game/join.rs => shared/src/api/game/join.rs
R client/src/api/game/mod.rs => shared/src/api/game/mod.rs
R client/src/api/game/mygames.rs => shared/src/api/game/mygames.rs
R client/src/api/game/patchstate.rs => shared/src/api/game/patchstate.rs
R client/src/api/game/types.rs => shared/src/api/game/types.rs
R client/src/api/mod.rs => shared/src/api/mod.rs
R client/src/api/user/mod.rs => shared/src/api/user/mod.rs
R client/src/api/user/types.rs => shared/src/api/user/types.rs
M shared/src/lib.rs
M Cargo.lock => Cargo.lock +2 -2
@@ 1865,10 1865,8 @@ dependencies = [
 "iyes_loopless",
 "naia-bevy-client",
 "proc-macro2",
 "reqwest",
 "serde",
 "serde_json",
 "serde_repr",
 "shared",
 "toml 0.7.1",
]


@@ 5622,7 5620,9 @@ name = "shared"
version = "0.1.0"
dependencies = [
 "naia-bevy-shared",
 "reqwest",
 "serde",
 "serde_repr",
 "thiserror",
]


M client/Cargo.toml => client/Cargo.toml +0 -4
@@ 41,13 41,9 @@ iyes_loopless = "0.9.1"
# NOTE: locked into a commit, since they don't have a crates.io release yet
belly = { git = "https://github.com/jkb0o/belly", rev = "bf05d3b" }

# http requests
reqwest = { version = "0.11.14", features = ["blocking", "json"] }

# (de)serialization
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
serde_repr = "0.1.10"

# futures for async
futures-lite = "1.12.0"

M client/src/main.rs => client/src/main.rs +0 -2
@@ 26,7 26,6 @@ use naia_bevy_client::{

use laurelin_shared::server::protocol::protocol;

mod api;
mod cfg;
mod constants;
//mod lua;


@@ 101,7 100,6 @@ fn main() {
        .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);

D client/src/plugins/connection_check/mod.rs => client/src/plugins/connection_check/mod.rs +0 -76
@@ 1,76 0,0 @@
/*
 * 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::*,
    tasks::{AsyncComputeTaskPool, Task},
};
use bevy_console::PrintConsoleLine;

use futures_lite::future;

use crate::{api, cfg::CfgDev};

/// This plugin will check if we can connect to the API
pub struct ConnectionCheckPlugin;

impl Plugin for ConnectionCheckPlugin {
    fn build(&self, app: &mut App) {
        app
            // Start the check at the start
            .add_startup_system(start_connection_check)
            .add_system(handle_connection_check);
    }
}

#[derive(Component)]
struct ConnectionCheck(Task<Result<api::APIInfo, String>>);

fn start_connection_check(mut commands: Commands, cfg_dev: Res<CfgDev>) {
    let api_address = cfg_dev.api_server.clone();
    let thread_pool = AsyncComputeTaskPool::get();
    let task = thread_pool.spawn(async move {
        let api_info = api::info(api_address);

        api_info
    });
    commands.spawn(ConnectionCheck(task));
}

fn handle_connection_check(
    mut commands: Commands,
    mut connection_check_tasks: Query<(Entity, &mut ConnectionCheck)>,
    mut console: EventWriter<PrintConsoleLine>,
) {
    for (entity, mut task) in &mut connection_check_tasks {
        if let Some(res) = future::block_on(future::poll_once(&mut task.0)) {
            match res {
                Ok(api_info) => {
                    console.send(PrintConsoleLine::new(
                        "API connection check passed".to_string().into(),
                    ));
                    console.send(PrintConsoleLine::new(
                        format!("API version: {}", api_info.ver).into(),
                    ));
                }
                Err(err) => {
                    console.send(PrintConsoleLine::new(
                        "API connection check FAILED with following error:"
                            .to_string()
                            .into(),
                    ));
                    console.send(PrintConsoleLine::new(err.into()));
                }
            }

            // Remove the task, since it's done now
            commands.entity(entity).remove::<ConnectionCheck>();
            commands.entity(entity).despawn_recursive();
        }
    }
}

M client/src/plugins/menu/mod.rs => client/src/plugins/menu/mod.rs +26 -26
@@ 17,16 17,16 @@ use mainmenuscreen::*;
mod settingsscreen;
use settingsscreen::*;

mod accountscreenloggedout;
use accountscreenloggedout::*;
//mod accountscreenloggedout;
//use accountscreenloggedout::*;

mod accountscreenloggedin;
use accountscreenloggedin::*;
//mod accountscreenloggedin;
//use accountscreenloggedin::*;

mod accountlogin;
mod accountregister;
//mod accountlogin;
//mod accountregister;

mod play;
//mod play;

pub struct MenuPlugin;



@@ 48,28 48,28 @@ impl Plugin for MenuPlugin {
                    .with_system(handle_to_account_event.run_on_event::<ToAccountEvent>())
                    .with_system(handle_exit_event.run_on_event::<ExitEvent>())
                    .into()
            )
            // Systems for the settings screen
            .add_enter_system(MenuState::Settings, settings_setup)
            .add_exit_system(MenuState::Settings, remove_ui)
            // Systems for account loggedout screen
            .add_enter_system(MenuState::AccountLoggedOut, account_loggedout_setup)
            .add_exit_system(MenuState::AccountLoggedOut, remove_ui)
            // Systems for account loggedin screen
            .add_enter_system(MenuState::AccountLoggedIn, account_loggedin_setup)
            .add_exit_system(MenuState::AccountLoggedIn, remove_ui)
            .add_event::<LogoutEvent>()
            .add_system_set(
                ConditionSet::new()
                    .run_in_state(MenuState::AccountLoggedIn)
                    .with_system(handle_logout_event.run_on_event::<LogoutEvent>())
                    .into()
            );
        // Systems for the settings screen
        //.add_enter_system(MenuState::Settings, settings_setup)
        //.add_exit_system(MenuState::Settings, remove_ui)
        // Systems for account loggedout screen
        //.add_enter_system(MenuState::AccountLoggedOut, account_loggedout_setup)
        //.add_exit_system(MenuState::AccountLoggedOut, remove_ui)
        // Systems for account loggedin screen
        //.add_enter_system(MenuState::AccountLoggedIn, account_loggedin_setup)
        //.add_exit_system(MenuState::AccountLoggedIn, remove_ui)
        //.add_event::<LogoutEvent>()
        //.add_system_set(
        //    ConditionSet::new()
        //        .run_in_state(MenuState::AccountLoggedIn)
        //        .with_system(handle_logout_event.run_on_event::<LogoutEvent>())
        //        .into()
        //);

        app.add_plugin(accountregister::AccountRegisterPlugin)
            .add_plugin(accountlogin::AccountLoginPlugin);
        //app.add_plugin(accountregister::AccountRegisterPlugin)
        //    .add_plugin(accountlogin::AccountLoginPlugin);

        app.add_plugin(play::PlayMenuPlugin);
        //app.add_plugin(play::PlayMenuPlugin);
    }
}


M client/src/plugins/mod.rs => client/src/plugins/mod.rs +0 -1
@@ 7,6 7,5 @@
 */

pub mod config;
pub mod connection_check;
pub mod menu;
pub mod phases;

M client/src/runtime/game/mod.rs => client/src/runtime/game/mod.rs +1 -1
@@ 8,7 8,7 @@

use bevy::prelude::Resource;

use crate::api::game::types::Game;
use laurelin_shared::api::game::types::Game;

/// Runtime data for use when in game
#[derive(Resource)]

M client/src/runtime/menu/mod.rs => client/src/runtime/menu/mod.rs +1 -1
@@ 8,7 8,7 @@

use bevy::prelude::Resource;

use crate::api::game::types::Game;
use laurelin_shared::api::game::types::Game;

/// Runtime data for use in the menu
#[derive(Resource)]

M shared/Cargo.toml => shared/Cargo.toml +4 -0
@@ 14,6 14,10 @@ naia-bevy-shared = "0.18.0"

thiserror = "1.0.38"

reqwest = { version = "0.11.14", features = ["blocking", "json"] }

serde_repr = "0.1.10"

[dependencies.serde]
version = "1.0.152"
default-features = false

R client/src/api/game/all_forming.rs => shared/src/api/game/all_forming.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/create.rs => shared/src/api/game/create.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/info.rs => shared/src/api/game/info.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/join.rs => shared/src/api/game/join.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/mod.rs => shared/src/api/game/mod.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/mygames.rs => shared/src/api/game/mygames.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/patchstate.rs => shared/src/api/game/patchstate.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/game/types.rs => shared/src/api/game/types.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/mod.rs => shared/src/api/mod.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/user/mod.rs => shared/src/api/user/mod.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

R client/src/api/user/types.rs => shared/src/api/user/types.rs +1 -1
@@ 1,5 1,5 @@
/*
 * This file is part of laurelin/client
 * This file is part of laurelin/shared
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.

M shared/src/lib.rs => shared/src/lib.rs +1 -0
@@ 6,5 6,6 @@
 * See LICENSE for licensing information.
 */

pub mod api;
pub mod error;
pub mod server;