From e8e1276a35ebfeeb0439849fd89eb3ca3b9f90be Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 17 May 2023 13:02:04 +0300 Subject: [PATCH] feat(client): kinda cleanup seed_gen usage --- client/src/api/game/mod.rs | 10 ++++++++-- client/src/game_status/parser.rs | 2 +- client/src/plugins/game/hand/mod.rs | 4 ++-- client/src/plugins/game/supply/mod.rs | 4 ++-- client/src/plugins/game/ui/mod.rs | 12 ++++++------ client/src/plugins/game/ui/state_button.rs | 6 +++--- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index 439e724..7d26c64 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -10,7 +10,7 @@ use bevy::reflect::{Reflect, FromReflect}; use serde::{Deserialize, Serialize}; use serde_repr::Deserialize_repr; -use crate::game_status::{Card, PlayerState}; +use crate::{game_status::{Card, PlayerState}, seed_gen}; use super::user::User; @@ -83,7 +83,13 @@ pub struct Action { } impl Action { - pub fn new(game_id: &str, invoker: &str, target: &str, command: &Command, seed: u64) -> Self { + pub fn new(game_id: &str, invoker: &str, target: &str, command: &Command, seed: Option) -> Self { + let seed = if seed.is_none() { + seed_gen!() + } else { + seed.unwrap() + }; + Self { id: "".to_string(), created_at: chrono::Utc::now(), diff --git a/client/src/game_status/parser.rs b/client/src/game_status/parser.rs index 9029cf4..29705f1 100644 --- a/client/src/game_status/parser.rs +++ b/client/src/game_status/parser.rs @@ -89,7 +89,7 @@ pub fn parse(game: &Game) -> Result { macro_rules! current_seed { ($action:ident) => { - $action.seed.parse::().unwrap() + Some($action.seed.parse::().unwrap()) }; } diff --git a/client/src/plugins/game/hand/mod.rs b/client/src/plugins/game/hand/mod.rs index 336aac5..1be6d93 100644 --- a/client/src/plugins/game/hand/mod.rs +++ b/client/src/plugins/game/hand/mod.rs @@ -14,7 +14,7 @@ use crate::{ api::game::{Action, Command}, game_status::PlayerState, plugins::GameActionCreateCallEvent, - seed_gen, Global, + Global, }; use super::{ @@ -153,7 +153,7 @@ fn handle_clicked_hand_card( &global.user.as_ref().unwrap().id, &global.user.as_ref().unwrap().id, &Command::PlayCard { index: card_kind.0 }, - seed_gen!(), + None, ), }); } diff --git a/client/src/plugins/game/supply/mod.rs b/client/src/plugins/game/supply/mod.rs index c574df9..a329b99 100644 --- a/client/src/plugins/game/supply/mod.rs +++ b/client/src/plugins/game/supply/mod.rs @@ -14,7 +14,7 @@ use crate::{ api::game::{Action, Command}, game_status::PlayerState, plugins::GameActionCreateCallEvent, - seed_gen, Global, + Global, }; use super::{ @@ -179,7 +179,7 @@ fn handle_clicked_supply_pile( index: card_kind.0, for_cost: card.card.cost, }, - seed_gen!(), + None, ), }); } diff --git a/client/src/plugins/game/ui/mod.rs b/client/src/plugins/game/ui/mod.rs index 5729304..996ddf1 100644 --- a/client/src/plugins/game/ui/mod.rs +++ b/client/src/plugins/game/ui/mod.rs @@ -13,7 +13,7 @@ use crate::{ api::game::{Action, Command, Game}, game_status::{Card, CardAction, PlayerState}, plugins::GameActionCreateCallEvent, - seed_gen, AppState, Global, + AppState, Global, }; use super::{GameData, RefreshGameEvent}; @@ -428,7 +428,7 @@ fn hardcoded_init(game: &Game, create_action_ev_w: &mut EventWriter