Browse Source

everything is fuk

ag-yep
Taylor Bockman 7 years ago
parent
commit
47438cf5ea
  1. 48
      src/options.rs
  2. 2
      tests/lib.rs

48
src/options.rs

@ -49,11 +49,11 @@ pub mod constants {
/// The `EngineOptionType` type used to indicate what type of option the GUI should display /// The `EngineOptionType` type used to indicate what type of option the GUI should display
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum EngineOptionType { pub enum EngineOptionType {
Check("check"), Check,
Spin("spin"), Spin,
Combo("combo"), Combo,
Button("button"), Button,
TypeString("string"), // `String` is a reserved word so `TypeString` is substituted TypeString, // `String` is a reserved word so `TypeString` is substituted
} }
#[derive(Clone, Debug, PartialEq, PartialOrd)] #[derive(Clone, Debug, PartialEq, PartialOrd)]
@ -68,10 +68,10 @@ pub enum EngineOptionData {
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
/// The `EngineOptionDataType` type used to indicate the type of the `EngineOption` setting /// The `EngineOptionDataType` type used to indicate the type of the `EngineOption` setting
pub enum EngineOptionDataType { pub enum EngineOptionDataType {
DefaultVal("default"), // `Default` is reserved so `DefaultVal` is used DefaultVal, // `Default` is reserved so `DefaultVal` is used
Min("min"), Min,
Max("max"), Max,
Var("var"), Var,
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -91,14 +91,34 @@ impl EngineOption {
} }
pub fn option_string(&self) -> String { pub fn option_string(&self) -> String {
let option_data_string: String; let mut option_data_string: String = "".to_owned();
for dt, eod in &self.option_data { for (ref dt, ref eod) in &self.option_data {
option_data_string = option_data_string + format!("{} {}", dt, eod); let dts = match dt {
EngineOptionDataType::DefaultVal => "default",
EngineOptionDataType::Min => "min",
EngineOptionDataType::Max => "max",
EngineOptionDataType::Var => "var",
};
let res = match eod {
EngineOptionData::Int(v) => v.to_string(),
EngineOptionData::Float(v) => v.to_string(),
EngineOptionData::Text(v) => v.cloned(),
};
option_data_string.push_str(&format!("{} {:?} ", dts, res));
} }
let ots = match self.option_type {
EngineOptionType::Check => "check",
EngineOptionType::Spin => "spin",
EngineOptionType::Combo => "combo",
EngineOptionType::Button => "button",
EngineOptionType::TypeString => "string",
};
format!("{} {} {} {} {} {}\n", commands::OPTION, commands::OPTIONNAME, self.name, format!("{} {} {} {} {} {}\n", commands::OPTION, commands::OPTIONNAME, self.name,
commands::TYPE, option_type, option_data_string); commands::TYPE, ots, option_data_string)
} }
} }

2
tests/lib.rs

@ -89,7 +89,7 @@ fn engine_option_string() {
let o = EngineOption { let o = EngineOption {
name: name, name: name,
option_type: option_type, option_type: option_type,
option_data: option_data1, option_data: option_data,
}; };
let expected = "option name hash type spin default 1 min 1 max 128\n"; let expected = "option name hash type spin default 1 min 1 max 128\n";

Loading…
Cancel
Save