forked from StrafesNET/map-tool
if model name is illegal prompt for new name
This commit is contained in:
parent
ef5703f282
commit
1b5eec9eaf
31
src/main.rs
31
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){
|
||||
|
Loading…
Reference in New Issue
Block a user