From 518d3db5aee258ac83899a8d3b00e9721431f8e7 Mon Sep 17 00:00:00 2001 From: MaxED Date: Wed, 4 Mar 2015 09:37:30 +0000 Subject: [PATCH] TEXTURES parser: "optional" texture definition keyword was not supported. TEXTURES parser: part of a TEXTURES filename is now used as a path in Image Browser. For example, textures from "textures.stuff" will be located in "[TEXTURES]/stuff" in the Image Browser. TEXTURES parser: added "//$GZDB_SKIP" special comment. Parsing of the file is stopped after this comment is encountered. Updated documentation. --- Help/gzdb/faq.html | 2 +- Help/gzdb/textures.html | 13 +++++----- Source/Core/Data/HighResImage.cs | 4 ++-- Source/Core/ZDoom/TextureStructure.cs | 34 +++++++++++++++++---------- Source/Core/ZDoom/TexturesParser.cs | 17 ++++++++++---- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/Help/gzdb/faq.html b/Help/gzdb/faq.html index 504899fc..3e6cff31 100644 --- a/Help/gzdb/faq.html +++ b/Help/gzdb/faq.html @@ -18,7 +18,7 @@ - +

Frequently asked questions

diff --git a/Help/gzdb/textures.html b/Help/gzdb/textures.html index 64016add..9f8a544b 100644 --- a/Help/gzdb/textures.html +++ b/Help/gzdb/textures.html @@ -6,24 +6,23 @@ - - +

TEXTURES support

-

GZDoom Builder adds support for the following TEXTURES parameters:

+

GZDoom Builder adds support for the following TEXTURES parameters:

+

GZDoom Builder supports the following special comments:

