2015-12-18 10:16:53 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2015-12-19 00:05:34 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.ZDoom
|
|
|
|
|
{
|
|
|
|
|
public struct CameraTextureData
|
|
|
|
|
{
|
|
|
|
|
public string Name;
|
|
|
|
|
public int Width;
|
|
|
|
|
public int Height;
|
|
|
|
|
public float ScaleX;
|
|
|
|
|
public float ScaleY;
|
|
|
|
|
public bool WorldPanning;
|
|
|
|
|
public bool FitTexture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mxd. Currently this only parses cameratextures
|
|
|
|
|
internal sealed class AnimdefsParser : ZDTextParser
|
|
|
|
|
{
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<string, CameraTextureData> cameratextures;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, CameraTextureData> CameraTextures { get { return cameratextures; } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
|
|
|
|
internal AnimdefsParser()
|
|
|
|
|
{
|
|
|
|
|
cameratextures = new Dictionary<string, CameraTextureData>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Parsing
|
|
|
|
|
|
|
|
|
|
public override bool Parse(Stream stream, string sourcefilename, bool clearerrors)
|
|
|
|
|
{
|
|
|
|
|
if(!base.Parse(stream, sourcefilename, clearerrors)) return false;
|
|
|
|
|
|
|
|
|
|
// Continue until at the end of the stream
|
|
|
|
|
while(SkipWhitespace(true))
|
|
|
|
|
{
|
|
|
|
|
string token = ReadToken();
|
|
|
|
|
if(string.IsNullOrEmpty(token) || string.Compare(token, "CAMERATEXTURE", true) != 0) continue;
|
|
|
|
|
|
|
|
|
|
// Texture name
|
2015-12-28 21:56:10 +00:00
|
|
|
|
SkipWhitespace(true);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
string texturename = StripTokenQuotes(ReadToken(false));
|
|
|
|
|
if(string.IsNullOrEmpty(texturename))
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Expected camera texture name");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Camera texture names are limited to 8 chars
|
|
|
|
|
if(texturename.Length > DataManager.CLASIC_IMAGE_NAME_LENGTH)
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Camera texture names must be no longer than " + DataManager.CLASIC_IMAGE_NAME_LENGTH + " chars");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Width
|
|
|
|
|
int width = -1;
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
if(!ReadSignedInt(ref width) || width < 1)
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Expected camera texture width");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Height
|
|
|
|
|
int height = -1;
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
if(!ReadSignedInt(ref height) || height < 1)
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Expected camera texture height");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "Fit" keyword?
|
|
|
|
|
bool worldpanning = false;
|
|
|
|
|
bool fit = false;
|
|
|
|
|
float scalex = 1.0f;
|
|
|
|
|
float scaley = 1.0f;
|
|
|
|
|
|
|
|
|
|
if(NextTokenIs("fit", false))
|
|
|
|
|
{
|
|
|
|
|
fit = true;
|
|
|
|
|
int fitwidth = width;
|
|
|
|
|
int fitheight = height;
|
|
|
|
|
|
|
|
|
|
// Fit width
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
if(!ReadSignedInt(ref fitwidth) || fitwidth < 1)
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Expected camera texture fit width");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fit height
|
|
|
|
|
SkipWhitespace(true);
|
|
|
|
|
if(!ReadSignedInt(ref fitheight) || fitheight < 1)
|
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
ReportError("Expected camera texture fit height");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update scale
|
|
|
|
|
scalex = (float)fitwidth / width;
|
|
|
|
|
scaley = (float)fitheight / height;
|
|
|
|
|
|
|
|
|
|
// WorldPanning
|
|
|
|
|
worldpanning = NextTokenIs("worldpanning", false);
|
|
|
|
|
}
|
|
|
|
|
else if(NextTokenIs("worldpanning", false))
|
|
|
|
|
{
|
|
|
|
|
worldpanning = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check results
|
|
|
|
|
if(cameratextures.ContainsKey(texturename.ToUpperInvariant()))
|
|
|
|
|
{
|
|
|
|
|
ReportError("Camera texture '" + texturename + "' is defined more than once");
|
2015-12-19 00:05:34 +00:00
|
|
|
|
return false;
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store results
|
|
|
|
|
texturename = texturename.ToUpperInvariant();
|
|
|
|
|
cameratextures[texturename] = new CameraTextureData { Name = texturename, Width = width, Height = height,
|
|
|
|
|
ScaleX = scalex, ScaleY = scaley,
|
|
|
|
|
WorldPanning = worldpanning, FitTexture = fit };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string GetLanguageType()
|
|
|
|
|
{
|
|
|
|
|
return "ANIMDEFS";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|