|
|
@ -90,39 +90,43 @@ impl EngineOption { |
|
|
|
EngineOption { name, option_type, option_data, } |
|
|
|
EngineOption { name, option_type, option_data, } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn engine_option_data_type_string(&t: EngineOptionDataType) -> String { |
|
|
|
fn engine_option_data_string(d: &EngineOptionData) -> String { |
|
|
|
match t { |
|
|
|
match d { |
|
|
|
EngineOptionDataType::DefaultVal => String::new("default"), |
|
|
|
&EngineOptionData::Int(v) => v.to_string(), |
|
|
|
EngineOptionDataType::Min => String::new("min"), |
|
|
|
&EngineOptionData::Float(v) => v.to_string(), |
|
|
|
EngineOptionDataType::Max => String::new("max"), |
|
|
|
&EngineOptionData::Text(ref v) => v.clone(), |
|
|
|
EngineOptionDataType::Var => String::new("var"), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn engine_option_data_string(&d: EngineOptionData) -> String { |
|
|
|
|
|
|
|
match eod { |
|
|
|
|
|
|
|
EngineOptionData::Int(v) => v.to_string(), |
|
|
|
|
|
|
|
EngineOptionData::Float(v) => v.to_string(), |
|
|
|
|
|
|
|
EngineOptionData::Text(ref v) => v.clone(), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn option_string(&self) -> String { |
|
|
|
pub fn option_string(&self) -> String { |
|
|
|
let mut option_data_string: String = String::new(); |
|
|
|
let mut option_data_string: String = String::new(); |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Hash maps are iterated out of order (obviously). In order to guarantee order in the response it'll be
|
|
|
|
// NOTE: The user is left to understand what option takes which of these data type values. There's some
|
|
|
|
// Easier to test if the key exists (since there are only 3 of them ever), if it does, get the value with
|
|
|
|
// work that can be done later switching based on the option type, but for now it's reasonable to
|
|
|
|
// HashMap::Get, which returns a reference.
|
|
|
|
// expect the user understands the standard well enough to know which options take what kind
|
|
|
|
//
|
|
|
|
// of settings.
|
|
|
|
// Test for the key with HashMap::contains_key. You'll have to match for each instance using the private
|
|
|
|
if self.option_data.contains_key(&EngineOptionDataType::DefaultVal) { |
|
|
|
// functions above. You will _still_ need to build a string like you did before.
|
|
|
|
let data = self.option_data.get(&EngineOptionDataType::DefaultVal); |
|
|
|
for (dt, eod) in self.option_data.iter() { |
|
|
|
option_data_string.push_str(&format!(" {} {}", "default", |
|
|
|
let _: (&EngineOptionDataType, &EngineOptionData) = (dt, eod); |
|
|
|
EngineOption::engine_option_data_string(&data.unwrap()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.option_data.contains_key(&EngineOptionDataType::Min) { |
|
|
|
|
|
|
|
let data = self.option_data.get(&EngineOptionDataType::Min); |
|
|
|
|
|
|
|
option_data_string.push_str(&format!(" {} {}", "min", EngineOption::engine_option_data_string(&data.unwrap()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.option_data.contains_key(&EngineOptionDataType::Max) { |
|
|
|
|
|
|
|
let data = self.option_data.get(&EngineOptionDataType::Max); |
|
|
|
|
|
|
|
option_data_string.push_str(&format!(" {} {}", "max", EngineOption::engine_option_data_string(&data.unwrap()))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
option_data_string.push_str(&format!("{} {} ", dts, res)); |
|
|
|
if self.option_data.contains_key(&EngineOptionDataType::Var) { |
|
|
|
|
|
|
|
let data = self.option_data.get(&EngineOptionDataType::Var); |
|
|
|
|
|
|
|
option_data_string.push_str(&format!(" {} {}", "var", EngineOption::engine_option_data_string(&data.unwrap()))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ots = match self.option_type { |
|
|
|
let ots = match self.option_type { |
|
|
|
EngineOptionType::Check => "check", |
|
|
|
EngineOptionType::Check => "check", |
|
|
|
EngineOptionType::Spin => "spin", |
|
|
|
EngineOptionType::Spin => "spin", |
|
|
@ -131,7 +135,7 @@ impl EngineOption { |
|
|
|
EngineOptionType::TypeString => "string", |
|
|
|
EngineOptionType::TypeString => "string", |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
format!("{} {} {} {} {} {}\n", commands::OPTION, commands::OPTIONNAME, self.name, |
|
|
|
format!("{} {} {} {} {}{}\n", commands::OPTION, commands::OPTIONNAME, self.name, |
|
|
|
commands::TYPE, ots, option_data_string) |
|
|
|
commands::TYPE, ots, option_data_string) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|