unsafe fn save_faction_banner_data(&self, data: &[HashMap<String, String>]) -> Result<PackedFile> {

        let table_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_table_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_table_name".to_owned())))?;
        let table_definition_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_table_definition").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_table_definition".to_owned())))?;
        let primary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_primary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_primary_colour_column_name".to_owned())))?;
        let secondary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_secondary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_secondary_colour_column_name".to_owned())))?;
        let tertiary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_tertiary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_tertiary_colour_column_name".to_owned())))?;
        let row_key = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_row_key").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_row_key".to_owned())))?;

        let key_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_key_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_key_column_name".to_owned())))?;

        if let Some(first) = data.iter().next() {
            if let Some(definition) = first.get(table_definition_name) {
                let definition = serde_json::from_str(definition)?;
                let mut table = DB::new(&table_name, None, &definition);

                let fields_processed = definition.get_fields_processed();
                let key_column = table.get_column_position_by_name(key_column_name)?;

                let primary_colour_column = table.get_column_position_by_name(primary_colour_column_name)?;
                let secondary_colour_column = table.get_column_position_by_name(secondary_colour_column_name)?;
                let tertiary_colour_column = table.get_column_position_by_name(tertiary_colour_column_name)?;

                let table_data = data.par_iter()
                    .filter_map(|row_data| {

                        // Check if the original line is found, use it. If not, make a new line.
                        let mut row = if let Some(row) = row_data.get(row_key) {
                            serde_json::from_str(row).ok()?
                        } else {
                            let key = row_data.get("key")?;
                            let mut row = table.get_new_row();
                            row[key_column] = match fields_processed[key_column].get_field_type() {
                                FieldType::StringU8 => DecodedData::StringU8(key.to_owned()),
                                FieldType::StringU16 => DecodedData::StringU16(key.to_owned()),
                                FieldType::OptionalStringU8 => DecodedData::OptionalStringU8(key.to_owned()),
                                FieldType::OptionalStringU16 => DecodedData::OptionalStringU16(key.to_owned()),
                                _ => unimplemented!()
                            };
                            row
                        };

                        if row_data.get("banner_primary").is_some() {
                            let primary = u32::from_str_radix(row_data.get("banner_primary")?, 16).ok()?;
                            let secondary = u32::from_str_radix(row_data.get("banner_secondary")?, 16).ok()?;
                            let tertiary = u32::from_str_radix(row_data.get("banner_tertiary")?, 16).ok()?;

                            row[primary_colour_column] = DecodedData::ColourRGB(primary);
                            row[secondary_colour_column] = DecodedData::ColourRGB(secondary);
                            row[tertiary_colour_column] = DecodedData::ColourRGB(tertiary);

                            Some(row)
                        } else {
                            None
                        }
                    }).collect::<Vec<Vec<DecodedData>>>();

                table.set_table_data(&table_data)?;
                let path = vec!["db".to_owned(), table_name.to_owned(), self.get_file_name()];
                Ok(PackedFile::new_from_decoded(&DecodedPackedFile::DB(table), &path))
            } else { Err(ErrorKind::Impossibru.into()) }
        } else { Err(ErrorKind::Impossibru.into()) }
    }
/// This function takes care of saving the banner's data into a PackedFile.
This function takes care of saving the banner's data into a PackedFile.
This function takes care of saving the banner ' s data into a PackedFile .
unsafe fn save_faction_banner_data(&self, data: &[HashMap<String, String>]) -> Result<PackedFile> {
        let table_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_table_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_table_name".to_owned())))?;
        let table_definition_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_table_definition").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_table_definition".to_owned())))?;
        let primary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_primary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_primary_colour_column_name".to_owned())))?;
        let secondary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_secondary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_secondary_colour_column_name".to_owned())))?;
        let tertiary_colour_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_tertiary_colour_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_tertiary_colour_column_name".to_owned())))?;
        let row_key = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_row_key").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_row_key".to_owned())))?;
        let key_column_name = GAME_SELECTED.read().unwrap().get_tool_var("faction_painter_banner_key_column_name").ok_or_else(|| Error::from(ErrorKind::ToolVarNotFoundForGame("faction_painter_banner_key_column_name".to_owned())))?;
        if let Some(first) = data.iter().next() {
            if let Some(definition) = first.get(table_definition_name) {
                let definition = serde_json::from_str(definition)?;
                let mut table = DB::new(&table_name, None, &definition);
                let fields_processed = definition.get_fields_processed();
                let key_column = table.get_column_position_by_name(key_column_name)?;
                let primary_colour_column = table.get_column_position_by_name(primary_colour_column_name)?;
                let secondary_colour_column = table.get_column_position_by_name(secondary_colour_column_name)?;
                let tertiary_colour_column = table.get_column_position_by_name(tertiary_colour_column_name)?;
                let table_data = data.par_iter()
                    .filter_map(|row_data| {
                        // Check if the original line is found, use it. If not, make a new line.
                        let mut row = if let Some(row) = row_data.get(row_key) {
                            serde_json::from_str(row).ok()?
                        } else {
                            let key = row_data.get("key")?;
                            let mut row = table.get_new_row();
                            row[key_column] = match fields_processed[key_column].get_field_type() {
                                FieldType::StringU8 => DecodedData::StringU8(key.to_owned()),
                                FieldType::StringU16 => DecodedData::StringU16(key.to_owned()),
                                FieldType::OptionalStringU8 => DecodedData::OptionalStringU8(key.to_owned()),
                                FieldType::OptionalStringU16 => DecodedData::OptionalStringU16(key.to_owned()),
                                _ => unimplemented!()
                            };
                            row
                        };
                        if row_data.get("banner_primary").is_some() {
                            let primary = u32::from_str_radix(row_data.get("banner_primary")?, 16).ok()?;
                            let secondary = u32::from_str_radix(row_data.get("banner_secondary")?, 16).ok()?;
                            let tertiary = u32::from_str_radix(row_data.get("banner_tertiary")?, 16).ok()?;
                            row[primary_colour_column] = DecodedData::ColourRGB(primary);
                            row[secondary_colour_column] = DecodedData::ColourRGB(secondary);
                            row[tertiary_colour_column] = DecodedData::ColourRGB(tertiary);
                            Some(row)
                        } else {
                            None
                        }
                    }).collect::<Vec<Vec<DecodedData>>>();
                table.set_table_data(&table_data)?;
                let path = vec!["db".to_owned(), table_name.to_owned(), self.get_file_name()];
                Ok(PackedFile::new_from_decoded(&DecodedPackedFile::DB(table), &path))
            } else { Err(ErrorKind::Impossibru.into()) }
        } else { Err(ErrorKind::Impossibru.into()) }
    }
