UltimateZoneBuilder/Source/Core/ZDoom/VoxeldefParser.cs
MaxED 0f7aa9f827 Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value. 
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00

147 lines
3.9 KiB
C#

#region ================== Namespaces
using System;
using System.Collections.Generic;
using CodeImp.DoomBuilder.Config;
using CodeImp.DoomBuilder.Data;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.GZBuilder.Data;
using SlimDX;
#endregion
namespace CodeImp.DoomBuilder.ZDoom
{
public sealed class VoxeldefParser : ZDTextParser
{
internal override ScriptType ScriptType { get { return ScriptType.VOXELDEF; } }
private Dictionary<string, ModelData> entries; //sprite name, entry
internal Dictionary<string, ModelData> Entries { get { return entries; } }
public override bool Parse(TextResourceData data, bool clearerrors)
{
entries = new Dictionary<string, ModelData>(StringComparer.Ordinal);
//mxd. Already parsed?
if(!base.AddTextResource(data))
{
if(clearerrors) ClearError();
return true;
}
// Cannot process?
if(!base.Parse(data, clearerrors)) return false;
List<string> spriteNames = new List<string>();
string modelName = string.Empty;
string prevToken = string.Empty;
// Continue until at the end of the stream
while(SkipWhitespace(true))
{
string token = ReadToken();
if(!string.IsNullOrEmpty(token))
{
token = StripTokenQuotes(token).ToLowerInvariant();
if(token == ",") //previous token was a sprite name
{
if(!string.IsNullOrEmpty(prevToken) && !spriteNames.Contains(prevToken)) spriteNames.Add(prevToken);
prevToken = token.ToUpperInvariant();
}
else if(token == "=") //next token should be a voxel model name
{
if(!string.IsNullOrEmpty(prevToken) && !spriteNames.Contains(prevToken)) spriteNames.Add(prevToken);
SkipWhitespace(true);
token = ReadToken();
if(string.IsNullOrEmpty(token))
{
ReportError("Expected voxel name");
return false;
}
modelName = StripTokenQuotes(token).ToLowerInvariant();
}
else if(token == "{") //read the settings
{
ModelData mde = new ModelData { IsVoxel = true };
float scale = 1.0f;
float angleoffset = 0;
while(SkipWhitespace(true))
{
token = ReadToken();
if(!string.IsNullOrEmpty(token))
{
token = StripTokenQuotes(token).ToLowerInvariant();
if(token == "}") //store data
{
if(!string.IsNullOrEmpty(modelName) && spriteNames.Count > 0)
{
mde.ModelNames.Add(modelName);
mde.SetTransform(Matrix.RotationZ(Angle2D.DegToRad(angleoffset)), Matrix.Identity, new Vector3(scale));
foreach(string s in spriteNames)
{
//TODO: is this the proper behaviour?
entries[s] = mde;
}
//reset local data
modelName = string.Empty;
prevToken = string.Empty;
spriteNames.Clear();
}
break;
}
else if(token == "overridepalette")
{
mde.OverridePalette = true;
}
else if(token == "angleoffset")
{
if(!NextTokenIs("=")) return false;
token = StripTokenQuotes(ReadToken());
if(!ReadSignedFloat(token, ref angleoffset))
{
// Not numeric!
ReportError("Expected AngleOffset value, but got \"" + token + "\"");
return false;
}
}
else if(token == "scale")
{
if(!NextTokenIs("=")) return false;
token = StripTokenQuotes(ReadToken());
if(!ReadSignedFloat(token, ref scale))
{
// Not numeric!
ReportError("Expected Scale value, but got \"" + token + "\"");
return false;
}
}
prevToken = token.ToUpperInvariant();
}
}
}
else
{
prevToken = token.ToUpperInvariant();
}
}
}
return entries.Count > 0;
}
}
}