Skip to content

Commit

Permalink
Merge #171
Browse files Browse the repository at this point in the history
171: Add support for rugby penalties r=TristanDebrunner a=TristanDebrunner

Fixes #163 

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Jul 9, 2023
2 parents bf01d51 + 1ad3db5 commit af4dd27
Show file tree
Hide file tree
Showing 4 changed files with 797 additions and 192 deletions.
23 changes: 19 additions & 4 deletions refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use super::APP_NAME;
use crate::{config::Config, penalty_editor::*, sound_controller::*, tournament_manager::*};
use crate::{
config::{Config, Mode},
penalty_editor::*,
sound_controller::*,
tournament_manager::*,
};
use iced::{
executor,
pure::{column, Application, Element},
Expand Down Expand Up @@ -1439,7 +1444,7 @@ impl Application for RefBoxApp {
let mut tm = self.tm.lock().unwrap();
let now = Instant::now();
if switch {
tm.switch_to_ref_timeout().unwrap();
tm.switch_to_ref_timeout(now).unwrap();
} else {
tm.start_ref_timeout(now).unwrap();
}
Expand All @@ -1454,7 +1459,13 @@ impl Application for RefBoxApp {
let mut tm = self.tm.lock().unwrap();
let now = Instant::now();
if switch {
tm.switch_to_penalty_shot().unwrap();
if self.config.mode == Mode::Rugby {
tm.switch_to_rugby_penalty_shot(now).unwrap();
} else {
tm.switch_to_penalty_shot().unwrap();
}
} else if self.config.mode == Mode::Rugby {
tm.start_rugby_penalty_shot(now).unwrap();
} else {
tm.start_penalty_shot(now).unwrap();
}
Expand Down Expand Up @@ -1614,7 +1625,11 @@ impl Application for RefBoxApp {
} if is_confirmation => {}
AppState::ConfirmScores(_) => {}
_ => {
main_view = main_view.push(build_timeout_ribbon(&self.snapshot, &self.tm));
main_view = main_view.push(build_timeout_ribbon(
&self.snapshot,
&self.tm,
self.config.mode,
));
}
}

Expand Down
12 changes: 8 additions & 4 deletions refbox/src/app/view_builders/shared_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
SPACING, WHITE, YELLOW,
},
};
use crate::tournament_manager::TournamentManager;
use crate::{config::Mode, tournament_manager::TournamentManager};
use uwh_common::{drawing_support::*, uwhscores::GameInfo};

use iced::{
Expand Down Expand Up @@ -136,6 +136,7 @@ pub(super) fn make_scroll_list<'a, const LIST_LEN: usize>(
pub(in super::super) fn build_timeout_ribbon<'a>(
snapshot: &GameSnapshot,
tm: &Arc<Mutex<TournamentManager>>,
mode: Mode,
) -> Row<'a, Message> {
let tm = tm.lock().unwrap();

Expand Down Expand Up @@ -215,11 +216,14 @@ pub(in super::super) fn build_timeout_ribbon<'a>(
.style(style::Button::Yellow)
}
TimeoutSnapshot::Black(_) | TimeoutSnapshot::White(_) | TimeoutSnapshot::Ref(_) => {
let can_switch = if mode == Mode::Rugby {
tm.can_switch_to_rugby_penalty_shot()
} else {
tm.can_switch_to_penalty_shot()
};
make_message_button(
"SWITCH TO\nPEN SHOT",
tm.can_switch_to_penalty_shot()
.ok()
.map(|_| Message::PenaltyShot(true)),
can_switch.ok().map(|_| Message::PenaltyShot(true)),
)
.style(style::Button::Red)
}
Expand Down
Loading

0 comments on commit af4dd27

Please sign in to comment.