Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet committed Aug 2, 2024
1 parent 3fd5eba commit efc9904
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions rust_controller/src/api/update_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub async fn update_loop(coordinator: Arc<Mutex<FlipUpVMixCoordinator>>) {
.for_each(|player| tjing_result_map.update_mut_player(player));
let div = coordinator.focused_player().division.clone();
let queue = coordinator.vmix_queue.clone();
coordinator.add_state_to_leaderboard();
coordinator.leaderboard.update_little_lb(&div, queue);
}
}
Expand Down
12 changes: 10 additions & 2 deletions rust_controller/src/controller/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,16 @@ impl FlipUpVMixCoordinator {
channel: &GeneralChannel<PlayerManagerUpdate>,
) -> Result<(), Error> {
self.player_manager.next_queued();
let up_until = self.focused_player().hole_shown_up_until;
self.focused_player_mut().total_score = 0;
self.add_state_to_leaderboard();

self.focused_player_mut()
.fix_round_score(Some(up_until as u8));
if let Some(player) = self.leaderboard.get_lb_player(self.focused_player()) {
let current_round_score = self.focused_player().round_score;
self.focused_player_mut().total_score =
player.total_score - player.round_score + current_round_score;
}
let all = self
.focused_player()
.set_all_values(&self.leaderboard, false)?;
Expand Down Expand Up @@ -375,7 +383,7 @@ impl FlipUpVMixCoordinator {
.map(Arc::clone)
}

fn add_state_to_leaderboard(&mut self) {
pub fn add_state_to_leaderboard(&mut self) {
self.set_current_through();
let current_players = self.available_players().into_iter().cloned().collect_vec();
let previous = self
Expand Down
8 changes: 6 additions & 2 deletions rust_controller/src/controller/coordinator/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,13 @@ impl Player {
/// Used by leaderboard
pub fn fix_round_score(&mut self, up_until: Option<u8>) {
self.round_score = 0;
for result in &self.results.results {
for (i, result) in self.results.results.iter().enumerate() {
if up_until.is_some_and(|up_until| i as u8 == up_until) {
break;
}
self.round_score += result.actual_score() as isize;
}

self.total_score += self.round_score
}

Expand Down Expand Up @@ -481,7 +485,7 @@ impl Player {
};
// Update score text, visibility, and colour

let score = self.get_current_shown_score()?.update_score(1);
let score = self.get_current_shown_score()?.update_score(0);

self.round_score += s.par_score() as isize;
self.total_score += s.par_score() as isize;
Expand Down
3 changes: 2 additions & 1 deletion rust_controller/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
<body>

<div id="division-selector" hx-ext="ws" ws-connect="/ws/division">
Leaderboard
<select id="division-dropdown">
<option value="">Select Division</option>

Expand Down Expand Up @@ -287,7 +288,7 @@
<div class="player" data-player-id="{{player.id}}">
<span class="player-name">{{player.name}}</span>
<form class="queue-form">
<input type="number" name="hole" placeholder="Hole number">
<input type="number" name="hole" placeholder="Through">
<input type="number" name="throws" placeholder="Number of throws">
<button type="submit">Queue player</button>
</form>
Expand Down
2 changes: 1 addition & 1 deletion rust_controller/templates/new_coordinator.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<input name="event_id" id="event_id" value="ac3788d0-6ab8-4684-83a0-42564fd8213a" required/>
</div>
<div>
<label for="round">What round will you be on?</label>
<label for="round">How many rounds have been completed before this one?</label>
<input name="round" id="round" value=0 required>
</div>
<div>
Expand Down

0 comments on commit efc9904

Please sign in to comment.