211 Ammo(n, None) => ("AMMO".to_string(), vec![n.to_string()]), |
211 Ammo(n, None) => ("AMMO".to_string(), vec![n.to_string()]), |
212 Ammo(n, Some(s)) => ("AMMO".to_string(), vec![n.to_string(), s.to_string()]), |
212 Ammo(n, Some(s)) => ("AMMO".to_string(), vec![n.to_string(), s.to_string()]), |
213 Scheme(n, s) if s.is_empty() => ("SCHEME".to_string(), vec![n.to_string()]), |
213 Scheme(n, s) if s.is_empty() => ("SCHEME".to_string(), vec![n.to_string()]), |
214 Scheme(n, s) => ("SCHEME".to_string(), { |
214 Scheme(n, s) => ("SCHEME".to_string(), { |
215 let mut v = vec![n.to_string()]; |
215 let mut v = vec![n.to_string()]; |
216 v.extend(s.clone().into_iter()); |
216 v.extend(s.clone()); |
217 v |
217 v |
218 }), |
218 }), |
219 Script(s) => ("SCRIPT".to_string(), vec![s.to_string()]), |
219 Script(s) => ("SCRIPT".to_string(), vec![s.to_string()]), |
220 Theme(t) => ("THEME".to_string(), vec![t.to_string()]), |
220 Theme(t) => ("THEME".to_string(), vec![t.to_string()]), |
221 DrawnMap(m) => ("DRAWNMAP".to_string(), vec![m.to_string()]), |
221 DrawnMap(m) => ("DRAWNMAP".to_string(), vec![m.to_string()]), |
257 |
257 |
258 macro_rules! msg { |
258 macro_rules! msg { |
259 [$($part: expr),*] => { |
259 [$($part: expr),*] => { |
260 format!(concat!($(const_braces!($part)),*, "\n"), $($part),*); |
260 format!(concat!($(const_braces!($part)),*, "\n"), $($part),*); |
261 }; |
261 }; |
262 } |
|
263 |
|
264 #[cfg(test)] |
|
265 macro_rules! several { |
|
266 [$part: expr] => { once($part) }; |
|
267 [$part: expr, $($other: expr),*] => { once($part).chain(several![$($other),*]) }; |
|
268 } |
262 } |
269 |
263 |
270 impl HwProtocolMessage { |
264 impl HwProtocolMessage { |
271 /** Converts the message to a raw `String`, which can be sent over the network. |
265 /** Converts the message to a raw `String`, which can be sent over the network. |
272 * |
266 * |
328 info.voice_pack, |
322 info.voice_pack, |
329 info.flag, |
323 info.flag, |
330 info.difficulty, |
324 info.difficulty, |
331 info.hedgehogs |
325 info.hedgehogs |
332 .iter() |
326 .iter() |
333 .flat_map(|h| several![&h.name[..], &h.hat[..]]) |
327 .flat_map(|h| [&h.name[..], &h.hat[..]]) |
334 .collect::<Vec<_>>() |
328 .collect::<Vec<_>>() |
335 .join("\n") |
329 .join("\n") |
336 ], |
330 ], |
337 RemoveTeam(name) => msg!["REMOVE_TEAM", name], |
331 RemoveTeam(name) => msg!["REMOVE_TEAM", name], |
338 SetHedgehogsNumber(team, number) => msg!["HH_NUM", team, number], |
332 SetHedgehogsNumber(team, number) => msg!["HH_NUM", team, number], |