From c176d390bd34d869235c2a55e394d43a2d31c16d Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Fri, 15 Dec 2017 12:07:08 -0800 Subject: [PATCH] first pass at option_string --- src/commands.rs | 7 +++++++ src/options.rs | 35 +++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 4f142e1..a5cc411 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -88,3 +88,10 @@ pub const INFO: &'static str = "info"; /// OPTION tells the GUI which parameters can be changed in the engine pub const OPTION: &'static str = "option"; + +/// OPTIONNAME tells the GUI which option name is being sent +pub const OPTIONNAME: &'static str = "name"; + +/// TYPE tells the GUI the type of the option +pub const TYPE: &'static str = "type"; + diff --git a/src/options.rs b/src/options.rs index e4df90a..db39b68 100644 --- a/src/options.rs +++ b/src/options.rs @@ -4,6 +4,7 @@ //! of the nicer parts of typechecking. use std::collections::HashMap; +use commands; pub mod constants { @@ -48,11 +49,11 @@ pub mod constants { /// The `EngineOptionType` type used to indicate what type of option the GUI should display #[derive(Copy, Clone, Debug, PartialEq)] pub enum EngineOptionType { - Check, - Spin, - Combo, - Button, - TypeString, // `String` is a reserved word so `TypeString` is substituted + Check("check"), + Spin("spin"), + Combo("combo"), + Button("button"), + TypeString("string"), // `String` is a reserved word so `TypeString` is substituted } #[derive(Clone, Debug, PartialEq, PartialOrd)] @@ -67,10 +68,10 @@ pub enum EngineOptionData { #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] /// The `EngineOptionDataType` type used to indicate the type of the `EngineOption` setting pub enum EngineOptionDataType { - DefaultVal, // `Default` is reserved so `DefaultVal` is used - Min, - Max, - Var, + DefaultVal("default"), // `Default` is reserved so `DefaultVal` is used + Min("min"), + Max("max"), + Var("var"), } #[derive(Debug, PartialEq)] @@ -90,12 +91,14 @@ impl EngineOption { } pub fn option_string(&self) -> String { - // TODO: Implement this to save this when looping through and sending options - // TODO: This should be tested in isolation as well - // This should handle the case where optional min max var are specified as well. - // pattern match the engine option type and convert it to the correct string. - // EVERYTHING SHOULD BE TRIVIALLY CASTABLE INTO A STRING - // NO MATCHING NEEDED....PROBABLY - format!("PUT THE FULL COMMAND STRING HERE!") + let option_data_string: String; + + for dt, eod in &self.option_data { + option_data_string = option_data_string + format!("{} {}", dt, eod); + } + + + format!("{} {} {} {} {} {}\n", commands::OPTION, commands::OPTIONNAME, self.name, + commands::TYPE, option_type, option_data_string); } }