mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-24 04:41:10 +00:00
724709e435
Script editor: pressing "F1" now opens keyword help instead of program manual. Linedef edit form, Thing edit form: rewritten script support logic. It should now work in the same manner as the rest of controls. Thing info panel: thing arguments now have proper labels. Edit forms, UDMF: fields, which are handled by UI, are no longer shown in "Custom" tab. Visual mode: fixed a crash when loading a model on a video card without Shader model 2.0 support. Fixed incorrect argument number and changed most of labels in "Cameras and interpolation" section of zdoom_things.cfg.
188 lines
4.7 KiB
C#
188 lines
4.7 KiB
C#
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
/*
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
* This program is released under GNU General Public License
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
#endregion
|
|
|
|
#region ================== Namespaces
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using CodeImp.DoomBuilder.Data;
|
|
using System.Text.RegularExpressions;
|
|
|
|
#endregion
|
|
|
|
namespace CodeImp.DoomBuilder.Config
|
|
{
|
|
internal sealed class MatchingTextureSet : TextureSet, IFilledTextureSet, IComparable<MatchingTextureSet>
|
|
{
|
|
#region ================== Variables
|
|
|
|
// Never stored, only used at run-time
|
|
private Regex regex;
|
|
|
|
// Matching textures and flats
|
|
private List<ImageData> textures;
|
|
private List<ImageData> flats;
|
|
|
|
#endregion
|
|
|
|
#region ================== Properties
|
|
|
|
public ICollection<ImageData> Textures { get { return textures; } }
|
|
public ICollection<ImageData> Flats { get { if(General.Map.Config.MixTexturesFlats) return textures; return flats; } } //mxd
|
|
|
|
#endregion
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
// New texture set for quick matching
|
|
public MatchingTextureSet(ICollection<string> filters)
|
|
{
|
|
this.filters = new List<string>(filters);
|
|
|
|
// Setup
|
|
Setup();
|
|
}
|
|
|
|
// Texture set from defined set
|
|
public MatchingTextureSet(DefinedTextureSet definedset)
|
|
{
|
|
// Copy the name
|
|
this.name = definedset.Name;
|
|
|
|
// Copy the filters
|
|
this.filters = new List<string>(definedset.Filters);
|
|
|
|
// Setup
|
|
Setup();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ================== Methods
|
|
|
|
// This sets up the object
|
|
private void Setup()
|
|
{
|
|
// Make the regex string that handles all filters
|
|
StringBuilder regexstr = new StringBuilder("");
|
|
foreach(string s in this.filters)
|
|
{
|
|
// Make sure filter is in uppercase
|
|
string ss = s.ToUpperInvariant();
|
|
|
|
// Escape regex characters
|
|
ss = ss.Replace("+", "\\+");
|
|
ss = ss.Replace("\\", "\\\\");
|
|
ss = ss.Replace("|", "\\|");
|
|
ss = ss.Replace("{", "\\{");
|
|
ss = ss.Replace("[", "\\[");
|
|
ss = ss.Replace("(", "\\(");
|
|
ss = ss.Replace(")", "\\)");
|
|
ss = ss.Replace("^", "\\^");
|
|
ss = ss.Replace("$", "\\$");
|
|
ss = ss.Replace(".", "\\.");
|
|
ss = ss.Replace("#", "\\#");
|
|
ss = ss.Replace(" ", "\\ ");
|
|
|
|
// Replace the ? with the regex code for single character
|
|
ss = ss.Replace("?", ".");
|
|
|
|
// Replace the * with the regex code for optional multiple characters
|
|
ss = ss.Replace("*", ".*?");
|
|
|
|
// When a filter has already added, insert a conditional OR operator
|
|
if(regexstr.Length > 0) regexstr.Append("|");
|
|
|
|
// Open group without backreferencing
|
|
regexstr.Append("(?:");
|
|
|
|
// Must be start of string
|
|
regexstr.Append("\\A");
|
|
|
|
// Add the filter
|
|
regexstr.Append(ss);
|
|
|
|
// Must be end of string
|
|
regexstr.Append("\\Z");
|
|
|
|
// Close group
|
|
regexstr.Append(")");
|
|
}
|
|
|
|
// No filters added? Then make a never-matching regex
|
|
if(this.filters.Count == 0) regexstr.Append("\\Z\\A");
|
|
|
|
// Make the regex
|
|
regex = new Regex(regexstr.ToString(), RegexOptions.Compiled |
|
|
RegexOptions.CultureInvariant);
|
|
|
|
// Initialize collections
|
|
textures = new List<ImageData>();
|
|
flats = new List<ImageData>();
|
|
}
|
|
|
|
// This matches a name against the regex and adds a texture to
|
|
// the list if it matches. Returns true when matched and added.
|
|
internal bool AddTexture(ImageData image)
|
|
{
|
|
// Check against regex
|
|
if(regex.IsMatch(image.Name.ToUpperInvariant()))
|
|
{
|
|
// Matches! Add it.
|
|
textures.Add(image);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
// Doesn't match
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// This matches a name against the regex and adds a flat to
|
|
// the list if it matches. Returns true when matched and added.
|
|
internal bool AddFlat(ImageData image)
|
|
{
|
|
// Check against regex
|
|
if(regex.IsMatch(image.Name.ToUpperInvariant()))
|
|
{
|
|
// Matches! Add it.
|
|
flats.Add(image);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
// Doesn't match
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// This only checks if the given image is a match
|
|
internal bool IsMatch(ImageData image)
|
|
{
|
|
return regex.IsMatch(image.Name.ToUpperInvariant());
|
|
}
|
|
|
|
// This compares it for sorting
|
|
public int CompareTo(MatchingTextureSet other)
|
|
{
|
|
return string.Compare(this.name, other.name);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|