Provide info for entity-component export
parent
efa2c24487
commit
dcf8079592
|
@ -172,7 +172,6 @@ pub fn get_tiled_tilemap( path: &str ) -> Result<TiledTilemap, Box<dyn Error>> {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!( "working directory is {}/", working_directory );
|
|
||||||
|
|
||||||
let map = document.descendants().find( | node | node.tag_name() == "map".into() );
|
let map = document.descendants().find( | node | node.tag_name() == "map".into() );
|
||||||
if let Some( map ) = map {
|
if let Some( map ) = map {
|
||||||
|
|
|
@ -385,6 +385,40 @@ pub fn get_ecs( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
print_info( &format!( "Component ID {}: {}", i, component_ids[ i ] ) );
|
print_info( &format!( "Component ID {}: {}", i, component_ids[ i ] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output type structures to terminal
|
||||||
|
let mut visited_types: LinkedHashSet<LinkedHashSet<String>> = LinkedHashSet::new();
|
||||||
|
for entity in &tilemap.ecs {
|
||||||
|
// Do the thing again
|
||||||
|
let mut components: Vec<String> = entity.components.keys().map( | id | id.to_lowercase() ).collect();
|
||||||
|
components.sort();
|
||||||
|
let components: LinkedHashSet<String> = components.into_iter().collect();
|
||||||
|
|
||||||
|
if visited_types.insert( components.clone() ) {
|
||||||
|
// What type id is this?
|
||||||
|
let type_id: u8 = types.iter().position( | ecs_type | ecs_type == &components ).ok_or( "internal error: no type id" )? as u8;
|
||||||
|
print_info( &format!( "Type ID {} Components and Attributes:", type_id ) );
|
||||||
|
|
||||||
|
let mut components: Vec<(&String, &Component)> = entity.components.iter().collect();
|
||||||
|
components.sort_by( | a, b | a.0.partial_cmp( b.0 ).expect( "internal error: unsortable" ) );
|
||||||
|
|
||||||
|
for ( component_name, component ) in components {
|
||||||
|
print_info( &format!( "\tComponent {}", component_name ) );
|
||||||
|
let mut attributes: Vec<(&String, &String)> = component.attributes.iter().collect();
|
||||||
|
attributes.sort_by( | a, b | a.0.partial_cmp( b.0 ).expect( "internal error: unsortable" ) );
|
||||||
|
|
||||||
|
let mut index = 0;
|
||||||
|
for ( attribute_name, _ ) in &attributes {
|
||||||
|
print_info( &format!( "\t\tAttribute ID {}: {}", index, attribute_name ) );
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if attributes.is_empty() {
|
||||||
|
print_info( "\t\tNo attributes" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok( result )
|
Ok( result )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue