Export constants to asm file
parent
94bec93c06
commit
62fcb599cc
|
@ -1,5 +1,6 @@
|
|||
use std::{error::Error, convert::TryInto, cmp::max, num::ParseIntError};
|
||||
use image::GenericImageView;
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use linked_hash_set::LinkedHashSet;
|
||||
use crate::reskit::{tileset::image_to_tiles, utility::{symbol_to_pascal, print_info}, cli::settings::TileOrder};
|
||||
use super::{converter::{TiledTilemap, Layer, SystemPlane}, ecs::Component};
|
||||
|
@ -436,6 +437,7 @@ pub fn get_ecs( tilemap: &TiledTilemap ) -> Result<Vec<u8>, Box<dyn Error>> {
|
|||
pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -> Result<String, Box<dyn Error>> {
|
||||
let version = env!( "CARGO_PKG_VERSION" );
|
||||
let level_label = symbol_to_pascal( level_name );
|
||||
let level_label_const_caps = level_label.to_uppercase();
|
||||
let ( width, height ) = ( tilemap.width, tilemap.height );
|
||||
let num_tiles = {
|
||||
let mut total_tiles = 0;
|
||||
|
@ -446,9 +448,43 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -
|
|||
|
||||
total_tiles
|
||||
};
|
||||
|
||||
// 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();
|
||||
for entity in &tilemap.ecs {
|
||||
let mut components: Vec<String> = entity.components.keys().map( | id | id.to_lowercase() ).collect();
|
||||
components.sort();
|
||||
let components: LinkedHashSet<String> = components.into_iter().collect();
|
||||
|
||||
component_ids.extend( components );
|
||||
|
||||
for ( component_name, component ) in &entity.components {
|
||||
let mut attributes: Vec<String> = component.attributes.keys().map( | id | id.to_lowercase() ).collect();
|
||||
attributes.sort();
|
||||
let attribues: LinkedHashSet<String> = attributes.into_iter().collect();
|
||||
|
||||
attribute_ids.entry( component_name.to_owned() ).or_default().extend( attribues );
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
let attribute_ids: Vec<String> = attribute_ids[ component_id ].iter().map( | string | string.clone() ).collect();
|
||||
for i in 0..attribute_ids.len() {
|
||||
constants += &format!( "\t{}_{}_{} = {}\n", level_label_const_caps, component_id.to_uppercase(), attribute_ids[ i ].to_uppercase(), i );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let file = format!( r#"; Level definition file
|
||||
; Generated by reskit v{version}
|
||||
|
||||
{constants}
|
||||
{level_label}Tiles:
|
||||
incbin '{path_prefix}{level_name}/tiles.bin'
|
||||
|
||||
|
@ -472,5 +508,6 @@ pub fn get_code( tilemap: &TiledTilemap, level_name: &str, path_prefix: &str ) -
|
|||
dc.l {level_label}Collision
|
||||
dc.l {level_label}Objects"# );
|
||||
|
||||
|
||||
Ok( file )
|
||||
}
|
Loading…
Reference in New Issue