2007-09-24 17:41:36 +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
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
2007-09-27 22:55:03 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
2007-10-01 20:53:10 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2007-09-27 22:55:03 +00:00
|
|
|
using System.IO;
|
2008-05-26 20:06:15 +00:00
|
|
|
using CodeImp.DoomBuilder.Editing;
|
2008-11-27 19:25:13 +00:00
|
|
|
using System.Collections.Specialized;
|
2007-06-14 23:31:57 +00:00
|
|
|
|
2007-09-24 17:41:36 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-10-21 18:06:10 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Config
|
2007-06-14 23:31:57 +00:00
|
|
|
{
|
2008-01-02 21:49:43 +00:00
|
|
|
internal class ConfigurationInfo : IComparable<ConfigurationInfo>
|
2007-06-14 23:31:57 +00:00
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
private const string MODE_DISABLED_KEY = "disabled";
|
|
|
|
private const string MODE_ENABLED_KEY = "enabled";
|
|
|
|
|
2009-01-15 19:42:55 +00:00
|
|
|
// The { and } are invalid key names in a configuration so this ensures this string is unique
|
|
|
|
private const string MISSING_NODEBUILDER = "{missing nodebuilder}";
|
|
|
|
|
2008-11-27 19:25:13 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
private string name;
|
|
|
|
private string filename;
|
|
|
|
private string settingskey;
|
2008-05-05 15:16:39 +00:00
|
|
|
private string defaultlumpname;
|
2007-10-09 20:47:08 +00:00
|
|
|
private string nodebuildersave;
|
|
|
|
private string nodebuildertest;
|
2007-10-01 20:53:10 +00:00
|
|
|
private DataLocationList resources;
|
2007-09-28 09:55:23 +00:00
|
|
|
private string testprogram;
|
|
|
|
private string testparameters;
|
2008-09-09 23:06:31 +00:00
|
|
|
private bool customparameters;
|
|
|
|
private int testskill;
|
2008-05-26 20:06:15 +00:00
|
|
|
private List<ThingsFilter> thingsfilters;
|
2008-10-01 14:17:52 +00:00
|
|
|
private List<DefinedTextureSet> texturesets;
|
2008-11-27 19:25:13 +00:00
|
|
|
private Dictionary<string, bool> editmodes;
|
2008-10-01 08:21:10 +00:00
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public string Name { get { return name; } }
|
|
|
|
public string Filename { get { return filename; } }
|
2008-05-05 15:16:39 +00:00
|
|
|
public string DefaultLumpName { get { return defaultlumpname; } }
|
2007-10-09 20:47:08 +00:00
|
|
|
public string NodebuilderSave { get { return nodebuildersave; } set { nodebuildersave = value; } }
|
|
|
|
public string NodebuilderTest { get { return nodebuildertest; } set { nodebuildertest = value; } }
|
2007-10-01 20:53:10 +00:00
|
|
|
public DataLocationList Resources { get { return resources; } }
|
2007-09-29 15:43:59 +00:00
|
|
|
public string TestProgram { get { return testprogram; } set { testprogram = value; } }
|
|
|
|
public string TestParameters { get { return testparameters; } set { testparameters = value; } }
|
2008-09-09 23:06:31 +00:00
|
|
|
public int TestSkill { get { return testskill; } set { testskill = value; } }
|
|
|
|
public bool CustomParameters { get { return customparameters; } set { customparameters = value; } }
|
2008-05-26 20:06:15 +00:00
|
|
|
internal ICollection<ThingsFilter> ThingsFilters { get { return thingsfilters; } }
|
2008-10-01 14:17:52 +00:00
|
|
|
public List<DefinedTextureSet> TextureSets { get { return texturesets; } }
|
2008-11-27 19:25:13 +00:00
|
|
|
internal Dictionary<string, bool> EditModes { get { return editmodes; } }
|
2008-11-27 11:59:17 +00:00
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
// Constructor
|
2008-05-05 15:16:39 +00:00
|
|
|
public ConfigurationInfo(Configuration cfg, string filename)
|
2007-06-14 23:31:57 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.filename = filename;
|
2007-09-27 22:55:03 +00:00
|
|
|
this.settingskey = Path.GetFileNameWithoutExtension(filename).ToLower();
|
|
|
|
|
2008-05-05 15:16:39 +00:00
|
|
|
// Load settings from game configuration
|
|
|
|
this.name = cfg.ReadSetting("game", "<unnamed game>");
|
|
|
|
this.defaultlumpname = cfg.ReadSetting("defaultlumpname", "");
|
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
// Load settings from program configuration
|
2009-01-15 19:42:55 +00:00
|
|
|
this.nodebuildersave = General.Settings.ReadSetting("configurations." + settingskey + ".nodebuildersave", MISSING_NODEBUILDER);
|
|
|
|
this.nodebuildertest = General.Settings.ReadSetting("configurations." + settingskey + ".nodebuildertest", MISSING_NODEBUILDER);
|
2007-09-28 09:55:23 +00:00
|
|
|
this.testprogram = General.Settings.ReadSetting("configurations." + settingskey + ".testprogram", "");
|
|
|
|
this.testparameters = General.Settings.ReadSetting("configurations." + settingskey + ".testparameters", "");
|
2008-09-09 23:06:31 +00:00
|
|
|
this.customparameters = General.Settings.ReadSetting("configurations." + settingskey + ".customparameters", false);
|
|
|
|
this.testskill = General.Settings.ReadSetting("configurations." + settingskey + ".testskill", 3);
|
2007-12-01 01:32:56 +00:00
|
|
|
this.resources = new DataLocationList(General.Settings.Config, "configurations." + settingskey + ".resources");
|
2008-05-26 20:06:15 +00:00
|
|
|
|
|
|
|
// Make list of things filters
|
|
|
|
thingsfilters = new List<ThingsFilter>();
|
|
|
|
IDictionary cfgfilters = General.Settings.ReadSetting("configurations." + settingskey + ".thingsfilters", new Hashtable());
|
|
|
|
foreach(DictionaryEntry de in cfgfilters)
|
|
|
|
{
|
|
|
|
thingsfilters.Add(new ThingsFilter(General.Settings.Config, "configurations." + settingskey + ".thingsfilters." + de.Key));
|
|
|
|
}
|
2008-10-01 08:21:10 +00:00
|
|
|
|
|
|
|
// Make list of texture sets
|
2008-10-01 14:17:52 +00:00
|
|
|
texturesets = new List<DefinedTextureSet>();
|
2008-10-01 08:21:10 +00:00
|
|
|
IDictionary sets = General.Settings.ReadSetting("configurations." + settingskey + ".texturesets", new Hashtable());
|
|
|
|
foreach(DictionaryEntry de in sets)
|
|
|
|
{
|
|
|
|
texturesets.Add(new DefinedTextureSet(General.Settings.Config, "configurations." + settingskey + ".texturesets." + de.Key));
|
|
|
|
}
|
2008-11-27 11:59:17 +00:00
|
|
|
|
|
|
|
// Make list of edit modes
|
2008-11-27 19:25:13 +00:00
|
|
|
this.editmodes = new Dictionary<string, bool>();
|
2008-11-27 11:59:17 +00:00
|
|
|
IDictionary modes = General.Settings.ReadSetting("configurations." + settingskey + ".editmodes", new Hashtable());
|
|
|
|
foreach(DictionaryEntry de in modes)
|
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
if(de.Key.ToString().StartsWith(MODE_ENABLED_KEY))
|
|
|
|
editmodes.Add(de.Value.ToString(), true);
|
|
|
|
else if(de.Key.ToString().StartsWith(MODE_DISABLED_KEY))
|
|
|
|
editmodes.Add(de.Value.ToString(), false);
|
2008-11-27 11:59:17 +00:00
|
|
|
}
|
2007-06-14 23:31:57 +00:00
|
|
|
}
|
2008-11-27 11:59:17 +00:00
|
|
|
|
2007-09-27 22:55:03 +00:00
|
|
|
// Constructor
|
|
|
|
private ConfigurationInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
// This compares it to other ConfigurationInfo objects
|
|
|
|
public int CompareTo(ConfigurationInfo other)
|
|
|
|
{
|
|
|
|
// Compare
|
|
|
|
return name.CompareTo(other.name);
|
|
|
|
}
|
2007-09-27 22:55:03 +00:00
|
|
|
|
|
|
|
// This saves the settings to program configuration
|
|
|
|
public void SaveSettings()
|
|
|
|
{
|
|
|
|
// Write to configuration
|
2007-10-09 20:47:08 +00:00
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".nodebuildersave", nodebuildersave);
|
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".nodebuildertest", nodebuildertest);
|
2007-09-28 09:55:23 +00:00
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".testprogram", testprogram);
|
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".testparameters", testparameters);
|
2008-09-09 23:06:31 +00:00
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".customparameters", customparameters);
|
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".testskill", testskill);
|
2007-12-01 01:32:56 +00:00
|
|
|
resources.WriteToConfig(General.Settings.Config, "configurations." + settingskey + ".resources");
|
2008-11-27 11:59:17 +00:00
|
|
|
|
2008-05-26 20:06:15 +00:00
|
|
|
// Write filters to configuration
|
|
|
|
for(int i = 0; i < thingsfilters.Count; i++)
|
|
|
|
{
|
|
|
|
thingsfilters[i].WriteSettings(General.Settings.Config,
|
|
|
|
"configurations." + settingskey + ".thingsfilters.filter" + i.ToString(CultureInfo.InvariantCulture));
|
|
|
|
}
|
2008-10-01 08:21:10 +00:00
|
|
|
|
|
|
|
// Write texturesets to configuration
|
|
|
|
for(int i = 0; i < texturesets.Count; i++)
|
|
|
|
{
|
|
|
|
texturesets[i].WriteToConfig(General.Settings.Config,
|
|
|
|
"configurations." + settingskey + ".texturesets.set" + i.ToString(CultureInfo.InvariantCulture));
|
|
|
|
}
|
2008-11-27 11:59:17 +00:00
|
|
|
|
|
|
|
// Write filters to configuration
|
2008-11-27 19:25:13 +00:00
|
|
|
ListDictionary modeslist = new ListDictionary();
|
|
|
|
int index = 0;
|
|
|
|
foreach(KeyValuePair<string, bool> em in editmodes)
|
2008-11-27 11:59:17 +00:00
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
if(em.Value)
|
|
|
|
modeslist.Add(MODE_ENABLED_KEY + index.ToString(CultureInfo.InvariantCulture), em.Key);
|
|
|
|
else
|
|
|
|
modeslist.Add(MODE_DISABLED_KEY + index.ToString(CultureInfo.InvariantCulture), em.Key);
|
|
|
|
|
|
|
|
index++;
|
2008-11-27 11:59:17 +00:00
|
|
|
}
|
2008-11-27 19:25:13 +00:00
|
|
|
General.Settings.WriteSetting("configurations." + settingskey + ".editmodes", modeslist);
|
2007-09-27 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// String representation
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This clones the object
|
|
|
|
public ConfigurationInfo Clone()
|
|
|
|
{
|
|
|
|
ConfigurationInfo ci = new ConfigurationInfo();
|
|
|
|
ci.name = this.name;
|
|
|
|
ci.filename = this.filename;
|
|
|
|
ci.settingskey = this.settingskey;
|
2007-10-09 20:47:08 +00:00
|
|
|
ci.nodebuildersave = this.nodebuildersave;
|
|
|
|
ci.nodebuildertest = this.nodebuildertest;
|
2007-10-01 20:53:10 +00:00
|
|
|
ci.resources = new DataLocationList();
|
2007-09-27 22:55:03 +00:00
|
|
|
ci.resources.AddRange(this.resources);
|
2007-09-28 09:55:23 +00:00
|
|
|
ci.testprogram = this.testprogram;
|
|
|
|
ci.testparameters = this.testparameters;
|
2008-09-09 23:06:31 +00:00
|
|
|
ci.customparameters = this.customparameters;
|
|
|
|
ci.testskill = this.testskill;
|
2008-10-01 14:17:52 +00:00
|
|
|
ci.texturesets = new List<DefinedTextureSet>();
|
|
|
|
foreach(DefinedTextureSet s in this.texturesets) ci.texturesets.Add(s.Copy());
|
2009-01-05 15:57:41 +00:00
|
|
|
ci.thingsfilters = new List<ThingsFilter>();
|
|
|
|
foreach(ThingsFilter f in this.thingsfilters) ci.thingsfilters.Add(new ThingsFilter(f));
|
2008-11-27 19:25:13 +00:00
|
|
|
ci.editmodes = new Dictionary<string, bool>(this.editmodes);
|
2007-09-27 22:55:03 +00:00
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This applies settings from an object
|
|
|
|
public void Apply(ConfigurationInfo ci)
|
|
|
|
{
|
|
|
|
this.name = ci.name;
|
|
|
|
this.filename = ci.filename;
|
|
|
|
this.settingskey = ci.settingskey;
|
2007-10-09 20:47:08 +00:00
|
|
|
this.nodebuildersave = ci.nodebuildersave;
|
|
|
|
this.nodebuildertest = ci.nodebuildertest;
|
2007-10-01 20:53:10 +00:00
|
|
|
this.resources = new DataLocationList();
|
2007-09-27 22:55:03 +00:00
|
|
|
this.resources.AddRange(ci.resources);
|
2007-09-28 09:55:23 +00:00
|
|
|
this.testprogram = ci.testprogram;
|
|
|
|
this.testparameters = ci.testparameters;
|
2008-09-09 23:06:31 +00:00
|
|
|
this.customparameters = ci.customparameters;
|
|
|
|
this.testskill = ci.testskill;
|
2008-10-01 14:17:52 +00:00
|
|
|
this.texturesets = new List<DefinedTextureSet>();
|
|
|
|
foreach(DefinedTextureSet s in ci.texturesets) this.texturesets.Add(s.Copy());
|
2009-01-05 15:57:41 +00:00
|
|
|
this.thingsfilters = new List<ThingsFilter>();
|
|
|
|
foreach(ThingsFilter f in ci.thingsfilters) this.thingsfilters.Add(new ThingsFilter(f));
|
2008-11-27 19:25:13 +00:00
|
|
|
this.editmodes = new Dictionary<string, bool>(ci.editmodes);
|
2008-10-01 08:21:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the defaults
|
2008-11-27 19:25:13 +00:00
|
|
|
public void ApplyDefaults(GameConfiguration gameconfig)
|
2008-10-01 08:21:10 +00:00
|
|
|
{
|
2009-01-05 15:57:41 +00:00
|
|
|
// Some of the defaults can only be applied from game configuration
|
2008-11-27 19:25:13 +00:00
|
|
|
if(gameconfig != null)
|
|
|
|
{
|
2009-01-15 19:42:55 +00:00
|
|
|
// No nodebuildes set?
|
|
|
|
if(nodebuildersave == MISSING_NODEBUILDER) nodebuildersave = gameconfig.DefaultSaveCompiler;
|
|
|
|
if(nodebuildertest == MISSING_NODEBUILDER) nodebuildertest = gameconfig.DefaultTestCompiler;
|
|
|
|
|
2008-11-27 19:25:13 +00:00
|
|
|
// No texture sets?
|
|
|
|
if(texturesets.Count == 0)
|
|
|
|
{
|
|
|
|
// Copy the default texture sets from the game configuration
|
|
|
|
foreach(DefinedTextureSet s in gameconfig.TextureSets)
|
|
|
|
{
|
|
|
|
// Add a copy to our list
|
|
|
|
texturesets.Add(s.Copy());
|
|
|
|
}
|
|
|
|
}
|
2009-01-05 15:57:41 +00:00
|
|
|
|
|
|
|
// No things filters?
|
|
|
|
if(thingsfilters.Count == 0)
|
|
|
|
{
|
|
|
|
// Copy the things filters from game configuration
|
|
|
|
foreach(ThingsFilter f in gameconfig.ThingsFilters)
|
|
|
|
{
|
|
|
|
thingsfilters.Add(new ThingsFilter(f));
|
|
|
|
}
|
|
|
|
}
|
2008-11-27 19:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go for all available editing modes
|
|
|
|
foreach(EditModeInfo info in General.Editing.ModesInfo)
|
2008-10-01 08:21:10 +00:00
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
// Is this a mode thats is optional?
|
|
|
|
if(info.IsOptional)
|
2008-10-01 08:21:10 +00:00
|
|
|
{
|
2008-11-27 19:25:13 +00:00
|
|
|
// Add if not listed yet
|
|
|
|
if(!editmodes.ContainsKey(info.Type.FullName))
|
|
|
|
editmodes.Add(info.Type.FullName, info.Attributes.UseByDefault);
|
2008-10-01 08:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-27 22:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2007-06-14 23:31:57 +00:00
|
|
|
}
|
|
|
|
}
|