unsafe fn save_faction_banner_data ( & self , data : & [ HashMap < String , String > ] ) -> Result < PackedFile > { let table_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let table_definition_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let primary_colour_column_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let secondary_colour_column_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let tertiary_colour_column_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let row_key = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; let key_column_name = GAME_SELECTED . read ( ) . unwrap ( ) . get_tool_var ( " " ) . ok_or_else ( | | Error :: from ( ErrorKind :: ToolVarNotFoundForGame ( " " . to_owned ( ) ) ) ) ? ; if let Some ( first ) = data . iter ( ) . next ( ) { if let Some ( definition ) = first . get ( table_definition_name ) { let definition = serde_json :: from_str ( definition ) ? ; let mut table = DB :: new ( & table_name , None , & definition ) ; let fields_processed = definition . get_fields_processed ( ) ; let key_column = table . get_column_position_by_name ( key_column_name ) ? ; let primary_colour_column = table . get_column_position_by_name ( primary_colour_column_name ) ? ; let secondary_colour_column = table . get_column_position_by_name ( secondary_colour_column_name ) ? ; let tertiary_colour_column = table . get_column_position_by_name ( tertiary_colour_column_name ) ? ; let table_data = data . par_iter ( ) . filter_map ( | row_data | { // Check if the original line is found, use it. If not, make a new line. let mut row = if let Some ( row ) = row_data . get ( row_key ) { serde_json :: from_str ( row ) . ok ( ) ? } else { let key = row_data . get ( " " ) ? ; let mut row = table . get_new_row ( ) ; row [ key_column ] = match fields_processed [ key_column ] . get_field_type ( ) { FieldType :: StringU8 => DecodedData :: StringU8 ( key . to_owned ( ) ) , FieldType :: StringU16 => DecodedData :: StringU16 ( key . to_owned ( ) ) , FieldType :: OptionalStringU8 => DecodedData :: OptionalStringU8 ( key . to_owned ( ) ) , FieldType :: OptionalStringU16 => DecodedData :: OptionalStringU16 ( key . to_owned ( ) ) , _ => unimplemented ! ( ) } ; row } ; if row_data . get ( " " ) . is_some ( ) { let primary = u32 :: from_str_radix ( row_data . get ( " " ) ? , 16 ) . ok ( ) ? ; let secondary = u32 :: from_str_radix ( row_data . get ( " " ) ? , 16 ) . ok ( ) ? ; let tertiary = u32 :: from_str_radix ( row_data . get ( " " ) ? , 16 ) . ok ( ) ? ; row [ primary_colour_column ] = DecodedData :: ColourRGB ( primary ) ; row [ secondary_colour_column ] = DecodedData :: ColourRGB ( secondary ) ; row [ tertiary_colour_column ] = DecodedData :: ColourRGB ( tertiary ) ; Some ( row ) } else { None } } ) . collect :: < Vec < Vec < DecodedData > > > ( ) ; table . set_table_data ( & table_data ) ? ; let path = vec ! [ " " to_owned ( ) table_name to_owned ( ) self get_file_name ( ) ] ; Ok ( PackedFile :: new_from_decoded ( & DecodedPackedFile :: DB ( table ) , & path ) ) } else { Err ( ErrorKind :: Impossibru . into ( ) ) } } else { Err ( ErrorKind :: Impossibru . into ( ) ) } }
This function takes care of saving the banner's data into a PackedFile.
This function takes care of saving the banner ' s data into a PackedFile .
&self
data
&[HashMap<String, String>]
&self
data
&[HashMap<String, String>]