From 1b5eec9eaf4bef15956dbff5a18fc30d9c33bc4e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 25 Apr 2024 04:25:32 -0700 Subject: [PATCH] if model name is illegal prompt for new name --- src/main.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c9a1a86..50fb7ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -539,19 +539,44 @@ fn interactive() -> AResult<()>{ let mut allowed_map=get_allowed_map()?; let mut replace_map=get_replace_map()?; let mut blocked = get_blocked()?; + let model_name_pattern=lazy_regex::regex!(r"^[a-z0-9_]+$"); 'map_loop: for entry in std::fs::read_dir("maps/unprocessed")? { let file_thing=entry?; println!("processing map={:?}",file_thing.file_name()); let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?); let mut dom = get_dom(&mut input)?; + let (modelname,creator,displayname) = get_mapinfo(&dom)?; + + let mut script_count=0; + let mut replace_count=0; + let mut block_count=0; + + //if model name is illegal prompt for new name + print!("Model name: {}\nCreator: {}\nDisplayName: {}\n",modelname,creator,displayname); + if !model_name_pattern.is_match(modelname.as_str()){ + //illegal + let new_model_name; + loop{ + print!("Enter new model name: "); + std::io::Write::flush(&mut std::io::stdout())?; + let mut input_string=String::new(); + std::io::stdin().read_line(&mut input_string)?; + if model_name_pattern.is_match(input_string.trim()){ + new_model_name=input_string.trim().to_owned(); + break; + } + } + if let Some(model_instance)=dom.get_by_ref_mut(dom.root().children()[0]){ + model_instance.name=new_model_name; + //mark file as edited so a new file is generated + replace_count+=1; + } + } let script_refs = get_script_refs(&dom); //check scribb - let mut script_count=0; - let mut replace_count=0; - let mut block_count=0; let mut fail_type=Interactive::Passed; for &script_ref in script_refs.iter() { if let Some(script)=dom.get_by_ref(script_ref){