2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#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.Collections.Generic;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2014-07-11 11:00:24 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Config
|
|
|
|
{
|
|
|
|
internal sealed class ResourceTextureSet : TextureSet, IFilledTextureSet
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Matching textures and flats
|
2010-08-12 19:59:06 +00:00
|
|
|
private Dictionary<long, ImageData> textures;
|
|
|
|
private Dictionary<long, ImageData> flats;
|
2010-08-14 10:21:38 +00:00
|
|
|
private DataLocation location;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2010-08-12 19:59:06 +00:00
|
|
|
public ICollection<ImageData> Textures { get { return textures.Values; } }
|
2013-12-03 10:50:33 +00:00
|
|
|
public ICollection<ImageData> Flats { get { return flats.Values; } }
|
2010-08-14 10:21:38 +00:00
|
|
|
public DataLocation Location { get { return location; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
// New texture set constructor
|
2010-08-14 10:21:38 +00:00
|
|
|
public ResourceTextureSet(string name, DataLocation location)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
this.name = name;
|
2010-08-14 10:21:38 +00:00
|
|
|
this.location = location;
|
2010-08-12 19:59:06 +00:00
|
|
|
this.textures = new Dictionary<long, ImageData>();
|
|
|
|
this.flats = new Dictionary<long, ImageData>();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2010-08-12 19:59:06 +00:00
|
|
|
// Add a texture
|
2009-04-19 18:07:22 +00:00
|
|
|
internal void AddTexture(ImageData image)
|
|
|
|
{
|
2014-07-11 11:00:24 +00:00
|
|
|
if(textures.ContainsKey(image.LongName) && (!(image is HighResImage) || !(image as HighResImage).ContainsPatch(image.Name)) )
|
2010-08-14 10:21:38 +00:00
|
|
|
General.ErrorLogger.Add(ErrorType.Warning, "Texture \"" + image.Name + "\" is double defined in resource \"" + this.Location.location + "\".");
|
|
|
|
textures[image.LongName] = image;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 19:59:06 +00:00
|
|
|
// Add a flat
|
2009-04-19 18:07:22 +00:00
|
|
|
internal void AddFlat(ImageData image)
|
|
|
|
{
|
2010-08-14 10:21:38 +00:00
|
|
|
if(flats.ContainsKey(image.LongName))
|
|
|
|
General.ErrorLogger.Add(ErrorType.Warning, "Flat \"" + image.Name + "\" is double defined in resource \"" + this.Location.location + "\".");
|
|
|
|
flats[image.LongName] = image;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this set has a texture
|
|
|
|
internal bool TextureExists(ImageData image)
|
|
|
|
{
|
|
|
|
return textures.ContainsKey(image.LongName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this set has a flat
|
|
|
|
internal bool FlatExists(ImageData image)
|
|
|
|
{
|
|
|
|
return flats.ContainsKey(image.LongName);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2010-08-12 19:59:06 +00:00
|
|
|
// Mix the textures and flats
|
|
|
|
internal void MixTexturesAndFlats()
|
|
|
|
{
|
2013-12-03 10:50:33 +00:00
|
|
|
// Make a copy of the flats only
|
|
|
|
Dictionary<long, ImageData> flatsonly = new Dictionary<long, ImageData>(flats);
|
|
|
|
|
|
|
|
// Add textures to flats
|
|
|
|
foreach(KeyValuePair<long, ImageData> t in textures)
|
|
|
|
{
|
|
|
|
if(!flats.ContainsKey(t.Key)) flats.Add(t.Key, t.Value);
|
2010-08-12 19:59:06 +00:00
|
|
|
}
|
2013-07-29 08:50:50 +00:00
|
|
|
|
2013-12-03 10:50:33 +00:00
|
|
|
// Add flats to textures
|
|
|
|
foreach(KeyValuePair<long, ImageData> f in flatsonly)
|
|
|
|
{
|
|
|
|
if(!textures.ContainsKey(f.Key)) textures.Add(f.Key, f.Value);
|
|
|
|
}
|
2010-08-12 19:59:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|