aboutsummaryrefslogtreecommitdiff
path: root/core/src/player.rs
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2025-04-12 13:47:00 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2025-04-12 13:47:00 +0800
commitd8dab41672fd757490dfbce44dfb3475ccc73b44 (patch)
tree5b289f6e3b593329fddb7e66c0bde9049619f195 /core/src/player.rs
parente3a61d6c644dcf898c726f7c870b17bbf3fe6c59 (diff)
修改 gamepad_layouts.rs 名为 layouts.rs
合并 message.rs 到 player.rs 修改 phantom_link_server.rs 名为 server.rs
Diffstat (limited to 'core/src/player.rs')
-rw-r--r--core/src/player.rs48
1 files changed, 47 insertions, 1 deletions
diff --git a/core/src/player.rs b/core/src/player.rs
index 01e47d0..78e4d23 100644
--- a/core/src/player.rs
+++ b/core/src/player.rs
@@ -1,8 +1,54 @@
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
+ 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[..16]);
+ self
+ }
+
+ /// # 配置玩家颜色
+ /// self : 自身
+ /// hue : 色调 0 -> RED; 120 -> GREEN; 240 -> BLUE
+ /// saturation : 饱和度
+ /// value : 明度
+ /// return -> 自身
+ pub fn color_hue(&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