UltimateZoneBuilder/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs
MaxED dbcc57b7a6 Fixed, Script Editor: file was marked as changed when changing script configurations.
Fixed, Script Editor: in some cases clicking on an error in the errors list didn't navigate to the error location.
Fixed, Script Editor: in some cases incorrect error line number was shown.
Fixed, Text lump parsers: fixed a crash when trying to get a filename from a quoted string with missing closing quote.
Fixed, Text lump parsers: in several cases parsing errors were ignored by overlaying data structures.
Fixed: in some cases Thing Filter thing flags were cleared when switching game configurations in the "Game Configurations" window.
Changed, PK3 reader: loading of files with invalid path chars is now skipped instead of skipping loading of the whole resource. Also more helpful warning message is now displayed.
Updated SharpCompress library to v.0.11.2.0.
2015-12-17 10:07:28 +00:00

110 lines
3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using CodeImp.DoomBuilder.ZDoom;
using CodeImp.DoomBuilder.GZBuilder.Data;
namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
{
internal class ModeldefParser : ZDTextParser
{
private Dictionary<string, ModelData> entries; //classname, entry
internal Dictionary<string, ModelData> Entries { get { return entries; } }
internal ModeldefParser()
{
entries = new Dictionary<string, ModelData>(StringComparer.Ordinal);
}
//should be called after all decorate actors are parsed
public override bool Parse(Stream stream, string sourcefilename)
{
base.Parse(stream, sourcefilename);
entries = new Dictionary<string, ModelData>(StringComparer.Ordinal);
// Continue until at the end of the stream
while(SkipWhitespace(true))
{
string token = ReadToken();
if(!string.IsNullOrEmpty(token))
{
token = StripTokenQuotes(token).ToLowerInvariant();
if(token == "model") //model structure start
{
//find classname
SkipWhitespace(true);
string displayclassname = StripTokenQuotes(ReadToken(ActorStructure.ACTOR_CLASS_SPECIAL_TOKENS));
string classname = displayclassname.ToLowerInvariant();
if(!string.IsNullOrEmpty(classname) && !entries.ContainsKey(classname))
{
//now find opening brace
SkipWhitespace(true);
token = ReadToken();
if(token != "{")
{
General.ErrorLogger.Add(ErrorType.Error, "Unexpected token found in '" + sourcefilename + "' at line " + GetCurrentLineNumber() + ": expected '{', but got '" + token + "'");
continue; //something wrong with modeldef declaration, continue to next one
}
ModeldefStructure mds = new ModeldefStructure();
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;
}
}
}
}
else
{
// Unknown structure!
string token2;
if(token != "{")
{
do
{
if(!SkipWhitespace(true)) break;
token2 = ReadToken();
if(string.IsNullOrEmpty(token2)) break;
}
while(token2 != "{");
}
int scopelevel = 1;
do
{
if(!SkipWhitespace(true)) break;
token2 = ReadToken();
if(string.IsNullOrEmpty(token2)) break;
if(token2 == "{") scopelevel++;
if(token2 == "}") scopelevel--;
}
while(scopelevel > 0);
}
}
}
return entries.Count > 0;
}
protected override string GetLanguageType()
{
return "MODELDEF";
}
}
}