added optional parameters that the ui will receive from server
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use eframe::egui;
|
||||
use env_logger::Env;
|
||||
use log::{error, info, warn};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::connection::handle_connection;
|
||||
mod connection;
|
||||
@@ -83,6 +84,7 @@ enum AppState {
|
||||
Settings,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ChessApp {
|
||||
fullscreen: bool,
|
||||
resolutions: Vec<(u32, u32)>,
|
||||
@@ -93,6 +95,9 @@ struct ChessApp {
|
||||
turn: Turn,
|
||||
pending_settings: PendingSettings,
|
||||
server_port: String,
|
||||
player_color: Option<String>,
|
||||
match_id: Option<Uuid>,
|
||||
opponent_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -121,6 +126,9 @@ impl Default for ChessApp {
|
||||
turn: Turn::White,
|
||||
pending_settings: PendingSettings::default(),
|
||||
server_port: "9001".to_string(), // Default port
|
||||
player_color: None,
|
||||
match_id: None,
|
||||
opponent_name: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +226,7 @@ impl eframe::App for ChessApp {
|
||||
//create a TCPlistener with tokio and bind machine ip for connection
|
||||
tokio::spawn(async move {
|
||||
info!("tokoi");
|
||||
handle_connection(&port).await
|
||||
handle_connection(&port, self).await
|
||||
});
|
||||
|
||||
self.state = AppState::InGame;
|
||||
@@ -351,8 +359,7 @@ impl eframe::App for ChessApp {
|
||||
);
|
||||
|
||||
// Draw the chess board
|
||||
let player = "black";
|
||||
if player =="white"{
|
||||
if self.player_color == Some("white".to_string()) {
|
||||
let tile_size = board_size / 8.0;
|
||||
for row in 0..8 {
|
||||
for col in 0..8 {
|
||||
@@ -419,7 +426,7 @@ impl eframe::App for ChessApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
if player=="black"{
|
||||
if self.player_color == Some("black".to_string()) {
|
||||
{
|
||||
let tile_size = board_size / 8.0;
|
||||
for row in 0..8 {
|
||||
@@ -444,7 +451,8 @@ impl eframe::App for ChessApp {
|
||||
let piece = self.board[row][col];
|
||||
if piece != Piece::Empty {
|
||||
let symbol = piece.symbol();
|
||||
let font_id = egui::FontId::proportional(tile_size * 0.75);
|
||||
let font_id =
|
||||
egui::FontId::proportional(tile_size * 0.75);
|
||||
painter.text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
@@ -478,8 +486,10 @@ impl eframe::App for ChessApp {
|
||||
|
||||
// Handle clicks
|
||||
if ui.ctx().input(|i| i.pointer.primary_clicked()) {
|
||||
let click_pos =
|
||||
ui.ctx().input(|i| i.pointer.interact_pos()).unwrap();
|
||||
let click_pos = ui
|
||||
.ctx()
|
||||
.input(|i| i.pointer.interact_pos())
|
||||
.unwrap();
|
||||
if rect.contains(click_pos) {
|
||||
self.handle_click(row, col);
|
||||
}
|
||||
@@ -488,8 +498,6 @@ impl eframe::App for ChessApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -548,6 +556,6 @@ mod tests {
|
||||
#[test]
|
||||
fn test_server_port_default() {
|
||||
let app = ChessApp::default();
|
||||
assert_eq!(app.server_port, "8080");
|
||||
assert_eq!(app.server_port, "9001");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user