diff --git a/macro_ui/src/parse.rs b/macro_ui/src/parse.rs index 913db2ab..92ee2768 100644 --- a/macro_ui/src/parse.rs +++ b/macro_ui/src/parse.rs @@ -50,7 +50,7 @@ pub fn parse_struct_field(field: &Field) -> TokenStream2 { } else if is_option(field) { let option_type = &get_option_type(field); quote! { - #field_name: if parser.get_str(&format!("{}.{}", path, stringify!(#field_name))).is_some() { + #field_name: if parser.parse_bool(&format!("{}.{}.availability", path, stringify!(#field_name))) { Some(#option_type::parse(parser, &format!("{}.{}", path, stringify!(#field_name)), &format!(" {}", spaces))) } else { Option::None diff --git a/resources/templates/appearance_edit.html.tera b/resources/templates/appearance_edit.html.tera index 9a759c01..5b18b4f4 100644 --- a/resources/templates/appearance_edit.html.tera +++ b/resources/templates/appearance_edit.html.tera @@ -466,29 +466,27 @@ Color: {{ macros::add_select(name="appearance.body.clothing.pants.color", options=[ "Aqua","Black","Blue","Fuchsia","Gray","Green","Lime","Maroon","Navy","Olive","Orange","Purple","Red","SaddleBrown","Silver","Teal","White","Yellow" ], selected=appearance.body.clothing.pants.color, update=true) }}
  • - Belt: {{ macros::add_select(name="appearance.body.clothing.pants.belt.available", options=[ "true","false" ], selected=appearance.body.clothing.pants.belt.available, update=true) }} - {% if appearance.body.clothing.pants.belt.available == "true" %} + {% if appearance.body.clothing.pants.belt %} + Belt Availability: {{ macros::add_select(name="appearance.body.clothing.pants.belt.availability", options=[ "true","false" ], selected=true, update=true) }} + Belt + {% else %} + Belt Availability: {{ macros::add_select(name="appearance.body.clothing.pants.belt.availability", options=[ "true","false" ], selected=false, update=true) }} {% endif %}
  • diff --git a/resources/templates/character.html.tera b/resources/templates/character.html.tera index 5afae22d..b3a92c53 100644 --- a/resources/templates/character.html.tera +++ b/resources/templates/character.html.tera @@ -467,28 +467,23 @@ Color: {{ appearance.body.clothing.pants.color }}
  • + {% if appearance.body.clothing.pants.belt %} Belt - {% if appearance.body.clothing.pants.belt.available %} {% endif %}
  • diff --git a/rpg_tools_core/src/ui/editor.rs b/rpg_tools_core/src/ui/editor.rs index 2a08e079..61e72314 100644 --- a/rpg_tools_core/src/ui/editor.rs +++ b/rpg_tools_core/src/ui/editor.rs @@ -48,16 +48,17 @@ impl EditorVisitor { } fn add_selection(&mut self, path: &str, variants: &[String]) { - self.add_named_selection(&self.get_name(), path, variants); + self.add_named_selection(&self.get_name(), path, variants, path); } - fn add_named_selection(&mut self, name: &str, path: &str, variants: &[String]) { + fn add_named_selection(&mut self, name: &str, path: &str, variants: &[String], selected: &str) { self.lines.push(format!( - "{0}{1}: {{{{ macros::add_select(name=\"{2}\", options=[ {3} ], selected={2}, update=true) }}}}", + "{}{}: {{{{ macros::add_select(name=\"{}\", options=[ {} ], selected={}, update=true) }}}}", self.spaces, name, path, variants.iter().map(|v| format!("\"{}\"", v)).collect::>().join(","), + selected, )); } } @@ -101,22 +102,24 @@ impl UiVisitor for EditorVisitor { } fn enter_option(&mut self) { - self.add_selection( - &format!("{}.available", self.get_path()), + self.lines + .push(format!("{}{{% if {} %}}", self.spaces, self.get_path(),)); + self.add_named_selection( + &format!("{} Availability", self.get_name()), + &format!("{}.availability", self.get_path()), &vec!["true".to_string(), "false".to_string()], + "true", ); - self.lines.push(format!( - "{}{{% if {}.available == \"true\" %}}", - self.spaces, - self.get_path(), - )); - self.enter_list(); - self.enter_child("value"); } fn leave_option(&mut self) { - self.leave_child(); - self.leave_list(); + self.lines.push(format!("{}{{% else %}}", self.spaces)); + self.add_named_selection( + &format!("{} Availability", self.get_name()), + &format!("{}.availability", self.get_path()), + &vec!["true".to_string(), "false".to_string()], + "false", + ); self.lines.push(format!("{}{{% endif %}}", self.spaces)); } diff --git a/rpg_tools_core/src/ui/viewer.rs b/rpg_tools_core/src/ui/viewer.rs index 7a166c5a..b76270e1 100644 --- a/rpg_tools_core/src/ui/viewer.rs +++ b/rpg_tools_core/src/ui/viewer.rs @@ -93,17 +93,10 @@ impl UiVisitor for ViewerVisitor { fn enter_option(&mut self) { self.lines - .push(format!("{}{}", self.spaces, self.get_name(),)); - self.lines.push(format!( - "{}{{% if {} %}}", - self.spaces, - self.get_path(), - )); - self.enter_list(); + .push(format!("{}{{% if {} %}}", self.spaces, self.get_path(),)); } fn leave_option(&mut self) { - self.leave_list(); self.lines.push(format!("{}{{% endif %}}", self.spaces)); }