Attribute export

stinkhead7ds
Ashley N. 2023-09-23 12:44:56 -04:00
parent 9d461a6c41
commit 5ba27514e7
1 changed files with 29 additions and 1 deletions

View File

@ -449,9 +449,12 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -
total_tiles
};
let mut constants: String = String::new();
// Output IDs for each type defined in the map
let mut component_ids: LinkedHashSet<String> = LinkedHashSet::new();
let mut attribute_ids: LinkedHashMap<String, LinkedHashSet<String>> = LinkedHashMap::new();
let mut attribute_string_values: LinkedHashSet<String> = LinkedHashSet::new();
for entity in &tilemap.ecs {
let mut components: Vec<String> = entity.components.keys().map( | id | id.to_lowercase() ).collect();
components.sort();
@ -460,6 +463,18 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -
component_ids.extend( components );
for ( component_name, component ) in &entity.components {
for ( _, attribute_value ) in &component.attributes {
match attribute_value.as_str() {
"true" | "false" => { /* nothing */ },
string => {
let try_as_u16: Result<u16, ParseIntError> = string.parse();
if let Err( _ ) = try_as_u16 {
attribute_string_values.insert_if_absent( attribute_value.to_owned() );
}
}
}
}
let mut attributes: Vec<String> = component.attributes.keys().map( | id | id.to_lowercase() ).collect();
attributes.sort();
let attribues: LinkedHashSet<String> = attributes.into_iter().collect();
@ -468,8 +483,21 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -
}
}
let attribute_string_values: Vec<String> = attribute_string_values.into_iter().collect();
for i in 0..attribute_string_values.len() {
let attr_val = &attribute_string_values[ i ];
match attr_val.as_str() {
"true" | "false" => { /* nothing */ },
string => {
let try_as_u16: Result<u16, ParseIntError> = string.parse();
if let Err( _ ) = try_as_u16 {
constants += &format!( "{}_ATTR_{} = {}\n", level_label_const_caps, attribute_string_values[ i ].to_uppercase(), i );
}
}
}
}
let component_ids: Vec<String> = component_ids.into_iter().collect();
let mut constants: String = String::new();
for i in 0..component_ids.len() {
let component_id = &component_ids[ i ];
constants += &format!( "{}_{} = {}\n", level_label_const_caps, component_id.to_uppercase(), i );