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};
}
}
-#[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 {
//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::{
pub r#type: String,
pub status: String,
pub board: Option<String>,
+ pub peer_emote: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
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::*;
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');
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');