+
diff --git a/Source/Core/Data/HighResImage.cs b/Source/Core/Data/HighResImage.cs index 781c652a..85abebac 100644 --- a/Source/Core/Data/HighResImage.cs +++ b/Source/Core/Data/HighResImage.cs @@ -40,7 +40,7 @@ namespace CodeImp.DoomBuilder.Data #region ================== Constructor / Disposer // Constructor - public HighResImage(string name, int width, int height, float scalex, float scaley, bool worldpanning, bool isflat) + public HighResImage(string name, string virtualpath, int width, int height, float scalex, float scaley, bool worldpanning, bool isflat) { // Initialize this.width = width; @@ -52,6 +52,7 @@ namespace CodeImp.DoomBuilder.Data //mxd SetName(name); + this.virtualname = "[TEXTURES]/" + (!string.IsNullOrEmpty(virtualpath) ? virtualpath + "/" : "") + this.name; this.isFlat = isflat; // We have no destructor @@ -74,7 +75,6 @@ namespace CodeImp.DoomBuilder.Data base.SetName(name); - this.virtualname = "[TEXTURES]/" + this.name; if(General.Settings.CapitalizeTextureNames && !string.IsNullOrEmpty(this.displayname)) { this.displayname = this.displayname.ToUpperInvariant(); diff --git a/Source/Core/ZDoom/TextureStructure.cs b/Source/Core/ZDoom/TextureStructure.cs index 6864e8eb..4dddc6cd 100644 --- a/Source/Core/ZDoom/TextureStructure.cs +++ b/Source/Core/ZDoom/TextureStructure.cs @@ -36,20 +36,21 @@ namespace CodeImp.DoomBuilder.ZDoom #region ================== Variables // Declaration - private string typename; - private string name; - private int width; - private int height; + private readonly string typename; + private readonly string name; + private readonly string virtualpath; //mxd + private readonly int width; + private readonly int height; // Properties - private float xscale; - private float yscale; - private int xoffset; - private int yoffset; - private bool worldpanning; + private readonly float xscale; + private readonly float yscale; + private readonly int xoffset; + private readonly int yoffset; + private readonly bool worldpanning; // Patches - private List patches; + private readonly List patches; #endregion @@ -71,10 +72,11 @@ namespace CodeImp.DoomBuilder.ZDoom #region ================== Constructor / Disposer // Constructor - internal TextureStructure(TexturesParser parser, string typename) + internal TextureStructure(TexturesParser parser, string typename, string virtualpath) { // Initialize this.typename = typename; + this.virtualpath = virtualpath; patches = new List(4); xscale = 0.0f; yscale = 0.0f; @@ -85,6 +87,14 @@ namespace CodeImp.DoomBuilder.ZDoom // First token is the class name parser.SkipWhitespace(true); name = parser.StripTokenQuotes(parser.ReadToken()); + + //mxd. It can also be "optional" keyword. + if(name.ToLowerInvariant() == "optional") + { + parser.SkipWhitespace(true); + name = parser.StripTokenQuotes(parser.ReadToken()); + } + if(string.IsNullOrEmpty(name)) { parser.ReportError("Expected texture or sprite name"); @@ -270,7 +280,7 @@ namespace CodeImp.DoomBuilder.ZDoom if(yscale == 0.0f) scaley = defaultscale; else scaley = 1f / yscale; // Make texture - HighResImage tex = new HighResImage(name, width, height, scalex, scaley, worldpanning, typename == "flat"); + HighResImage tex = new HighResImage(name, virtualpath, width, height, scalex, scaley, worldpanning, typename == "flat"); // Add patches foreach(PatchStructure p in patches) diff --git a/Source/Core/ZDoom/TexturesParser.cs b/Source/Core/ZDoom/TexturesParser.cs index 8a369407..829c890e 100644 --- a/Source/Core/ZDoom/TexturesParser.cs +++ b/Source/Core/ZDoom/TexturesParser.cs @@ -40,6 +40,7 @@ namespace CodeImp.DoomBuilder.ZDoom private readonly Dictionary textures; private readonly Dictionary flats; private readonly Dictionary sprites; + private readonly char[] pathtrimchars = new[] {'_', '.', ' ', '-'}; //mxd #endregion @@ -75,6 +76,10 @@ namespace CodeImp.DoomBuilder.ZDoom public override bool Parse(Stream stream, string sourcefilename) { base.Parse(stream, sourcefilename); + + //mxd. Make vitrual path from filename + string virtualpath = sourcefilename.Substring(8).TrimStart(pathtrimchars); + if(virtualpath.ToLowerInvariant() == "txt") virtualpath = string.Empty; // Continue until at the end of the stream while(SkipWhitespace(true)) @@ -87,7 +92,7 @@ namespace CodeImp.DoomBuilder.ZDoom if(objdeclaration == "texture") { // Read texture structure - TextureStructure tx = new TextureStructure(this, "texture"); + TextureStructure tx = new TextureStructure(this, "texture", virtualpath); if(this.HasError) break; // if a limit for the texture name length is set make sure that it's not exceeded @@ -105,7 +110,7 @@ namespace CodeImp.DoomBuilder.ZDoom else if(objdeclaration == "sprite") { // Read sprite structure - TextureStructure tx = new TextureStructure(this, "sprite"); + TextureStructure tx = new TextureStructure(this, "sprite", virtualpath); if(this.HasError) break; // if a limit for the sprite name length is set make sure that it's not exceeded @@ -122,7 +127,7 @@ namespace CodeImp.DoomBuilder.ZDoom else if(objdeclaration == "walltexture") { // Read walltexture structure - TextureStructure tx = new TextureStructure(this, "walltexture"); + TextureStructure tx = new TextureStructure(this, "walltexture", virtualpath); if(this.HasError) break; // if a limit for the walltexture name length is set make sure that it's not exceeded @@ -140,7 +145,7 @@ namespace CodeImp.DoomBuilder.ZDoom else if(objdeclaration == "flat") { // Read flat structure - TextureStructure tx = new TextureStructure(this, "flat"); + TextureStructure tx = new TextureStructure(this, "flat", virtualpath); if(this.HasError) break; // if a limit for the flat name length is set make sure that it's not exceeded @@ -155,6 +160,10 @@ namespace CodeImp.DoomBuilder.ZDoom flats[tx.Name] = tx; } } + else if(objdeclaration == "$gzdb_skip") //mxd + { + break; + } else { // Unknown structure!