diff --git a/namerena-runner/src/engine.rs b/namerena-runner/src/engine.rs index 2a72250..fe2580d 100644 --- a/namerena-runner/src/engine.rs +++ b/namerena-runner/src/engine.rs @@ -1,13 +1,33 @@ pub const PROFILE_START: u32 = 33554431; pub mod runners { - use crate::name::Player; + use crate::player::Player; use crate::rc4::RC4; pub struct PlayerGroup { players: Vec, } + impl PlayerGroup { + /// 从一个 名竞的原始输入 中创建一个 PlayerGroup + /// + /// # 要求 + /// 会默认整个输入是同一个队伍的 + /// 也就是会忽略所有 \n\n 的队伍分割 + pub fn new_from_namerena_raw(raw_input: String) -> PlayerGroup { + // 首先以 \n 分割 + let raw_input = raw_input.split("\n"); + // 然后直接 map 生成 Player + let players: Vec = raw_input.map(|raw_name| { + Player::new_from_namerena_raw(raw_name.to_string()) + }).collect(); + + PlayerGroup { + players, + } + } + } + pub struct Runner { /// 应该是一个 Rc4 实例类似物 randomer: RC4, @@ -18,4 +38,15 @@ pub mod runners { /// 也应该是一个队伍 winner: Option, } + + impl Runner { + /// 从一个 名竞的原始输入 中创建一个 Runner + /// + /// 其实就是解析名竞的输入格式 + pub fn new_from_namerena_raw(raw_input: String) { + // 首先以 \n\n 分割 + let mut raw_input = raw_input.split("\n\n"); + + } + } } diff --git a/namerena-runner/src/main.rs b/namerena-runner/src/main.rs index 770f2f7..7e22e5a 100644 --- a/namerena-runner/src/main.rs +++ b/namerena-runner/src/main.rs @@ -1,5 +1,4 @@ mod engine; -mod name; /// 万里长征, 始于足下 mod player; mod rc4; diff --git a/namerena-runner/src/name.rs b/namerena-runner/src/name.rs deleted file mode 100644 index 011e923..0000000 --- a/namerena-runner/src/name.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub struct Player { - team: String, - name: String, - weapon: String, -} diff --git a/namerena-runner/src/player.rs b/namerena-runner/src/player.rs index 10494d6..63b3487 100644 --- a/namerena-runner/src/player.rs +++ b/namerena-runner/src/player.rs @@ -131,6 +131,34 @@ impl Player { } } + /// 直接从一个名竞的原始输入创建一个 Player + /// + /// # 要求 + /// 不许有 \n + /// + /// 可能的输入格式: + /// - + /// - @ + /// - + + /// - ++diy{xxxxx} + /// - @+ + /// - @++diy{xxxxx} + pub fn new_from_namerena_raw(raw_name: String) -> Self { + // 先判断是否有 + 和 @ + if !raw_name.contains("@") && !raw_name.contains("+") { + return Player::new(raw_name.clone(), raw_name.clone(), None); + } + // 区分队伍名 + let name: &str; + let mut team: &str; + let weapon: Option<&str>; + if raw_name.contains("@") { + (name, team) = raw_name.split_once("@").unwrap(); + } + + todo!() + } + pub fn update_player(&mut self) {} pub fn step(&mut self, randomer: &mut RC4) {}