Fixes related to new send emote functionality

This commit is contained in:
Stephen Seo 2022-04-29 17:24:42 +09:00
parent 5381578b08
commit 36dd43bb70
3 changed files with 49 additions and 49 deletions

View 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 {

View 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::{

View 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');