DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

dfcae52675dc9372a0ee45fda5350876ebdd9ae5 — Jonni Liljamo 1 year, 8 months ago 83c6d89
feat(client): change users_cache to a HashMap, instead of a Vec
M client/src/main.rs => client/src/main.rs +2 -2
@@ 52,7 52,7 @@ pub enum GameState {

#[derive(Resource)]
pub struct Global {
    pub users_cache: Vec<UserPub>,
    pub users_cache: HashMap<String, UserPub>,
    /// stores ids of users currently in queue to be gotten
    pub users_cache_queue: Vec<String>,
    pub games_cache: HashMap<String, GamePub>,


@@ 111,7 111,7 @@ fn main() {
    //app.add_plugin(ScriptingPlugin).add_plugin(lua::LuaPlugin);

    app.insert_resource(Global {
        users_cache: vec![],
        users_cache: HashMap::new(),
        users_cache_queue: vec![],
        games_cache: HashMap::new(),
        games_cache_queue: vec![],

M client/src/plugins/menu/ui/play/ui.rs => client/src/plugins/menu/ui/play/ui.rs +13 -39
@@ 137,11 137,7 @@ pub fn ui(
                    "Host: {}",
                    global
                        .users_cache
                        .iter()
                        .filter(|u| u.id == global.cur_game.as_ref().unwrap().host_id)
                        .cloned()
                        .collect::<Vec<UserPub>>()
                        .first()
                        .get(&global.cur_game.as_ref().unwrap().host_id)
                        .unwrap_or(&UserPub {
                            id: "".to_string(),
                            created_at: "".to_string(),


@@ 154,18 150,15 @@ pub fn ui(
                    "Guest: {}",
                    global
                        .users_cache
                        .iter()
                        .filter(|u| &u.id
                            == global
                        .get(
                            global
                                .cur_game
                                .as_ref()
                                .unwrap()
                                .guest_id
                                .as_ref()
                                .unwrap_or(&"".to_string()))
                        .cloned()
                        .collect::<Vec<UserPub>>()
                        .first()
                                .unwrap_or(&"".to_string())
                        )
                        .unwrap_or(&UserPub {
                            id: "".to_string(),
                            created_at: "".to_string(),


@@ 187,11 180,7 @@ pub fn ui(
                    "Host: {}",
                    global
                        .users_cache
                        .iter()
                        .filter(|u| u.id == global.cur_game.as_ref().unwrap().host_id)
                        .cloned()
                        .collect::<Vec<UserPub>>()
                        .first()
                        .get(&global.cur_game.as_ref().unwrap().host_id)
                        .unwrap_or(&UserPub {
                            id: "".to_string(),
                            created_at: "".to_string(),


@@ 204,18 193,15 @@ pub fn ui(
                    "Guest: {}",
                    global
                        .users_cache
                        .iter()
                        .filter(|u| &u.id
                            == global
                        .get(
                            global
                                .cur_game
                                .as_ref()
                                .unwrap()
                                .guest_id
                                .as_ref()
                                .unwrap_or(&"".to_string()))
                        .cloned()
                        .collect::<Vec<UserPub>>()
                        .first()
                                .unwrap_or(&"".to_string())
                        )
                        .unwrap_or(&UserPub {
                            id: "".to_string(),
                            created_at: "".to_string(),


@@ 271,11 257,7 @@ fn browse_forming(
                            "Host: {}",
                            global
                                .users_cache
                                .iter()
                                .filter(|u| u.id == game.host_id)
                                .cloned()
                                .collect::<Vec<UserPub>>()
                                .first()
                                .get(&game.host_id)
                                .unwrap_or(&UserPub {
                                    id: "".to_string(),
                                    created_at: "".to_string(),


@@ 346,11 328,7 @@ fn browse_inprogress(
                            "Host: {}",
                            global
                                .users_cache
                                .iter()
                                .filter(|u| u.id == game.host_id)
                                .cloned()
                                .collect::<Vec<UserPub>>()
                                .first()
                                .get(&game.host_id)
                                .unwrap_or(&UserPub {
                                    id: "".to_string(),
                                    created_at: "".to_string(),


@@ 409,11 387,7 @@ fn browse_finished(
                            "Host: {}",
                            global
                                .users_cache
                                .iter()
                                .filter(|u| u.id == game.host_id)
                                .cloned()
                                .collect::<Vec<UserPub>>()
                                .first()
                                .get(&game.host_id)
                                .unwrap_or(&UserPub {
                                    id: "".to_string(),
                                    created_at: "".to_string(),

M client/src/plugins/networking/systems/events/receive/mod.rs => client/src/plugins/networking/systems/events/receive/mod.rs +1 -1
@@ 149,7 149,7 @@ pub fn message_events(
                    let user: UserPub =
                        serde_json::from_str(response.data.unwrap().get(0).unwrap()).unwrap();
                    global.users_cache_queue.retain(|id| id != &user.id);
                    global.users_cache.push(user);
                    global.users_cache.insert(user.id.clone(), user);
                }
            }
        }

M client/src/plugins/networking/systems/events/send/user.rs => client/src/plugins/networking/systems/events/send/user.rs +4 -14
@@ 7,12 7,9 @@
 */

use bevy::prelude::{EventReader, ResMut};
use laurelin_shared::{
    server::{
        channels::DataRequestChannel,
        messages::{DataRequest, DataRequestType},
    },
    types::user::UserPub,
use laurelin_shared::server::{
    channels::DataRequestChannel,
    messages::{DataRequest, DataRequestType},
};
use naia_bevy_client::Client;



@@ 29,14 26,7 @@ pub fn pub_user_details_event(
) {
    for ev in ev.iter() {
        // check if already in cache OR in cache queue
        if !global
            .users_cache
            .iter()
            .filter(|&u| u.id == ev.id)
            .cloned()
            .collect::<Vec<UserPub>>()
            .is_empty()
        {
        if global.users_cache.contains_key(&ev.id) {
            return;
        }