feat: huge refactor to data acessing, some API changes

This commit is contained in:
2026-03-23 14:52:53 -04:00
Unverified
parent c5738741f1
commit 12c5c675e2
6 changed files with 258 additions and 323 deletions

View File

@@ -61,32 +61,30 @@ pub struct Match {
pub id: u32,
pub demo_mode: bool,
pub board: Vec<Vec<Color>>,
pub viewers: Vec<SocketAddr>,
pub ledger: Vec<(Color, usize, Instant)>,
pub wait_thread: Option<tokio::task::JoinHandle<()>>,
pub timeout_thread: Option<tokio::task::JoinHandle<()>>,
pub player1: SocketAddr,
pub player2: SocketAddr,
pub player1: String,
pub player2: String,
}
impl Match {
pub fn new(id: u32, player1: SocketAddr, player2: SocketAddr, demo_mode: bool) -> Match {
let first = if rand::rng().random_range(0..=1) == 0 {
player1.to_string().parse().unwrap()
pub fn new(id: u32, player1: String, player2: String, demo_mode: bool) -> Match {
let (first_player, second_player) = if rand::rng().random_range(0..=1) == 0 {
(player1, player2)
} else {
player2.to_string().parse().unwrap()
(player2, player1)
};
Match {
id,
demo_mode,
board: vec![vec![Color::None; 6]; 7],
viewers: Vec::new(),
ledger: Vec::new(),
wait_thread: None,
timeout_thread: None,
player1: if player1 == first { player1 } else { player2 },
player2: if player1 == first { player2 } else { player1 },
player1: first_player,
player2: second_player,
}
}