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
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum EngineOptionType {
Check("check"),
Spin("spin"),
Combo("combo"),
Button("button"),
TypeString("string"), // `String` is a reserved word so `TypeString` is substituted
Check,
Spin,
Combo,
Button,
TypeString, // `String` is a reserved word so `TypeString` is substituted
}
#[derive(Clone, Debug, PartialEq, PartialOrd)]
@ -68,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"), // `Default` is reserved so `DefaultVal` is used
Min("min"),
Max("max"),
Var("var"),
DefaultVal, // `Default` is reserved so `DefaultVal` is used
Min,
Max,
Var,
}
#[derive(Debug, PartialEq)]
@ -91,14 +91,34 @@ impl EngineOption {
}
pub fn option_string(&self) -> String {
let option_data_string: String;
for dt, eod in &self.option_data {
option_data_string = option_data_string + format!("{} {}", dt, eod);
let mut option_data_string: String = "".to_owned();
for (ref dt, ref eod) in &self.option_data {
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,
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 {
name: name,
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";

Loading…
Cancel
Save