DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

52e20a058bd65415203bbce44fb27ddcf4d43972 — Jonni Liljamo 1 year, 5 months ago 77fd1fd
feat(client): use chrono for game and action times
4 files changed, 189 insertions(+), 59 deletions(-)

M Cargo.lock
M client/Cargo.toml
M client/src/api/game/mod.rs
M client/src/plugins/menu/ui/browse.rs
M Cargo.lock => Cargo.lock +140 -4
@@ 56,7 56,7 @@ dependencies = [
 "arrayvec",
 "once_cell",
 "paste",
 "windows",
 "windows 0.44.0",
]

[[package]]


@@ 1144,6 1144,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"

[[package]]
name = "chrono"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
dependencies = [
 "iana-time-zone",
 "js-sys",
 "num-integer",
 "num-traits",
 "serde",
 "time",
 "wasm-bindgen",
 "winapi",
]

[[package]]
name = "chrono-humanize"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32dce1ea1988dbdf9f9815ff11425828523bd2a134ec0805d2ac8af26ee6096e"
dependencies = [
 "chrono",
]

[[package]]
name = "clipboard-win"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1281,6 1306,50 @@ dependencies = [
]

[[package]]
name = "cxx"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93"
dependencies = [
 "cc",
 "cxxbridge-flags",
 "cxxbridge-macro",
 "link-cplusplus",
]

[[package]]
name = "cxx-build"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b"
dependencies = [
 "cc",
 "codespan-reporting",
 "once_cell",
 "proc-macro2",
 "quote",
 "scratch",
 "syn 2.0.15",
]

[[package]]
name = "cxxbridge-flags"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb"

[[package]]
name = "cxxbridge-macro"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [
 "proc-macro2",
 "quote",
 "syn 2.0.15",
]

[[package]]
name = "d3d12"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 1638,7 1707,7 @@ dependencies = [
 "cfg-if",
 "js-sys",
 "libc",
 "wasi",
 "wasi 0.11.0+wasi-snapshot-preview1",
 "wasm-bindgen",
]



@@ 1716,7 1785,7 @@ dependencies = [
 "log",
 "thiserror",
 "winapi",
 "windows",
 "windows 0.44.0",
]

[[package]]


@@ 1896,6 1965,30 @@ dependencies = [
]

[[package]]
name = "iana-time-zone"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
dependencies = [
 "android_system_properties",
 "core-foundation-sys",
 "iana-time-zone-haiku",
 "js-sys",
 "wasm-bindgen",
 "windows 0.48.0",
]

[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
 "cxx",
 "cxx-build",
]

[[package]]
name = "idna"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 2029,6 2122,8 @@ dependencies = [
 "bevy",
 "bevy_editor_pls",
 "bevy_egui",
 "chrono",
 "chrono-humanize",
 "fastrand",
 "futures-lite",
 "reqwest",


@@ 2060,6 2155,15 @@ dependencies = [
]

[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
 "cc",
]

[[package]]
name = "linux-raw-sys"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 2164,7 2268,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
dependencies = [
 "libc",
 "log",
 "wasi",
 "wasi 0.11.0+wasi-snapshot-preview1",
 "windows-sys 0.45.0",
]



@@ 2819,6 2923,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"

[[package]]
name = "scratch"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"

[[package]]
name = "security-framework"
version = "2.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 3096,6 3206,17 @@ dependencies = [
]

[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
 "libc",
 "wasi 0.10.0+wasi-snapshot-preview1",
 "winapi",
]

