diff options
Diffstat (limited to 'src/client/games/manager.rs')
| -rw-r--r-- | src/client/games/manager.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/client/games/manager.rs b/src/client/games/manager.rs index 02e9451..4e0218b 100644 --- a/src/client/games/manager.rs +++ b/src/client/games/manager.rs | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | use super::blackjack::BlackjackGame; | ||
| 1 | use super::response::{RouletteResult, SpinResult}; | 2 | use super::response::{RouletteResult, SpinResult}; |
| 2 | use super::roulette::RouletteGame; | 3 | use super::roulette::RouletteGame; |
| 3 | use super::slots::SlotsGame; | 4 | use super::slots::SlotsGame; |
| 4 | use super::traits::{Game, GameError, GamePhase, GameState}; | 5 | use super::traits::{Game, GameError, GamePhase, GameState}; |
| 6 | use crate::blackjack::BlackjackState; | ||
| 5 | use crate::roulette::Bets; | 7 | use crate::roulette::Bets; |
| 6 | use std::collections::HashMap; | 8 | use std::collections::HashMap; |
| 7 | 9 | ||
| @@ -15,6 +17,7 @@ impl GameManager { | |||
| 15 | let mut games: HashMap<String, Box<dyn Game>> = HashMap::new(); | 17 | let mut games: HashMap<String, Box<dyn Game>> = HashMap::new(); |
| 16 | games.insert("slots".to_string(), Box::new(SlotsGame::new())); | 18 | games.insert("slots".to_string(), Box::new(SlotsGame::new())); |
| 17 | games.insert("roulette".to_string(), Box::new(RouletteGame::new())); | 19 | games.insert("roulette".to_string(), Box::new(RouletteGame::new())); |
| 20 | games.insert("blackjack".to_string(), Box::new(BlackjackGame::new())); | ||
| 18 | 21 | ||
| 19 | Self { | 22 | Self { |
| 20 | current_session: None, | 23 | current_session: None, |
| @@ -51,6 +54,9 @@ impl GameManager { | |||
| 51 | data.insert("status".to_string(), "place".to_string()); | 54 | data.insert("status".to_string(), "place".to_string()); |
| 52 | data.insert("number_input".to_string(), String::new()); | 55 | data.insert("number_input".to_string(), String::new()); |
| 53 | 0 | 56 | 0 |
| 57 | } else if game_type == "blackjack" { | ||
| 58 | data.insert("status".to_string(), "ready".to_string()); | ||
| 59 | 10 | ||
| 54 | } else { | 60 | } else { |
| 55 | 10 | 61 | 10 |
| 56 | }; | 62 | }; |
| @@ -260,6 +266,49 @@ impl GameManager { | |||
| 260 | .insert("number_input".to_string(), String::new()); | 266 | .insert("number_input".to_string(), String::new()); |
| 261 | } | 267 | } |
| 262 | 268 | ||
| 269 | pub fn apply_blackjack_state(&mut self, state: BlackjackState) { | ||
| 270 | let Some(session) = self.current_session.as_mut() else { | ||
| 271 | return; | ||
| 272 | }; | ||
| 273 | session.phase = if state.phase == "player" { | ||
| 274 | GamePhase::Playing | ||
| 275 | } else { | ||
| 276 | GamePhase::Finished | ||
| 277 | }; | ||
| 278 | session.bet_amount = state.base_bet; | ||
| 279 | session.data.remove("error"); | ||
| 280 | session | ||
| 281 | .data | ||
| 282 | .insert("balance".to_string(), state.balance.to_string()); | ||
| 283 | session.data.insert( | ||
| 284 | "status".to_string(), | ||
| 285 | if state.phase == "player" { | ||
| 286 | "player".to_string() | ||
| 287 | } else { | ||
| 288 | "done".to_string() | ||
| 289 | }, | ||
| 290 | ); | ||
| 291 | session.data.insert( | ||
| 292 | "blackjack".to_string(), | ||
| 293 | serde_json::to_string(&state).unwrap_or_default(), | ||
| 294 | ); | ||
| 295 | } | ||
| 296 | |||
| 297 | pub fn blackjack_state(&self) -> Option<BlackjackState> { | ||
| 298 | self.current_session | ||
| 299 | .as_ref() | ||
| 300 | .and_then(|session| session.data.get("blackjack")) | ||
| 301 | .and_then(|raw| serde_json::from_str(raw).ok()) | ||
| 302 | } | ||
| 303 | |||
| 304 | pub fn set_blackjack_status(&mut self, status: &str) { | ||
| 305 | if let Some(session) = self.current_session.as_mut() { | ||
| 306 | session | ||
| 307 | .data | ||
| 308 | .insert("status".to_string(), status.to_string()); | ||
| 309 | } | ||
| 310 | } | ||
| 311 | |||
| 263 | pub fn get_current_game(&self) -> Option<&dyn Game> { | 312 | pub fn get_current_game(&self) -> Option<&dyn Game> { |
| 264 | self.current_session | 313 | self.current_session |
| 265 | .as_ref() | 314 | .as_ref() |
