From 36dd43bb7053289e54d2a50553a2c1fc745c4db2 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 29 Apr 2022 17:24:42 +0900 Subject: [PATCH] Fixes related to new send emote functionality --- back_end/src/db_handler.rs | 47 +-------------------------------- back_end/src/json_handlers.rs | 2 +- front_end/src/state.rs | 49 +++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/back_end/src/db_handler.rs b/back_end/src/db_handler.rs index 0c73f83..9b5aa24 100644 --- a/back_end/src/db_handler.rs +++ b/back_end/src/db_handler.rs @@ -11,10 +11,9 @@ use crate::constants::{ BACKEND_CLEANUP_INTERVAL_SECONDS, COLS, GAME_CLEANUP_TIMEOUT, PLAYER_CLEANUP_TIMEOUT, PLAYER_COUNT_LIMIT, ROWS, TURN_SECONDS, }; -use crate::state::{board_from_string, new_string_board, string_from_board, BoardState, Turn}; +use crate::state::{board_from_string, new_string_board, string_from_board, BoardState, Turn, EmoteEnum}; use std::collections::HashMap; -use std::fmt::Display; use std::sync::mpsc::{Receiver, RecvTimeoutError, SyncSender}; use std::time::{Duration, Instant}; use std::{fmt, thread}; @@ -119,50 +118,6 @@ impl fmt::Display for DBPlaceError { } } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub enum EmoteEnum { - Smile, - Neutral, - Frown, - Think, -} - -impl Display for EmoteEnum { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - EmoteEnum::Smile => f.write_str("smile"), - EmoteEnum::Neutral => f.write_str("neutral"), - EmoteEnum::Frown => f.write_str("frown"), - EmoteEnum::Think => f.write_str("think"), - } - } -} - -impl TryFrom<&str> for EmoteEnum { - type Error = (); - - fn try_from(value: &str) -> Result { - match value.to_lowercase().as_str() { - "smile" => Ok(Self::Smile), - "neutral" => Ok(Self::Neutral), - "frown" => Ok(Self::Frown), - "think" => Ok(Self::Think), - _ => Err(()), - } - } -} - -impl From for String { - fn from(e: EmoteEnum) -> Self { - match e { - EmoteEnum::Smile => "smile".into(), - EmoteEnum::Neutral => "neutral".into(), - EmoteEnum::Frown => "frown".into(), - EmoteEnum::Think => "think".into(), - } - } -} - #[derive(Clone, Debug)] pub enum DBHandlerRequest { GetID { diff --git a/back_end/src/json_handlers.rs b/back_end/src/json_handlers.rs index 95ff212..973d60f 100644 --- a/back_end/src/json_handlers.rs +++ b/back_end/src/json_handlers.rs @@ -8,7 +8,7 @@ //You should have received a copy of the GNU General Public License along with this program. If not, see . use crate::{ constants::BACKEND_PHRASE_MAX_LENGTH, - db_handler::{CheckPairingType, DBHandlerRequest, EmoteEnum, GetIDSenderType}, + db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType}, state::EmoteEnum, }; use std::{ diff --git a/front_end/src/state.rs b/front_end/src/state.rs index 242e5e8..7824c2d 100644 --- a/front_end/src/state.rs +++ b/front_end/src/state.rs @@ -563,6 +563,7 @@ pub struct GameStateResponse { pub r#type: String, pub status: String, pub board: Option, + pub peer_emote: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -593,6 +594,50 @@ pub enum PlacedEnum { Other(NetworkedGameState), } +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +pub enum EmoteEnum { + Smile, + Neutral, + Frown, + Think, +} + +impl Display for EmoteEnum { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match *self { + EmoteEnum::Smile => f.write_str("smile"), + EmoteEnum::Neutral => f.write_str("neutral"), + EmoteEnum::Frown => f.write_str("frown"), + EmoteEnum::Think => f.write_str("think"), + } + } +} + +impl TryFrom<&str> for EmoteEnum { + type Error = (); + + fn try_from(value: &str) -> Result { + match value.to_lowercase().as_str() { + "smile" => Ok(Self::Smile), + "neutral" => Ok(Self::Neutral), + "frown" => Ok(Self::Frown), + "think" => Ok(Self::Think), + _ => Err(()), + } + } +} + +impl From for String { + fn from(e: EmoteEnum) -> Self { + match e { + EmoteEnum::Smile => "smile".into(), + EmoteEnum::Neutral => "neutral".into(), + EmoteEnum::Frown => "frown".into(), + EmoteEnum::Think => "think".into(), + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -629,7 +674,7 @@ mod tests { board[54].set(BoardState::Cyan); board[55].set(BoardState::Magenta); - let (board_string, state_opt) = string_from_board(board.clone(), 51); + let (board_string, state_opt) = string_from_board(&board, 51); let board_chars: Vec = board_string.chars().collect(); assert_eq!(board_chars[49], 'b'); @@ -649,7 +694,7 @@ mod tests { board[54].set(BoardState::Magenta); board[55].set(BoardState::Cyan); - let (board_string, state_opt) = string_from_board(board.clone(), 51); + let (board_string, state_opt) = string_from_board(&board, 51); let board_chars: Vec = board_string.chars().collect(); assert_eq!(board_chars[49], 'c');