[[package]]
name = "tinyvec"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 3358,6 3479,12 @@ dependencies = [

[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"

[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"


@@ 3630,6 3757,15 @@ dependencies = [
]

[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
 "windows-targets 0.48.0",
]

[[package]]
name = "windows-implement"
version = "0.44.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

M client/Cargo.toml => client/Cargo.toml +3 -0
@@ 20,6 20,9 @@ serde_json = "1.0.96"

fastrand = "1.9.0"

chrono = { version = "0.4.24", features = [ "serde" ] }
chrono-humanize = "0.2.2"

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

M client/src/api/game/mod.rs => client/src/api/game/mod.rs +7 -7
@@ 49,8 49,8 @@ pub enum Command {
#[derive(Deserialize, Serialize, Clone)]
pub struct Action {
    pub id: String,
    pub created_at: String,
    pub updated_at: String,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub game_id: String,
    pub invoker: String,
    pub target: String,


@@ 69,8 69,8 @@ impl Action {
    ) -> Self {
        Self {
            id: "".to_string(),
            created_at: "".to_string(),
            updated_at: "".to_string(),
            created_at: chrono::Utc::now(),
            updated_at: chrono::Utc::now(),
            game_id: game_id.to_string(),
            invoker: invoker.to_string(),
            target: target.to_string(),


@@ 92,9 92,9 @@ pub enum GameState {
#[derive(Deserialize, Clone)]
pub struct Game {
    pub id: String,
    pub created_at: String,
    pub updated_at: String,
    pub ended_at: String,
    pub created_at: chrono::DateTime<chrono::Utc>,
    pub updated_at: chrono::DateTime<chrono::Utc>,
    pub ended_at: chrono::DateTime<chrono::Utc>,
    pub host_id: String,
    pub host: Option<User>,
    pub guest_id: String,

M client/src/plugins/menu/ui/browse.rs => client/src/plugins/menu/ui/browse.rs +39 -48
@@ 13,7 13,7 @@ use crate::{plugins::{
    GameCreateCallEvent, BrowseState, 
    GameFormingCallEvent, GameMyGamesCallEvent,
    GameJoinCallEvent, menu::MenuState
}, api::game::GameState, Global, AppState};
}, api::game::{GameState, Game}, Global, AppState};

use super::{MenuData, MenuUIState};



@@ 79,54 79,26 @@ pub fn view(
        egui::ScrollArea::vertical().show(ui, |ui| match data.browse_state {
            BrowseState::Forming => {
                for game in &data.forming_games {
                    egui::Frame::none()
                        .fill(egui::Color32::BLACK)
                        .rounding(4.)
                        .outer_margin(4.)
                        .inner_margin(4.)
                        .show(ui, |ui| {
                            ui.horizontal(|ui| {
                                ui.label(format!(
                                        "Host: {}",
                                        game.host.as_ref().unwrap().username
                                    ));

                                ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
                                    if game.host_id == global.user.as_ref().unwrap().id {
                                        ui.add_enabled(false, egui::Button::new("Host"));
                                    } else if ui.button("Join").clicked() {
                                        join_ev_w.send(GameJoinCallEvent {
                                            game_id: game.id.clone(),
                                        });
                                    }
                                });
                    game_row(ui, game, |ui| {
                        if game.host_id == global.user.as_ref().unwrap().id {
                            ui.add_enabled(false, egui::Button::new("Host"));
                        } else if ui.button("Join").clicked() {
                            join_ev_w.send(GameJoinCallEvent {
                                game_id: game.id.clone(),
                            });
                        });
                        }
                    });
                }
            }
            BrowseState::InProgress => {
                let mut games = data.my_games.clone();
                games.retain(|g| g.state == GameState::InProgress);
                for game in &games {
                    egui::Frame::none()
                        .fill(egui::Color32::BLACK)
                        .rounding(4.)
                        .outer_margin(4.)
                        .inner_margin(4.)
                        .show(ui, |ui| {
                            ui.horizontal(|ui| {
                                ui.label(format!(
                                        "Host: {}",
                                        game.host.as_ref().unwrap().username
                                    ));

                                ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
                                    if ui.button("Enter").clicked() {
                                        enter_game(&mut commands, &mut global, &game.id);
                                    }
                                });
                            });
                        });
                    game_row(ui, game, |ui| {
                        if ui.button("Enter").clicked() {
                            enter_game(&mut commands, &mut global, &game.id);
                        }
                    });
                }
            }
            BrowseState::Finished => {


@@ 139,12 111,7 @@ pub fn view(
                        .outer_margin(4.)
                        .inner_margin(4.)
                        .show(ui, |ui| {
                            ui.horizontal(|ui| {
                                ui.label(format!(
                                        "Host: {}",
                                        game.host.as_ref().unwrap().username
                                    ));
                            });
                            game_row(ui, game, |_| {});
                        });
                }
            }


@@ 153,6 120,30 @@ pub fn view(
    });
}

fn game_row(ui: &mut egui::Ui, game: &Game, buttons: impl FnOnce(&mut egui::Ui)) {
    egui::Frame::none()
        .fill(egui::Color32::BLACK)
        .rounding(4.)
        .outer_margin(4.)
        .inner_margin(4.)
        .show(ui, |ui| {
            ui.horizontal(|ui| {
                ui.label(format!(
                        "Host: {}",
                        game.host.as_ref().unwrap().username
                        ));
                ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
                    buttons(ui);

                    ui.label(format!(
                            "{}",
                            chrono_humanize::HumanTime::from(game.created_at)
                            ));
                });
            });
        });
}

fn enter_game(commands: &mut Commands, global: &mut Global, game_id: &str) {
    global.cur_game_id = game_id.to_string();