fix config loading
authoralfadur
Wed, 20 May 2020 23:41:25 +0300
changeset 15602 98482c4ccf4b
parent 15601 db710cd8df69
child 15603 ab095fc0256c
fix config loading
rust/hedgewars-server/src/server/demo.rs
rust/hedgewars-server/src/server/haskell.rs
--- a/rust/hedgewars-server/src/server/demo.rs	Wed May 20 23:08:08 2020 +0300
+++ b/rust/hedgewars-server/src/server/demo.rs	Wed May 20 23:41:25 2020 +0300
@@ -8,6 +8,7 @@
     str::FromStr,
 };
 
+#[derive(PartialEq, Debug)]
 struct Demo {
     teams: Vec<TeamInfo>,
     config: Vec<GameCfg>,
@@ -341,32 +342,20 @@
         let mut tuple = item.into_tuple()?;
         let mut tuple_iter = tuple.drain(..);
         let name = tuple_iter.next()?.into_string()?;
-        let value = tuple_iter.next()?;
+        let mut value = tuple_iter.next()?.into_list()?;
+        let mut value_iter = value.drain(..);
 
         let config_item = match &name[..] {
-            "AMMO" => {
-                let mut ammo = value.into_list()?;
-                let mut ammo_iter = ammo.drain(..);
-                GameCfg::Ammo(
-                    ammo_iter.next()?.into_string()?,
-                    ammo_iter.next().and_then(|v| v.into_string()),
-                )
-            }
-            "SCHEME" => {
-                let mut scheme = value.into_list()?;
-                let mut scheme_iter = scheme.drain(..);
-                GameCfg::Scheme(
-                    scheme_iter.next()?.into_string()?,
-                    scheme_iter
-                        .next()?
-                        .into_list()?
-                        .drain(..)
-                        .filter_map(|v| v.into_string())
-                        .collect(),
-                )
-            }
-            "SCRIPT" => GameCfg::Script(value.into_string()?),
-            "THEME" => GameCfg::Theme(value.into_string()?),
+            "AMMO" => GameCfg::Ammo(
+                value_iter.next()?.into_string()?,
+                value_iter.next().and_then(|v| v.into_string()),
+            ),
+            "SCHEME" => GameCfg::Scheme(
+                value_iter.next()?.into_string()?,
+                value_iter.filter_map(|v| v.into_string()).collect(),
+            ),
+            "SCRIPT" => GameCfg::Script(value_iter.next()?.into_string()?),
+            "THEME" => GameCfg::Theme(value_iter.next()?.into_string()?),
             _ => None?,
         };
         config.push(config_item);
--- a/rust/hedgewars-server/src/server/haskell.rs	Wed May 20 23:08:08 2020 +0300
+++ b/rust/hedgewars-server/src/server/haskell.rs	Wed May 20 23:41:25 2020 +0300
@@ -1,11 +1,9 @@
-use crate::server::haskell::HaskellValue::Boolean;
-use nom::multi::many0;
 use nom::{
     branch::alt,
     bytes::complete::{escaped_transform, is_not, tag, take_while, take_while1},
     character::{is_alphanumeric, is_digit, is_space},
     combinator::{map, map_res},
-    multi::separated_list,
+    multi::{many0, separated_list},
     sequence::{delimited, pair, preceded, separated_pair, terminated},
     ExtendInto, IResult,
 };