From dcf8079592847e3dda3878dd339b5a566ca79638 Mon Sep 17 00:00:00 2001 From: ashley Date: Wed, 20 Sep 2023 23:45:02 -0400 Subject: [PATCH] Provide info for entity-component export --- src/reskit/level/converter.rs | 1 - src/reskit/level/system.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/reskit/level/converter.rs b/src/reskit/level/converter.rs index f930661..0b96a4e 100644 --- a/src/reskit/level/converter.rs +++ b/src/reskit/level/converter.rs @@ -172,7 +172,6 @@ pub fn get_tiled_tilemap( path: &str ) -> Result> { result } }; - println!( "working directory is {}/", working_directory ); let map = document.descendants().find( | node | node.tag_name() == "map".into() ); if let Some( map ) = map { diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index dc69e5e..28acfa5 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -385,6 +385,40 @@ pub fn get_ecs( tilemap: &TiledTilemap ) -> Result, Box> { print_info( &format!( "Component ID {}: {}", i, component_ids[ i ] ) ); } + // Output type structures to terminal + let mut visited_types: LinkedHashSet> = LinkedHashSet::new(); + for entity in &tilemap.ecs { + // Do the thing again + let mut components: Vec = entity.components.keys().map( | id | id.to_lowercase() ).collect(); + components.sort(); + let components: LinkedHashSet = 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 ) }