diff options
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/player.rs | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/core/src/player.rs b/core/src/player.rs deleted file mode 100644 index 7cdeb16..0000000 --- a/core/src/player.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::net::SocketAddr; -use sha1::{Digest, Sha1}; -use crate::constants::SALT; - -pub struct PlayerInfo { - addr: SocketAddr, - name: &'static str, - name_hash: &'static str, - index: u8, - - // 颜色 HSV - color_hue: i32, // 0 - 360 - color_saturation: f32, // 0 - 1 - color_value: f32 // 0 - 1 -} - -pub enum PlayerMessage { - Say(&'static str), - PressedDown(char), - PressedUp(char) -} - -impl PlayerInfo { - - /// # 配置玩家 ID 和 名称 - /// self : 自身 - /// name : 玩家名称 - /// number : 玩家序号 - /// return -> 自身 - pub fn name(&mut self, name : &'static str, number : &'static str) -> &mut Self { - self.name = name; - - let combined = format!("{}{}{}", name, number, SALT); - let mut hasher = Sha1::new(); - hasher.update(combined); - let result = hasher.finalize(); - - self.name_hash = &format!("{:x}", &result[..]); - self - } - - /// # 配置玩家颜色 - /// self : 自身 - /// hue : 色调 0 -> RED; 120 -> GREEN; 240 -> BLUE - /// saturation : 饱和度 - /// value : 明度 - /// return -> 自身 - pub fn color_hsv(&mut self, hue: i32, saturation: f32, value: f32) -> &mut Self { - self.color_hue = hue.clamp(0, 360); - self.color_saturation = saturation.clamp(0.0, 1.0); - self.color_value = value.clamp(0.0, 1.0); - self - } -}
\ No newline at end of file |
