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 ;
2014-12-03 23:15:26 +00:00
namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
{
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 ; } }
2012-05-21 23:51:32 +00:00
2014-12-03 23:15:26 +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
2015-12-18 10:16:53 +00:00
public override bool Parse ( Stream stream , string sourcefilename , bool clearerrors )
2014-12-03 23:15:26 +00:00
{
2014-02-26 14:11:06 +00:00
entries = new Dictionary < string , ModelData > ( StringComparer . Ordinal ) ;
2015-12-18 10:16:53 +00:00
if ( ! base . Parse ( stream , sourcefilename , clearerrors ) ) return false ;
2012-05-21 23:51:32 +00:00
2013-09-11 09:47:53 +00:00
// Continue until at the end of the stream
2015-12-17 10:07:28 +00:00
while ( SkipWhitespace ( true ) )
2014-12-03 23:15:26 +00:00
{
2013-09-11 09:47:53 +00:00
string token = ReadToken ( ) ;
2015-12-17 10:07:28 +00:00
if ( ! string . IsNullOrEmpty ( token ) )
2014-12-03 23:15:26 +00:00
{
2013-09-11 09:47:53 +00:00
token = StripTokenQuotes ( token ) . ToLowerInvariant ( ) ;
2015-12-17 10:07:28 +00:00
if ( token = = "model" ) //model structure start
2014-12-03 23:15:26 +00:00
{
2013-09-11 09:47:53 +00:00
//find classname
SkipWhitespace ( true ) ;
2015-12-17 10:07:28 +00:00
string displayclassname = StripTokenQuotes ( ReadToken ( ActorStructure . ACTOR_CLASS_SPECIAL_TOKENS ) ) ;
string classname = displayclassname . ToLowerInvariant ( ) ;
2012-05-21 23:51:32 +00:00
2015-12-17 10:07:28 +00:00
if ( ! string . IsNullOrEmpty ( classname ) & & ! entries . ContainsKey ( classname ) )
2014-12-03 23:15:26 +00:00
{
2013-09-11 09:47:53 +00:00
//now find opening brace
SkipWhitespace ( true ) ;
token = ReadToken ( ) ;
2015-12-17 10:07:28 +00:00
if ( token ! = "{" )
2014-12-03 23:15:26 +00:00
{
2015-12-17 10:07:28 +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 ( ) ;
2015-12-17 10:07:28 +00:00
if ( mds . Parse ( this , displayclassname ) & & mds . ModelData ! = null )
{
entries . Add ( classname , mds . ModelData ) ;
}
if ( HasError )
{
LogError ( ) ;
ClearError ( ) ;
}
// Skip untill current structure end
if ( ! mds . ParsingFinished )
{
while ( SkipWhitespace ( true ) )
{
token = ReadToken ( ) ;
if ( string . IsNullOrEmpty ( token ) | | token = = "}" ) break ;
}
}
2013-09-11 09:47:53 +00:00
}
2014-12-03 23:15:26 +00:00
}
else
{
2013-09-11 09:47:53 +00:00
// Unknown structure!
string token2 ;
2015-12-17 10:07:28 +00:00
if ( token ! = "{" )
2014-12-03 23:15:26 +00:00
{
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
do
{
2015-12-17 10:07:28 +00:00
if ( ! SkipWhitespace ( true ) ) break ;
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
token2 = ReadToken ( ) ;
2015-12-17 10:07:28 +00:00
if ( string . IsNullOrEmpty ( token2 ) ) break ;
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
}
2015-12-17 10:07:28 +00:00
while ( token2 ! = "{" ) ;
2013-09-11 09:47:53 +00:00
}
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
2013-09-11 09:47:53 +00:00
int scopelevel = 1 ;
2014-12-03 23:15:26 +00:00
do
{
2015-12-17 10:07:28 +00:00
if ( ! SkipWhitespace ( true ) ) break ;
2013-09-11 09:47:53 +00:00
token2 = ReadToken ( ) ;
2015-12-17 10:07:28 +00:00
if ( string . IsNullOrEmpty ( token2 ) ) break ;
if ( token2 = = "{" ) scopelevel + + ;
if ( token2 = = "}" ) scopelevel - - ;
2013-09-11 09:47:53 +00:00
}
2015-12-17 10:07:28 +00:00
while ( scopelevel > 0 ) ;
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
}
2015-12-17 10:07:28 +00:00
protected override string GetLanguageType ( )
{
return "MODELDEF" ;
}
2013-09-11 09:47:53 +00:00
}
2012-05-21 23:51:32 +00:00
}