UltimateZoneBuilder/Source/Core/GZBuilder/GZDoom/ModeldefParser.cs
MaxED 16b97e1c83 Added GLDEFS and (Z)MAPINFO parsers.
Dynamic lights defined in GLDEFS are now rendered in Visual modes (currently only one light per Thing is supported).
Several values from (Z)MAPINFO are now used in Visual modes.
Added "Reload GLDEFS", "Reload (Z)MAPINFO" and "Reload MODELDEF" menu options (in "Tools" section).
MODELDEF parser now checks which model(s) is/are used in first frame.
Dynamic lights are now created with more meaningful default parameters.
Added errors and warnings indicator to main window.
2012-06-01 10:17:47 +00:00

94 lines
3.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using CodeImp.DoomBuilder.ZDoom;
using CodeImp.DoomBuilder.GZBuilder.Data;
using CodeImp.DoomBuilder.GZBuilder.GZDoom;
namespace CodeImp.DoomBuilder.GZBuilder.GZDoom {
public class ModeldefParser : ZDTextParser {
private Dictionary<string, ModeldefEntry> modelDefEntries; //classname, entry
public Dictionary<string, ModeldefEntry> ModelDefEntries { get { return modelDefEntries; } }
private List<string> classNames;
public string Source { get { return sourcename; } }
public ModeldefParser() {
modelDefEntries = new Dictionary<string, ModeldefEntry>();
classNames = new List<string>();
}
//should be called after all decorate actors are parsed
public override bool Parse(Stream stream, string sourcefilename) {
base.Parse(stream, sourcefilename);
modelDefEntries = new Dictionary<string, ModeldefEntry>();
// Continue until at the end of the stream
while (SkipWhitespace(true)) {
string token = ReadToken();
if (token != null) {
token = StripTokenQuotes(token).ToLowerInvariant();
if (token == "model") { //model structure start
//find classname
SkipWhitespace(true);
string className = StripTokenQuotes(ReadToken()).ToLowerInvariant();
if (!string.IsNullOrEmpty(className)) {
if (classNames.IndexOf(className) != -1) {
continue; //already got this class; continue to next one
}
classNames.Add(className);
//now find opening brace
SkipWhitespace(true);
token = ReadToken();
if (token != "{") {
GZBuilder.GZGeneral.LogAndTraceWarning("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();
ModeldefEntry mde = mds.Parse(this);
if (mde != null) {
mde.ClassName = className;
modelDefEntries.Add(className, mde);
classNames.Add(mde.ClassName);
}
}
} 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);
}
}
}
if (modelDefEntries.Count > 0)
return true;
return false;
}
}
}