Implement dialogue file validator debug event.

This commit is contained in:
Mari the Deer 2023-09-04 14:08:18 +02:00
commit 4bcee65ace
2 changed files with 168 additions and 2 deletions

View file

@ -440,6 +440,172 @@ Class SWWMStaticHandler : StaticEventHandler
}
if ( !fail ) Console.Printf("ALL OK");
}
else if ( e.Name ~== "swwmvalidatedlgfiles" )
{
for ( int lmp = Wads.FindLumpFullName("swwmdialogue",0,true); lmp != -1; lmp = Wads.FindLumpFullName("swwmdialogue",lmp+1,true) )
{
Console.Printf("\ce-- PARSING FILE \cf'%s'\ce...\c-",Wads.GetLumpFullName(lmp));
Console.Printf("");
String dat = Wads.ReadLump(lmp);
dat.Replace("\r",""); // just in case
Array<String> lines;
lines.Clear();
dat.Split(lines,"\n",0);
// strip comments and trim whitespace
for ( int i=0; i<lines.Size(); i++ )
{
int cmm = lines[i].IndexOf("#");
if ( cmm != -1 ) lines[i].Truncate(cmm);
lines[i].StripLeftRight();
}
int cur = 0;
bool indlg = false;
bool inseq = false, gotseq = false;
int nseq = 0;
String sdlg, schr, sname;
int scnt, sdelay, sstartdelay, senddelay, schardelay, spausedelay;
bool sindirect, sznvspecial;
while ( cur < lines.Size() )
{
// skip empty lines
if ( lines[cur] == "" )
{
cur++;
continue;
}
// sequence ends here
// dialogue ends here
if ( lines[cur].Left(6) == "ENDDLG" )
{
if ( !indlg ) ThrowAbortException("line %d, 'ENDDLG' found without start of dialogue.",cur+1);
if ( inseq ) ThrowAbortException("dialogue '%s', line %d, premature end of sequence %d.",sdlg,cur+1,nseq);
if ( !gotseq ) ThrowAbortException("dialogue '%s', line %d, dialogue is empty.",sdlg,cur+1);
Console.Printf("");
indlg = false;
cur++;
continue;
}
if ( !indlg )
{
if ( lines[cur].Left(4) == "DLG " )
{
sdlg = lines[cur].Mid(4);
Console.Printf("\cqdialogue \cd'%s'\cq:\c-",sdlg);
indlg = true;
nseq = 1;
cur++;
continue;
}
ThrowAbortException("line %d, expected 'DLG' directive",cur+1);
return;
}
if ( inseq )
{
// fetch params until we find ENDSEQ
if ( lines[cur].Left(6) == "ENDSEQ" )
{
// put out the sequence
if ( sname == "" ) ThrowAbortException("dialogue '%s', line %d, sequence %d has no name.",sdlg,cur+1,nseq);
if ( scnt <= 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d has invalid count.",sdlg,cur+1,nseq);
Console.Printf(" \cqsequence \cd%d\cq with character \cd'%s'\cq, name \cd'%s'\cq:\c-",nseq,schr,sname);
if ( sdelay > 0 ) Console.Printf(" \cqdelay: \cd%d\c-",sdelay);
if ( sstartdelay > 0 ) Console.Printf(" \cqstartdelay: \cd%d\c-",sstartdelay);
if ( senddelay > 0 ) Console.Printf(" \cqenddelay: \cd%d\c-",senddelay);
if ( schardelay > 0 ) Console.Printf(" \cqchardelay: \cd%d\c-",schardelay);
if ( spausedelay > 0 ) Console.Printf(" \cqpausedelay: \cd%d\c-",spausedelay);
if ( sznvspecial ) Console.Printf(" \cq+\cdznvspecial\c-");
if ( sindirect ) Console.Printf(" \cq+\cdindirect\c-");
Console.Printf(" \cqcount: \cd%d\c-\n\cd---\c-",scnt);
for ( int i=0; i<scnt; i++ )
{
String ln = StringTable.Localize("$SWWM_"..sname..(i+1));
if ( (i == 1) && sznvspecial )
{
int nyears = SystemTime.Format("%Y",SystemTime.Now()).ToInt()-2010;
ln = String.Format(ln,nyears);
}
Console.Printf("%s\n\cd---\c-",ln);
}
gotseq = true;
inseq = false;
nseq++;
}
else if ( lines[cur].Left(5) == "NAME " )
{
if ( sname != "" ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'NAME' parameter.",sdlg,cur+1,nseq);
sname = lines[cur].Mid(5);
}
else if ( lines[cur].Left(4) == "CNT " )
{
if ( scnt > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'CNT' parameter.",sdlg,cur+1,nseq);
scnt = lines[cur].Mid(4).ToInt();
}
else if ( lines[cur].Left(6) == "DELAY " )
{
if ( sdelay > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'DELAY' parameter.",sdlg,cur+1,nseq);
sdelay = lines[cur].Mid(6).ToInt();
}
else if ( lines[cur].Left(11) == "STARTDELAY " )
{
if ( sstartdelay > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'STARTDELAY' parameter.",sdlg,cur+1,nseq);
sstartdelay = lines[cur].Mid(11).ToInt();
}
else if ( lines[cur].Left(9) == "ENDDELAY " )
{
if ( senddelay > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'ENDDELAY' parameter.",sdlg,cur+1,nseq);
senddelay = lines[cur].Mid(9).ToInt();
}
else if ( lines[cur].Left(10) == "CHARDELAY " )
{
if ( schardelay > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'CHARDELAY' parameter.",sdlg,cur+1,nseq);
schardelay = lines[cur].Mid(10).ToInt();
}
else if ( lines[cur].Left(11) == "PAUSEDELAY " )
{
if ( spausedelay > 0 ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'PAUSEDELAY' parameter.",sdlg,cur+1,nseq);
spausedelay = lines[cur].Mid(11).ToInt();
}
else if ( lines[cur].Left(8) == "INDIRECT" )
{
if ( sindirect ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'INDIRECT' parameter.",sdlg,cur+1,nseq);
sindirect = true;
}
else if ( lines[cur].Left(10) == "ZNVSPECIAL" )
{
if ( sznvspecial ) ThrowAbortException("dialogue '%s', line %d, sequence %d, duplicate 'ZNVSPECIAL' parameter.",sdlg,cur+1,nseq);
sznvspecial = true;
}
else ThrowAbortException("dialogue '%s', line %d, sequence %d, parameter not recognized",sdlg,cur+1,nseq);
cur++;
continue;
}
if ( lines[cur].Left(4) == "SEQ " )
{
// begin dialogue
inseq = true;
schr = lines[cur].Mid(4);
// wipe params
sname = "";
scnt = 0;
sdelay = 0;
sstartdelay = 0;
senddelay = 0;
schardelay = 0;
spausedelay = 0;
sindirect = false;
sznvspecial = false;
cur++;
continue;
}
ThrowAbortException("dialogue '%s', line %d, expected 'SEQ' directive",sdlg,cur+1);
return;
}
if ( indlg ) ThrowAbortException("line %d, premature end of file reached for dialogue '%s'",cur+1,sdlg);
if ( inseq ) ThrowAbortException("dialogue '%s', line %d, premature end of file reached for sequence %d",sdlg,cur+1,nseq);
Console.Printf("\ce-- END OF FILE \cf'%s'\ce...\c-",Wads.GetLumpFullName(lmp));
Console.Printf("");
}
}
else if ( e.Name ~== "swwmdumpmonsters" )
{
int i = 0;