]> git.seodisparate.com - EN605.607.81.SP22_ASDM_Project/commitdiff
Fixes related to new send emote functionality
authorStephen Seo <seo.disparate@gmail.com>
Fri, 29 Apr 2022 08:24:42 +0000 (17:24 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 29 Apr 2022 08:24:42 +0000 (17:24 +0900)
back_end/src/db_handler.rs
back_end/src/json_handlers.rs
front_end/src/state.rs

index 0c73f835d1c63327a4917dd1b11d151f66ea3d1b..9b5aa24ae1d05e2b2d67665b13d23eb45765b7cf 100644 (file)
@@ -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<Self, Self::Error> {
-        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<EmoteEnum> 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 {
index 95ff212425a87a21fbb8bec7d6863cf6f1233007..973d60f6fbc7b6dfec9da4875b0c835750cde4ae 100644 (file)
@@ -8,7 +8,7 @@
 //You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
 use crate::{
     constants::BACKEND_PHRASE_MAX_LENGTH,
-    db_handler::{CheckPairingType, DBHandlerRequest, EmoteEnum, GetIDSenderType},
+    db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType}, state::EmoteEnum,
 };
 
 use std::{
index 242e5e8b702976ee7e100b95ebaf786d787d240a..7824c2d2c5076106d5694554ee2ec16d4cc77995 100644 (file)
@@ -563,6 +563,7 @@ pub struct GameStateResponse {
     pub r#type: String,
     pub status: String,
     pub board: Option<String>,
+    pub peer_emote: Option<String>,
 }
 
 #[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<Self, Self::Error> {
+        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<EmoteEnum> 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<char> = 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<char> = board_string.chars().collect();
         assert_eq!(board_chars[49], 'c');