forked from StrafesNET/map-tool
reject uncapitalized display names
This commit is contained in:
parent
8e9c76d6f8
commit
e92528ad83
34
src/main.rs
34
src/main.rs
@ -201,7 +201,7 @@ fn find_first_child_class<'a>(dom:&'a rbx_dom_weak::WeakDom,instance:&'a rbx_dom
|
||||
None
|
||||
}
|
||||
|
||||
fn get_mapinfo(dom:&rbx_dom_weak::WeakDom) -> AResult<(String,String,String)>{
|
||||
fn get_mapinfo(dom:&rbx_dom_weak::WeakDom) -> AResult<(String,String,String,rbx_dom_weak::types::Ref)>{
|
||||
let workspace_children=dom.root().children();
|
||||
if workspace_children.len()!=1{
|
||||
return Err(anyhow::Error::msg("there can only be one model"));
|
||||
@ -215,7 +215,7 @@ fn get_mapinfo(dom:&rbx_dom_weak::WeakDom) -> AResult<(String,String,String)>{
|
||||
creator.properties.get("Value"),
|
||||
displayname.properties.get("Value")
|
||||
){
|
||||
return Ok((model_instance.name.clone(),creator_string.clone(),displayname_string.clone()));
|
||||
return Ok((model_instance.name.clone(),creator_string.clone(),displayname_string.clone(),displayname.referent()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -425,7 +425,7 @@ fn upload() -> AResult<()>{
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
|
||||
|
||||
let dom = get_dom(&mut input)?;
|
||||
let (modelname,creator,displayname) = get_mapinfo(&dom)?;
|
||||
let (modelname,creator,displayname,_) = get_mapinfo(&dom)?;
|
||||
|
||||
//Creator: [auto fill creator]
|
||||
//DisplayName: [auto fill DisplayName]
|
||||
@ -540,13 +540,14 @@ fn interactive() -> AResult<()>{
|
||||
let mut replace_map=get_replace_map()?;
|
||||
let mut blocked = get_blocked()?;
|
||||
let model_name_pattern=lazy_regex::regex!(r"^[a-z0-9_]+$");
|
||||
let display_name_pattern=lazy_regex::regex!(r"\b[a-z]");
|
||||
|
||||
'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 (modelname,creator,displayname,displayname_ref)=get_mapinfo(&dom)?;
|
||||
|
||||
let mut script_count=0;
|
||||
let mut replace_count=0;
|
||||
@ -567,11 +568,28 @@ fn interactive() -> AResult<()>{
|
||||
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 model_instance=dom.get_by_ref_mut(dom.root().children()[0]).unwrap();
|
||||
model_instance.name=new_model_name;
|
||||
//mark file as edited so a new file is generated
|
||||
replace_count+=1;
|
||||
}
|
||||
if displayname.len()==0||display_name_pattern.is_match(displayname.as_str()){
|
||||
//illegal
|
||||
let new_display_name;
|
||||
loop{
|
||||
print!("Enter new display name: ");
|
||||
std::io::Write::flush(&mut std::io::stdout())?;
|
||||
let mut input_string=String::new();
|
||||
std::io::stdin().read_line(&mut input_string)?;
|
||||
if displayname.len()!=0||!display_name_pattern.is_match(input_string.trim()){
|
||||
new_display_name=input_string.trim().to_owned();
|
||||
break;
|
||||
}
|
||||
}
|
||||
let displayname_instance=dom.get_by_ref_mut(displayname_ref).unwrap();
|
||||
assert!(displayname_instance.properties.insert("Value".to_owned(),new_display_name.into()).is_some(),"StringValue we have a problem");
|
||||
//mark file as edited so a new file is generated
|
||||
replace_count+=1;
|
||||
}
|
||||
|
||||
let script_refs = get_script_refs(&dom);
|
||||
|
Loading…
Reference in New Issue
Block a user