Skip to content

Commit

Permalink
Fixes not being able to send gamecontrols reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
IongIer committed Jul 25, 2024
1 parent 65ce39a commit 0a8aae3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions apis/src/components/molecules/control_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ pub fn ControlButtons() -> impl IntoView {
.expect("Control buttons show only for logged in players")
};

let color = move || {
let color = Signal::derive(move || {
game_state
.signal
.get_untracked()
.user_color(user_id())
.expect("Control buttons show only for logged in players")
};
.user_color_as_signal(Some(user_id()).into())
.get()
.expect("User_id is one of the players in this game")
});
let pending = create_read_slice(game_state.signal, |gs| gs.game_control_pending.clone());
let not_tournament = create_read_slice(game_state.signal, |gs| {
gs.game_response
Expand Down
4 changes: 2 additions & 2 deletions apis/src/providers/game_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl GameState {
}

// Still needed because send_game_control uses it, maybe this should be moved out of the gamestate?
pub fn user_color(&self, user_id: Uuid) -> Option<Color> {
fn user_color(&self, user_id: Uuid) -> Option<Color> {
if Some(user_id) == self.black_id {
return Some(Color::Black);
}
Expand All @@ -327,7 +327,7 @@ impl GameState {
pub fn send_game_control(&mut self, game_control: GameControl, user_id: Uuid) {
if let Some(color) = self.user_color(user_id) {
if color != game_control.color() {
log!("This is a bug, you should only send GCs of your own color");
log!("This is a bug, you should only send GCs of your own color, user id color is {color} and gc color is {}", game_control.color());
} else if let Some(ref game_id) = self.game_id {
ApiRequests::new().game_control(game_id.to_owned(), game_control);
} else {
Expand Down

0 comments on commit 0a8aae3

Please sign in to comment.