Skip to content

Commit

Permalink
Merge #81
Browse files Browse the repository at this point in the history
81: Fixes after testing on hardware r=TristanDebrunner a=TristanDebrunner

- Fixes for working with the overlay (actually send tid, add `\n` to JSON for message end detection
- Add fullscreen option for refbox

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Jun 22, 2022
2 parents e6c393e + 5922dd7 commit fffd453
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion uwh-common/src/game_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct GameSnapshot {
pub is_old_game: bool,
pub game_number: u32,
pub next_game_number: u32,
pub tournament_id: u64,
pub tournament_id: u32,
}

#[cfg(feature = "std")]
Expand Down
17 changes: 16 additions & 1 deletion uwh-refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct RefBoxApp {
current_pool: Option<String>,
sound: Option<(OutputStream, OutputStreamHandle)>,
sim_child: Option<Child>,
fullscreen: bool,
}

#[derive(Debug)]
Expand All @@ -73,6 +74,7 @@ pub struct RefBoxAppFlags {
pub json_port: u16,
pub sim_child: Option<Child>,
pub require_https: bool,
pub fullscreen: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -264,14 +266,17 @@ pub enum ConfirmationOption {
}

impl RefBoxApp {
fn apply_snapshot(&mut self, new_snapshot: GameSnapshot) {
fn apply_snapshot(&mut self, mut new_snapshot: GameSnapshot) {
if new_snapshot.current_period != self.snapshot.current_period {
if new_snapshot.current_period == GamePeriod::BetweenGames {
self.handle_game_end();
} else if self.snapshot.current_period == GamePeriod::BetweenGames {
self.handle_game_start(new_snapshot.game_number);
}
}
if let Some(tid) = self.current_tid {
new_snapshot.tournament_id = tid;
}
self.maybe_play_sound(&new_snapshot);
self.update_sender
.send_snapshot(new_snapshot.clone(), self.config.hardware.white_on_right)
Expand Down Expand Up @@ -568,6 +573,7 @@ impl Application for RefBoxApp {
json_port,
sim_child,
require_https,
fullscreen,
} = flags;

let sound = match OutputStream::try_default() {
Expand Down Expand Up @@ -628,6 +634,7 @@ impl Application for RefBoxApp {
current_pool: None,
sound,
sim_child,
fullscreen,
},
Command::none(),
)
Expand All @@ -644,6 +651,14 @@ impl Application for RefBoxApp {
"UWH Ref Box".into()
}

fn mode(&self) -> iced::window::Mode {
if self.fullscreen {
iced::window::Mode::Fullscreen
} else {
iced::window::Mode::Windowed
}
}

fn update(&mut self, message: Message) -> Command<Message> {
trace!("Handling message: {message:?}");
match message {
Expand Down
6 changes: 3 additions & 3 deletions uwh-refbox/src/app/update_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl Server {
ServerMessage::NewSnapshot(snapshot, white_on_right) => {
//info!("Server received snapshot: {snapshot:?}");
let json = if self.has_json {
serde_json::to_string(&snapshot).unwrap().into_bytes()
(serde_json::to_string(&snapshot).unwrap() + "\n").into_bytes()
} else {
vec![]
};
Expand Down Expand Up @@ -290,8 +290,8 @@ impl Drop for Server {

async fn listener_loop(tx: mpsc::Sender<ServerMessage>, binary_port: u16, json_port: u16) {
info!("Strating Listeners for JSON (port {json_port}) and binary (port {binary_port})");
let binary_listener = TcpListener::bind(("localhost", binary_port)).await.unwrap();
let json_listener = TcpListener::bind(("localhost", json_port)).await.unwrap();
let binary_listener = TcpListener::bind(("::", binary_port)).await.unwrap();
let json_listener = TcpListener::bind(("::", json_port)).await.unwrap();
info!("Listeners started");

loop {
Expand Down
5 changes: 5 additions & 0 deletions uwh-refbox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ struct Cli {
/// Spacing between pixels in the panel the simulator
spacing: Option<f32>,

#[clap(long, short)]
/// Make the app fullscreen
fullscreen: bool,

#[clap(long, default_value = "8001")]
/// Port to listen on for TCP connections with a binary send type
binary_port: u16,
Expand Down Expand Up @@ -167,6 +171,7 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
json_port: args.json_port,
sim_child: child,
require_https: !args.allow_http,
fullscreen: args.fullscreen,
};

let mut settings = Settings::with_flags(flags);
Expand Down

0 comments on commit fffd453

Please sign in to comment.