parent
c63997d161
commit
343a4011dd
@ -48,23 +48,9 @@ enum Zone{
|
||||
|
||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
|
||||
struct ModeID(u64);
|
||||
macro_rules! write_zone{
|
||||
($fname:ident,$zone:expr)=>{
|
||||
fn $fname(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
match self{
|
||||
ModeID(0)=>write!(f,concat!("Map",$zone)),
|
||||
ModeID(1)=>write!(f,concat!("Bonus",$zone)),
|
||||
ModeID(other)=>write!(f,concat!("Bonus{}",$zone),other),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
impl ModeID{
|
||||
const MAIN:Self=Self(0);
|
||||
const BONUS:Self=Self(1);
|
||||
write_zone!(write_start_zone,"Start");
|
||||
write_zone!(write_finish_zone,"Finish");
|
||||
write_zone!(write_anticheat_zone,"Anticheat");
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub enum ZoneParseError{
|
||||
@ -426,10 +412,11 @@ impl<'a> MapCheck<'a>{
|
||||
}
|
||||
}
|
||||
|
||||
fn comma_separated<T,F>(f:&mut std::fmt::Formatter<'_>,mut it:impl Iterator<Item=T>,custom_write:F)->std::fmt::Result
|
||||
where
|
||||
F:Fn(&mut std::fmt::Formatter<'_>,T)->std::fmt::Result,
|
||||
{
|
||||
fn write_comma_separated<T>(
|
||||
f:&mut std::fmt::Formatter<'_>,
|
||||
mut it:impl Iterator<Item=T>,
|
||||
custom_write:impl Fn(&mut std::fmt::Formatter<'_>,T)->std::fmt::Result
|
||||
)->std::fmt::Result{
|
||||
if let Some(t)=it.next(){
|
||||
custom_write(f,t)?;
|
||||
for t in it{
|
||||
@ -440,6 +427,15 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
macro_rules! write_zone{
|
||||
($f:expr,$mode:expr,$zone:expr)=>{
|
||||
match $mode{
|
||||
ModeID(0)=>write!($f,concat!("Map",$zone)),
|
||||
ModeID(1)=>write!($f,concat!("Bonus",$zone)),
|
||||
ModeID(other)=>write!($f,concat!("Bonus{}",$zone),other),
|
||||
}
|
||||
};
|
||||
}
|
||||
impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
if let StringCheck(Err(context))=&self.model_class{
|
||||
@ -471,8 +467,8 @@ impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||
}
|
||||
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.mode_start_counts{
|
||||
write!(f,"Duplicate start zones: ")?;
|
||||
comma_separated(f,context.iter(),|f,(mode_id,count)|{
|
||||
mode_id.write_start_zone(f)?;
|
||||
write_comma_separated(f,context.iter(),|f,(mode_id,count)|{
|
||||
write_zone!(f,mode_id,"Start")?;
|
||||
write!(f,"({count} duplicates)")?;
|
||||
Ok(())
|
||||
})?;
|
||||
@ -482,16 +478,16 @@ impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||
// perhaps there are extra end zones (context.extra)
|
||||
if !context.extra.is_empty(){
|
||||
write!(f,"Extra finish zones with no matching start zone: ")?;
|
||||
comma_separated(f,context.extra.iter(),|f,(mode_id,_count)|
|
||||
mode_id.write_finish_zone(f)
|
||||
write_comma_separated(f,context.extra.iter(),|f,(mode_id,_count)|
|
||||
write_zone!(f,mode_id,"Finish")
|
||||
)?;
|
||||
writeln!(f,"")?;
|
||||
}
|
||||
// perhaps there are missing end zones (context.missing)
|
||||
if !context.missing.is_empty(){
|
||||
write!(f,"Missing finish zones: ")?;
|
||||
comma_separated(f,context.missing.iter(),|f,mode_id|
|
||||
mode_id.write_finish_zone(f)
|
||||
write_comma_separated(f,context.missing.iter(),|f,mode_id|
|
||||
write_zone!(f,mode_id,"Finish")
|
||||
)?;
|
||||
writeln!(f,"")?;
|
||||
}
|
||||
@ -500,8 +496,8 @@ impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||
// perhaps there are extra end zones (context.extra)
|
||||
if !context.extra.is_empty(){
|
||||
write!(f,"Extra anticheat zones with no matching start zone: ")?;
|
||||
comma_separated(f,context.extra.iter(),|f,(mode_id,_count)|
|
||||
mode_id.write_anticheat_zone(f)
|
||||
write_comma_separated(f,context.extra.iter(),|f,(mode_id,_count)|
|
||||
write_zone!(f,mode_id,"Anticheat")
|
||||
)?;
|
||||
writeln!(f,"")?;
|
||||
}
|
||||
@ -511,14 +507,14 @@ impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||
}
|
||||
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.spawn_counts{
|
||||
write!(f,"Duplicate spawn zones: ")?;
|
||||
comma_separated(f,context.iter(),|f,(SpawnID(spawn_id),count)|
|
||||
write_comma_separated(f,context.iter(),|f,(SpawnID(spawn_id),count)|
|
||||
write!(f,"Spawn{spawn_id}({count} duplicates)")
|
||||
)?;
|
||||
writeln!(f,"")?;
|
||||
}
|
||||
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.wormhole_out_counts{
|
||||
write!(f,"Duplicate wormhole out: ")?;
|
||||
comma_separated(f,context.iter(),|f,(WormholeOutID(wormhole_out_id),count)|
|
||||
write_comma_separated(f,context.iter(),|f,(WormholeOutID(wormhole_out_id),count)|
|
||||
write!(f,"WormholeOut{wormhole_out_id}({count} duplicates)")
|
||||
)?;
|
||||
writeln!(f,"")?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user