2014-12-03 23:15:26 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
2012-07-12 22:34:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-12-17 10:07:28 +00:00
|
|
|
|
using System.IO;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Data;
|
2015-12-17 10:07:28 +00:00
|
|
|
|
using CodeImp.DoomBuilder.ZDoom;
|
2012-07-12 22:34:12 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2012-07-12 22:34:12 +00:00
|
|
|
|
//mxd. Modeldef parser used to create ScriptItems for use in script editor's navigator
|
2015-12-17 10:07:28 +00:00
|
|
|
|
//Should be parse model definitions even from invalid MODELDEF and should never fail parsing
|
2014-12-03 23:15:26 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.GZDoom
|
|
|
|
|
{
|
|
|
|
|
internal sealed class ModeldefParserSE : ZDTextParser
|
|
|
|
|
{
|
|
|
|
|
private readonly List<ScriptItem> models;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
internal List<ScriptItem> Models { get { return models; } }
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public ModeldefParserSE()
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
models = new List<ScriptItem>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override bool Parse(Stream stream, string sourcefilename)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
base.Parse(stream, sourcefilename);
|
|
|
|
|
|
|
|
|
|
// 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) || token.ToUpperInvariant() != "MODEL") continue;
|
|
|
|
|
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
int startpos = (int)stream.Position;
|
|
|
|
|
string modelname = ReadToken();
|
|
|
|
|
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
token = ReadToken(); //this should be "{"
|
2013-09-11 09:47:53 +00:00
|
|
|
|
|
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
|
|
|
|
ScriptItem i = new ScriptItem(modelname, startpos, false);
|
|
|
|
|
models.Add(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(SkipWhitespace(true))
|
|
|
|
|
{
|
|
|
|
|
token = ReadToken();
|
|
|
|
|
if(string.IsNullOrEmpty(token) || token == "}") break;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 10:07:28 +00:00
|
|
|
|
// Sort nodes
|
2013-09-11 09:47:53 +00:00
|
|
|
|
models.Sort(ScriptItem.SortByName);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-12-17 10:07:28 +00:00
|
|
|
|
|
|
|
|
|
protected override string GetLanguageType()
|
|
|
|
|
{
|
|
|
|
|
return "MODELDEF";
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-07-12 22:34:12 +00:00
|
|
|
|
}
|