2014-02-26 14:11:06 +00:00
using System ;
using System.Collections.Generic ;
2012-05-21 23:51:32 +00:00
using System.IO ;
using CodeImp.DoomBuilder.ZDoom ;
using CodeImp.DoomBuilder.GZBuilder.Data ;
namespace CodeImp.DoomBuilder.GZBuilder.GZDoom {
2013-09-11 09:47:53 +00:00
internal class ModeldefParser : ZDTextParser {
2014-01-03 10:33:45 +00:00
private Dictionary < string , ModelData > entries ; //classname, entry
internal Dictionary < string , ModelData > Entries { get { return entries ; } }
2013-09-11 09:47:53 +00:00
internal string Source { get { return sourcename ; } }
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
internal ModeldefParser ( ) {
2014-02-26 14:11:06 +00:00
entries = new Dictionary < string , ModelData > ( StringComparer . Ordinal ) ;
2013-09-11 09:47:53 +00:00
}
2012-06-01 10:17:47 +00:00
2013-09-11 09:47:53 +00:00
//should be called after all decorate actors are parsed
public override bool Parse ( Stream stream , string sourcefilename ) {
base . Parse ( stream , sourcefilename ) ;
2014-02-26 14:11:06 +00:00
entries = new Dictionary < string , ModelData > ( StringComparer . Ordinal ) ;
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
// Continue until at the end of the stream
while ( SkipWhitespace ( true ) ) {
string token = ReadToken ( ) ;
2012-05-22 22:56:42 +00:00
2013-09-11 09:47:53 +00:00
if ( token ! = null ) {
token = StripTokenQuotes ( token ) . ToLowerInvariant ( ) ;
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
if ( token = = "model" ) { //model structure start
//find classname
SkipWhitespace ( true ) ;
2014-01-03 10:33:45 +00:00
string className = StripTokenQuotes ( ReadToken ( ActorStructure . ACTOR_CLASS_SPECIAL_TOKENS ) ) . ToLowerInvariant ( ) ;
2012-05-21 23:51:32 +00:00
2014-01-03 10:33:45 +00:00
if ( ! string . IsNullOrEmpty ( className ) & & ! entries . ContainsKey ( className ) ) {
2013-09-11 09:47:53 +00:00
//now find opening brace
SkipWhitespace ( true ) ;
token = ReadToken ( ) ;
if ( token ! = "{" ) {
2014-01-03 10:33:45 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Unexpected token found in '" + sourcefilename + "' at line " + GetCurrentLineNumber ( ) + ": expected '{', but got '" + token + "'" ) ;
2013-09-11 09:47:53 +00:00
continue ; //something wrong with modeldef declaration, continue to next one
}
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
ModeldefStructure mds = new ModeldefStructure ( ) ;
ModelData mde = mds . Parse ( this ) ;
if ( mde ! = null ) {
2014-01-03 10:33:45 +00:00
entries . Add ( className , mde ) ;
2013-09-11 09:47:53 +00:00
}
}
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
} else {
// Unknown structure!
string token2 ;
do {
if ( ! SkipWhitespace ( true ) ) break ;
token2 = ReadToken ( ) ;
if ( token2 = = null ) break ;
}
while ( token2 ! = "{" ) ;
int scopelevel = 1 ;
do {
if ( ! SkipWhitespace ( true ) ) break ;
token2 = ReadToken ( ) ;
if ( token2 = = null ) break ;
if ( token2 = = "{" ) scopelevel + + ;
if ( token2 = = "}" ) scopelevel - - ;
}
while ( scopelevel > 0 ) ;
}
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
}
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
}
2012-05-21 23:51:32 +00:00
2014-01-03 10:33:45 +00:00
return entries . Count > 0 ;
2013-09-11 09:47:53 +00:00
}
}
2012-05-21 23:51:32 +00:00
}