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
|
|
|
|
|
2016-02-05 15:21:58 +00:00
|
|
|
using System;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2016-02-05 15:21:58 +00:00
|
|
|
using System.Collections.Specialized;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Globalization;
|
2016-02-05 15:21:58 +00:00
|
|
|
using System.IO;
|
2009-07-29 17:15:48 +00:00
|
|
|
using System.Reflection;
|
2016-02-05 15:21:58 +00:00
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2015-07-09 22:32:12 +00:00
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2009-04-19 18:07:22 +00:00
|
|
|
using CodeImp.DoomBuilder.IO;
|
2009-07-29 17:15:48 +00:00
|
|
|
using CodeImp.DoomBuilder.Plugins;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Map
|
|
|
|
{
|
2009-07-29 17:15:48 +00:00
|
|
|
public sealed class MapOptions
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Map configuration
|
2016-02-05 15:21:58 +00:00
|
|
|
private readonly Configuration mapconfig;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Game configuration
|
|
|
|
private string configfile;
|
|
|
|
|
|
|
|
// Map header name
|
|
|
|
private string currentname;
|
|
|
|
private string previousname; // When zero length string, map has not renamed
|
|
|
|
|
|
|
|
// Strict pathes loading?
|
|
|
|
private bool strictpatches;
|
|
|
|
|
|
|
|
// Additional resources
|
|
|
|
private DataLocationList resources;
|
|
|
|
|
2016-02-05 15:21:58 +00:00
|
|
|
//mxd. View settings for opened script files and lumps
|
|
|
|
private Dictionary<string, ScriptDocumentSettings> scriptfilesettings;
|
|
|
|
private Dictionary<string, ScriptDocumentSettings> scriptlumpsettings;
|
2013-11-21 10:53:11 +00:00
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
// mxd. Script compiler
|
|
|
|
private string scriptcompiler;
|
|
|
|
|
2013-11-21 10:53:11 +00:00
|
|
|
//mxd. Sector drawing options
|
|
|
|
private string defaultfloortexture;
|
|
|
|
private string defaultceiltexture;
|
2014-01-08 09:46:57 +00:00
|
|
|
private string defaulttoptexture;
|
2013-11-21 10:53:11 +00:00
|
|
|
private string defaultwalltexture;
|
2014-01-08 09:46:57 +00:00
|
|
|
private string defaultbottomtexture;
|
2013-11-21 11:51:48 +00:00
|
|
|
private int custombrightness;
|
|
|
|
private int customfloorheight;
|
|
|
|
private int customceilheight;
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Sector drawing overrides
|
|
|
|
private bool overridefloortexture;
|
|
|
|
private bool overrideceiltexture;
|
2014-01-08 09:46:57 +00:00
|
|
|
private bool overridetoptexture;
|
|
|
|
private bool overridemiddletexture;
|
|
|
|
private bool overridebottomtexture;
|
2013-11-21 10:53:11 +00:00
|
|
|
private bool overridefloorheight;
|
|
|
|
private bool overrideceilheight;
|
|
|
|
private bool overridebrightness;
|
2015-02-19 13:00:19 +00:00
|
|
|
|
|
|
|
//mxd.
|
|
|
|
private bool uselongtexturenames;
|
2015-07-09 22:32:12 +00:00
|
|
|
|
|
|
|
//mxd. Position and scale
|
2016-02-05 15:21:58 +00:00
|
|
|
private readonly Vector2D viewposition;
|
|
|
|
private readonly float viewscale;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2009-07-29 17:15:48 +00:00
|
|
|
internal string ConfigFile { get { return configfile; } set { configfile = value; } }
|
|
|
|
internal DataLocationList Resources { get { return resources; } }
|
|
|
|
internal bool StrictPatches { get { return strictpatches; } set { strictpatches = value; } }
|
2016-02-05 15:21:58 +00:00
|
|
|
internal Dictionary<string, ScriptDocumentSettings> ScriptFileSettings { get { return scriptfilesettings; } } //mxd
|
|
|
|
internal Dictionary<string, ScriptDocumentSettings> ScriptLumpSettings { get { return scriptlumpsettings; } } //mxd
|
2014-07-11 10:13:26 +00:00
|
|
|
internal string ScriptCompiler { get { return scriptcompiler; } set { scriptcompiler = value; } } //mxd
|
2009-07-29 17:15:48 +00:00
|
|
|
internal string PreviousName { get { return previousname; } set { previousname = value; } }
|
|
|
|
internal string CurrentName
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
get { return currentname; }
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// Change the name, but keep previous name
|
|
|
|
if(currentname != value)
|
|
|
|
{
|
2016-02-01 22:04:00 +00:00
|
|
|
if(string.IsNullOrEmpty(previousname)) previousname = currentname;
|
2009-04-19 18:07:22 +00:00
|
|
|
currentname = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-24 11:47:52 +00:00
|
|
|
internal bool LevelNameChanged { get { return (!string.IsNullOrEmpty(previousname) && previousname != currentname); } } //mxd
|
2009-07-29 17:15:48 +00:00
|
|
|
|
|
|
|
public string LevelName { get { return currentname; } }
|
2013-03-18 13:52:27 +00:00
|
|
|
public Dictionary<int, string> TagLabels { get { return tagLabels; } internal set { tagLabels = value; } } //mxd
|
|
|
|
private Dictionary<int, string> tagLabels;
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Sector drawing options
|
2014-01-08 09:46:57 +00:00
|
|
|
public string DefaultTopTexture { get { return defaulttoptexture; } set { defaulttoptexture = value; } }
|
2013-11-21 10:53:11 +00:00
|
|
|
public string DefaultWallTexture { get { return defaultwalltexture; } set { defaultwalltexture = value; } }
|
2014-01-08 09:46:57 +00:00
|
|
|
public string DefaultBottomTexture { get { return defaultbottomtexture; } set { defaultbottomtexture = value; } }
|
2013-11-21 10:53:11 +00:00
|
|
|
public string DefaultFloorTexture { get { return defaultfloortexture; } set { defaultfloortexture = value; } }
|
|
|
|
public string DefaultCeilingTexture { get { return defaultceiltexture; } set { defaultceiltexture = value; } }
|
2013-11-21 11:51:48 +00:00
|
|
|
public int CustomBrightness { get { return custombrightness; } set { custombrightness = value; } }
|
|
|
|
public int CustomFloorHeight { get { return customfloorheight; } set { customfloorheight = value; } }
|
|
|
|
public int CustomCeilingHeight { get { return customceilheight; } set { customceilheight = value; } }
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Sector drawing overrides
|
|
|
|
public bool OverrideFloorTexture { get { return overridefloortexture; } set { overridefloortexture = value; } }
|
|
|
|
public bool OverrideCeilingTexture { get { return overrideceiltexture; } set { overrideceiltexture = value; } }
|
2014-01-08 09:46:57 +00:00
|
|
|
public bool OverrideTopTexture { get { return overridetoptexture; } set { overridetoptexture = value; } }
|
|
|
|
public bool OverrideMiddleTexture { get { return overridemiddletexture; } set { overridemiddletexture = value; } }
|
|
|
|
public bool OverrideBottomTexture { get { return overridebottomtexture; } set { overridebottomtexture = value; } }
|
2013-11-21 10:53:11 +00:00
|
|
|
public bool OverrideFloorHeight { get { return overridefloorheight; } set { overridefloorheight = value; } }
|
|
|
|
public bool OverrideCeilingHeight { get { return overrideceilheight; } set { overrideceilheight = value; } }
|
|
|
|
public bool OverrideBrightness { get { return overridebrightness; } set { overridebrightness = value; } }
|
2014-11-25 11:52:01 +00:00
|
|
|
|
2015-02-19 13:00:19 +00:00
|
|
|
//mxd
|
|
|
|
public bool UseLongTextureNames { get { return uselongtexturenames; } set { uselongtexturenames = value; } }
|
|
|
|
|
2015-07-09 22:32:12 +00:00
|
|
|
//mxd. Position and scale
|
|
|
|
public Vector2D ViewPosition { get { return viewposition; } }
|
|
|
|
public float ViewScale { get { return viewscale; } }
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
internal MapOptions()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.previousname = "";
|
|
|
|
this.currentname = "";
|
|
|
|
this.configfile = "";
|
|
|
|
this.strictpatches = false;
|
|
|
|
this.resources = new DataLocationList();
|
|
|
|
this.mapconfig = new Configuration(true);
|
2016-02-05 15:21:58 +00:00
|
|
|
this.scriptfilesettings = new Dictionary<string, ScriptDocumentSettings>(); //mxd
|
|
|
|
this.scriptlumpsettings = new Dictionary<string, ScriptDocumentSettings>(); //mxd
|
2014-07-11 10:13:26 +00:00
|
|
|
this.scriptcompiler = ""; //mxd
|
2013-03-18 13:52:27 +00:00
|
|
|
this.tagLabels = new Dictionary<int, string>(); //mxd
|
2015-07-09 22:32:12 +00:00
|
|
|
this.viewposition = new Vector2D(float.NaN, float.NaN); //mxd
|
|
|
|
this.viewscale = float.NaN; //mxd
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Sector drawing options
|
2013-11-21 11:51:48 +00:00
|
|
|
this.custombrightness = 196;
|
|
|
|
this.customceilheight = 128;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor to load from Doom Builder Map Settings Configuration
|
2015-02-19 13:00:19 +00:00
|
|
|
internal MapOptions(Configuration cfg, string mapname, bool longtexturenamessupported)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.previousname = "";
|
|
|
|
this.currentname = mapname;
|
|
|
|
this.strictpatches = General.Int2Bool(cfg.ReadSetting("strictpatches", 0));
|
|
|
|
this.configfile = cfg.ReadSetting("gameconfig", "");
|
|
|
|
this.resources = new DataLocationList();
|
|
|
|
this.mapconfig = new Configuration(true);
|
2016-02-05 15:21:58 +00:00
|
|
|
this.scriptfilesettings = new Dictionary<string, ScriptDocumentSettings>(); //mxd
|
|
|
|
this.scriptlumpsettings = new Dictionary<string, ScriptDocumentSettings>(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Read map configuration
|
|
|
|
this.mapconfig.Root = cfg.ReadSetting("maps." + mapname, new Hashtable());
|
|
|
|
|
2013-11-21 10:53:11 +00:00
|
|
|
//mxd. Read Tag Labels
|
2013-03-18 13:52:27 +00:00
|
|
|
this.tagLabels = new Dictionary<int, string>();
|
|
|
|
ListDictionary tagLabelsData = (ListDictionary)this.mapconfig.ReadSetting("taglabels", new ListDictionary());
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
foreach(DictionaryEntry tagLabelsEntry in tagLabelsData)
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
int tag = 0;
|
|
|
|
string label = string.Empty;
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
foreach(DictionaryEntry entry in (ListDictionary)tagLabelsEntry.Value)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
switch((string)entry.Key)
|
2015-07-15 09:09:47 +00:00
|
|
|
{
|
|
|
|
case "tag": tag = (int)entry.Value; break;
|
|
|
|
case "label": label = (string)entry.Value; break;
|
|
|
|
}
|
2013-03-18 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(tag != 0 && !string.IsNullOrEmpty(label))
|
|
|
|
tagLabels.Add(tag, label);
|
|
|
|
}
|
|
|
|
|
2014-07-11 10:13:26 +00:00
|
|
|
//mxd. Script compiler
|
|
|
|
scriptcompiler = this.mapconfig.ReadSetting("scriptcompiler", string.Empty);
|
|
|
|
|
2013-11-21 10:53:11 +00:00
|
|
|
//mxd. Read Sector drawing options
|
|
|
|
defaultfloortexture = this.mapconfig.ReadSetting("defaultfloortexture", string.Empty);
|
|
|
|
defaultceiltexture = this.mapconfig.ReadSetting("defaultceiltexture", string.Empty);
|
2014-01-08 09:46:57 +00:00
|
|
|
defaulttoptexture = this.mapconfig.ReadSetting("defaulttoptexture", string.Empty);
|
2013-11-21 10:53:11 +00:00
|
|
|
defaultwalltexture = this.mapconfig.ReadSetting("defaultwalltexture", string.Empty);
|
2014-01-08 09:46:57 +00:00
|
|
|
defaultbottomtexture = this.mapconfig.ReadSetting("defaultbottomtexture", string.Empty);
|
2013-11-21 11:51:48 +00:00
|
|
|
custombrightness = General.Clamp(this.mapconfig.ReadSetting("custombrightness", 196), 0, 255);
|
|
|
|
customfloorheight = this.mapconfig.ReadSetting("customfloorheight", 0);
|
|
|
|
customceilheight = this.mapconfig.ReadSetting("customceilheight", 128);
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Read Sector drawing overrides
|
|
|
|
overridefloortexture = this.mapconfig.ReadSetting("overridefloortexture", false);
|
|
|
|
overrideceiltexture = this.mapconfig.ReadSetting("overrideceiltexture", false);
|
2014-01-08 09:46:57 +00:00
|
|
|
overridetoptexture = this.mapconfig.ReadSetting("overridetoptexture", false);
|
|
|
|
overridemiddletexture = this.mapconfig.ReadSetting("overridemiddletexture", false);
|
|
|
|
overridebottomtexture = this.mapconfig.ReadSetting("overridebottomtexture", false);
|
2013-11-21 10:53:11 +00:00
|
|
|
overridefloorheight = this.mapconfig.ReadSetting("overridefloorheight", false);
|
|
|
|
overrideceilheight = this.mapconfig.ReadSetting("overrideceilheight", false);
|
|
|
|
overridebrightness = this.mapconfig.ReadSetting("overridebrightness", false);
|
|
|
|
|
2015-02-19 13:00:19 +00:00
|
|
|
//mxd
|
|
|
|
uselongtexturenames = longtexturenamessupported && this.mapconfig.ReadSetting("uselongtexturenames", false);
|
|
|
|
|
2015-07-09 22:32:12 +00:00
|
|
|
//mxd. Position and scale
|
|
|
|
float vpx = this.mapconfig.ReadSetting("viewpositionx", float.NaN);
|
|
|
|
float vpy = this.mapconfig.ReadSetting("viewpositiony", float.NaN);
|
|
|
|
if(!float.IsNaN(vpx) && !float.IsNaN(vpy)) viewposition = new Vector2D(vpx, vpy);
|
|
|
|
viewscale = this.mapconfig.ReadSetting("viewscale", float.NaN);
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Resources
|
|
|
|
IDictionary reslist = this.mapconfig.ReadSetting("resources", new Hashtable());
|
|
|
|
foreach(DictionaryEntry mp in reslist)
|
|
|
|
{
|
|
|
|
// Item is a structure?
|
2016-02-05 15:21:58 +00:00
|
|
|
IDictionary resinfo = mp.Value as IDictionary;
|
|
|
|
if(resinfo != null)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Create resource
|
2015-12-28 15:01:53 +00:00
|
|
|
DataLocation res = new DataLocation();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Copy information from Configuration to ResourceLocation
|
|
|
|
if(resinfo.Contains("type") && (resinfo["type"] is int)) res.type = (int)resinfo["type"];
|
|
|
|
if(resinfo.Contains("location") && (resinfo["location"] is string)) res.location = (string)resinfo["location"];
|
|
|
|
if(resinfo.Contains("textures") && (resinfo["textures"] is bool)) res.option1 = (bool)resinfo["textures"];
|
|
|
|
if(resinfo.Contains("flats") && (resinfo["flats"] is bool)) res.option2 = (bool)resinfo["flats"];
|
|
|
|
|
|
|
|
// Add resource
|
|
|
|
AddResource(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-05 15:21:58 +00:00
|
|
|
//mxd. Script files settings
|
|
|
|
IDictionary sflist = this.mapconfig.ReadSetting("scriptfiles", new Hashtable());
|
|
|
|
foreach(DictionaryEntry mp in sflist)
|
|
|
|
{
|
|
|
|
// Item is a structure?
|
|
|
|
IDictionary scfinfo = mp.Value as IDictionary;
|
|
|
|
if(scfinfo != null)
|
|
|
|
{
|
|
|
|
ScriptDocumentSettings settings = ReadScriptDocumentSettings(scfinfo);
|
|
|
|
if(!string.IsNullOrEmpty(settings.Filename)) scriptfilesettings.Add(settings.Filename, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. Script lumps settings
|
|
|
|
IDictionary sllist = this.mapconfig.ReadSetting("scriptlumps", new Hashtable());
|
|
|
|
foreach(DictionaryEntry mp in sllist)
|
|
|
|
{
|
|
|
|
// Item is a structure?
|
|
|
|
IDictionary sclinfo = mp.Value as IDictionary;
|
|
|
|
if(sclinfo != null)
|
|
|
|
{
|
|
|
|
ScriptDocumentSettings settings = ReadScriptDocumentSettings(sclinfo);
|
|
|
|
if(!string.IsNullOrEmpty(settings.Filename)) scriptlumpsettings.Add(settings.Filename, settings);
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 15:21:58 +00:00
|
|
|
//mxd. Is that really needed?..
|
2016-03-18 12:52:12 +00:00
|
|
|
/*~MapOptions()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
this.resources = null;
|
2016-02-05 15:21:58 +00:00
|
|
|
this.scriptfilesettings = null; //mxd
|
|
|
|
this.scriptlumpsettings = null; //mxd
|
2016-03-18 12:52:12 +00:00
|
|
|
}*/
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2009-07-29 17:15:48 +00:00
|
|
|
// This makes the path prefix for the given assembly
|
2014-03-05 09:21:28 +00:00
|
|
|
private static string GetPluginPathPrefix(Assembly asm)
|
2009-07-29 17:15:48 +00:00
|
|
|
{
|
|
|
|
Plugin p = General.Plugins.FindPluginByAssembly(asm);
|
|
|
|
return "plugins." + p.Name.ToLowerInvariant() + ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadPluginSetting
|
|
|
|
public string ReadPluginSetting(string setting, string defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public int ReadPluginSetting(string setting, int defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public float ReadPluginSetting(string setting, float defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public short ReadPluginSetting(string setting, short defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public long ReadPluginSetting(string setting, long defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public bool ReadPluginSetting(string setting, bool defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public byte ReadPluginSetting(string setting, byte defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
public IDictionary ReadPluginSetting(string setting, IDictionary defaultsetting) { return mapconfig.ReadSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, defaultsetting); }
|
|
|
|
|
|
|
|
// ReadPluginSetting with specific plugin
|
|
|
|
public string ReadPluginSetting(string pluginname, string setting, string defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public int ReadPluginSetting(string pluginname, string setting, int defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public float ReadPluginSetting(string pluginname, string setting, float defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public short ReadPluginSetting(string pluginname, string setting, short defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public long ReadPluginSetting(string pluginname, string setting, long defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public bool ReadPluginSetting(string pluginname, string setting, bool defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public byte ReadPluginSetting(string pluginname, string setting, byte defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
public IDictionary ReadPluginSetting(string pluginname, string setting, IDictionary defaultsetting) { return mapconfig.ReadSetting(pluginname.ToLowerInvariant() + "." + setting, defaultsetting); }
|
|
|
|
|
|
|
|
// WritePluginSetting
|
|
|
|
public bool WritePluginSetting(string setting, object settingvalue) { return mapconfig.WriteSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting, settingvalue); }
|
|
|
|
|
|
|
|
// DeletePluginSetting
|
|
|
|
public bool DeletePluginSetting(string setting) { return mapconfig.DeleteSetting(GetPluginPathPrefix(Assembly.GetCallingAssembly()) + setting); }
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This stores the map options in a configuration
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void WriteConfiguration(string settingsfile)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
Configuration wadcfg;
|
|
|
|
|
|
|
|
// Write resources to config
|
|
|
|
resources.WriteToConfig(mapconfig, "resources");
|
|
|
|
|
2014-07-16 09:45:04 +00:00
|
|
|
//mxd. Save selection groups
|
|
|
|
General.Map.Map.WriteSelectionGroups(mapconfig);
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
//mxd. Save Tag Labels
|
2014-11-25 11:52:01 +00:00
|
|
|
if(tagLabels.Count > 0)
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
ListDictionary tagLabelsData = new ListDictionary();
|
|
|
|
int counter = 1;
|
|
|
|
|
2014-11-25 11:52:01 +00:00
|
|
|
foreach(KeyValuePair<int, string> group in tagLabels)
|
|
|
|
{
|
2013-03-18 13:52:27 +00:00
|
|
|
ListDictionary data = new ListDictionary();
|
|
|
|
data.Add("tag", group.Key);
|
|
|
|
data.Add("label", group.Value);
|
|
|
|
tagLabelsData.Add("taglabel"+counter, data);
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapconfig.WriteSetting("taglabels", tagLabelsData);
|
|
|
|
}
|
|
|
|
|
2013-11-21 10:53:11 +00:00
|
|
|
//mxd. Write Sector drawing options
|
|
|
|
mapconfig.WriteSetting("defaultfloortexture", defaultfloortexture);
|
|
|
|
mapconfig.WriteSetting("defaultceiltexture", defaultceiltexture);
|
2014-01-08 09:46:57 +00:00
|
|
|
mapconfig.WriteSetting("defaulttoptexture", defaulttoptexture);
|
2013-11-21 10:53:11 +00:00
|
|
|
mapconfig.WriteSetting("defaultwalltexture", defaultwalltexture);
|
2014-01-08 09:46:57 +00:00
|
|
|
mapconfig.WriteSetting("defaultbottomtexture", defaultbottomtexture);
|
2013-11-21 11:51:48 +00:00
|
|
|
mapconfig.WriteSetting("custombrightness", custombrightness);
|
|
|
|
mapconfig.WriteSetting("customfloorheight", customfloorheight);
|
|
|
|
mapconfig.WriteSetting("customceilheight", customceilheight);
|
2013-11-21 10:53:11 +00:00
|
|
|
|
|
|
|
//mxd. Write Sector drawing overrides
|
|
|
|
mapconfig.WriteSetting("overridefloortexture", overridefloortexture);
|
|
|
|
mapconfig.WriteSetting("overrideceiltexture", overrideceiltexture);
|
2014-01-08 09:46:57 +00:00
|
|
|
mapconfig.WriteSetting("overridetoptexture", overridetoptexture);
|
|
|
|
mapconfig.WriteSetting("overridemiddletexture", overridemiddletexture);
|
|
|
|
mapconfig.WriteSetting("overridebottomtexture", overridebottomtexture);
|
2013-11-21 10:53:11 +00:00
|
|
|
mapconfig.WriteSetting("overridefloorheight", overridefloorheight);
|
|
|
|
mapconfig.WriteSetting("overrideceilheight", overrideceilheight);
|
|
|
|
mapconfig.WriteSetting("overridebrightness", overridebrightness);
|
|
|
|
|
2015-02-19 13:00:19 +00:00
|
|
|
//mxd
|
|
|
|
mapconfig.WriteSetting("uselongtexturenames", uselongtexturenames);
|
|
|
|
|
2015-07-09 22:32:12 +00:00
|
|
|
//mxd. Position and scale
|
|
|
|
mapconfig.WriteSetting("viewpositionx", General.Map.Renderer2D.OffsetX);
|
|
|
|
mapconfig.WriteSetting("viewpositiony", General.Map.Renderer2D.OffsetY);
|
|
|
|
mapconfig.WriteSetting("viewscale", General.Map.Renderer2D.Scale);
|
|
|
|
|
2014-07-16 09:45:04 +00:00
|
|
|
//mxd. Write script compiler
|
|
|
|
if(!string.IsNullOrEmpty(scriptcompiler))
|
|
|
|
mapconfig.WriteSetting("scriptcompiler", scriptcompiler);
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Write grid settings
|
|
|
|
General.Map.Grid.WriteToConfig(mapconfig, "grid");
|
|
|
|
|
2016-02-05 15:21:58 +00:00
|
|
|
//mxd. Write script files settings to config
|
|
|
|
mapconfig.DeleteSetting("scriptfiles");
|
|
|
|
foreach(ScriptDocumentSettings settings in scriptfilesettings.Values)
|
|
|
|
WriteScriptDocumentSettings(mapconfig, "scriptfiles.file", settings);
|
|
|
|
|
|
|
|
|
|
|
|
//mxd. Write script lumps settings to config
|
|
|
|
mapconfig.DeleteSetting("scriptlumps");
|
|
|
|
foreach(ScriptDocumentSettings settings in scriptlumpsettings.Values)
|
|
|
|
WriteScriptDocumentSettings(mapconfig, "scriptlumps.lump", settings);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Load the file or make a new file
|
|
|
|
if(File.Exists(settingsfile))
|
|
|
|
wadcfg = new Configuration(settingsfile, true);
|
|
|
|
else
|
|
|
|
wadcfg = new Configuration(true);
|
|
|
|
|
|
|
|
// Write configuration type information
|
|
|
|
wadcfg.WriteSetting("type", "Doom Builder Map Settings Configuration");
|
|
|
|
wadcfg.WriteSetting("gameconfig", configfile);
|
|
|
|
wadcfg.WriteSetting("strictpatches", General.Bool2Int(strictpatches));
|
|
|
|
|
|
|
|
// Update the settings file with this map configuration
|
|
|
|
wadcfg.WriteSetting("maps." + currentname, mapconfig.Root);
|
|
|
|
|
|
|
|
// Save file
|
|
|
|
wadcfg.SaveConfiguration(settingsfile);
|
|
|
|
}
|
2016-02-05 15:21:58 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private static ScriptDocumentSettings ReadScriptDocumentSettings(IDictionary scfinfo)
|
|
|
|
{
|
|
|
|
ScriptDocumentSettings settings = new ScriptDocumentSettings { FoldLevels = new Dictionary<int, HashSet<int>>() };
|
|
|
|
|
|
|
|
// Copy information from Configuration to ScriptDocumentSaveSettings
|
|
|
|
if(scfinfo.Contains("filename") && (scfinfo["filename"] is string)) settings.Filename = (string)scfinfo["filename"];
|
|
|
|
if(scfinfo.Contains("hash") && (scfinfo["hash"] is long)) settings.Hash = (long)scfinfo["hash"];
|
|
|
|
if(scfinfo.Contains("caretposition") && (scfinfo["caretposition"] is int)) settings.CaretPosition = (int)scfinfo["caretposition"];
|
|
|
|
if(scfinfo.Contains("firstvisibleline") && (scfinfo["firstvisibleline"] is int)) settings.FirstVisibleLine = (int)scfinfo["firstvisibleline"];
|
|
|
|
if(scfinfo.Contains("activetab") && (scfinfo["activetab"] is bool)) settings.IsActiveTab = (bool)scfinfo["activetab"];
|
|
|
|
if(scfinfo.Contains("foldlevels") && (scfinfo["foldlevels"] is string))
|
|
|
|
{
|
|
|
|
// 1:12,13,14;2:21,43,36
|
|
|
|
string foldstr = (string)scfinfo["foldlevels"];
|
|
|
|
|
|
|
|
// Convert string to dictionary
|
|
|
|
if(!string.IsNullOrEmpty(foldstr))
|
|
|
|
{
|
|
|
|
//TODO: add all kinds of warnings?
|
|
|
|
string[] foldlevels = foldstr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
foreach(string foldlevel in foldlevels)
|
|
|
|
{
|
|
|
|
// 1:12,13,14
|
|
|
|
string[] parts = foldlevel.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if(parts.Length != 2) continue;
|
|
|
|
|
|
|
|
int fold;
|
|
|
|
if(!int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out fold)) continue;
|
|
|
|
if(settings.FoldLevels.ContainsKey(fold)) continue;
|
|
|
|
|
|
|
|
string[] linenumbersstr = parts[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if(linenumbersstr.Length == 0) continue;
|
|
|
|
|
|
|
|
HashSet<int> linenumbers = new HashSet<int>();
|
|
|
|
foreach(string linenumber in linenumbersstr)
|
|
|
|
{
|
|
|
|
int linenum;
|
|
|
|
if(int.TryParse(linenumber, NumberStyles.Integer, CultureInfo.InvariantCulture, out linenum))
|
|
|
|
linenumbers.Add(linenum);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(linenumbers.Count != linenumbersstr.Length) continue;
|
|
|
|
|
|
|
|
// Add to collection
|
|
|
|
settings.FoldLevels.Add(fold, new HashSet<int>(linenumbers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
private static void WriteScriptDocumentSettings(Configuration mapconfig, string prefix, ScriptDocumentSettings settings)
|
|
|
|
{
|
|
|
|
// Store data
|
|
|
|
ListDictionary data = new ListDictionary();
|
|
|
|
data.Add("filename", settings.Filename);
|
|
|
|
data.Add("hash", settings.Hash);
|
|
|
|
if(settings.CaretPosition > 0) data.Add("caretposition", settings.CaretPosition);
|
|
|
|
if(settings.FirstVisibleLine > 0) data.Add("firstvisibleline", settings.FirstVisibleLine);
|
|
|
|
if(settings.IsActiveTab) data.Add("activetab", true);
|
|
|
|
|
|
|
|
// Convert dictionary to string
|
|
|
|
List<string> foldlevels = new List<string>();
|
|
|
|
foreach(KeyValuePair<int, HashSet<int>> group in settings.FoldLevels)
|
|
|
|
{
|
|
|
|
List<string> linenums = new List<string>(group.Value.Count);
|
|
|
|
foreach(int i in group.Value) linenums.Add(i.ToString());
|
|
|
|
foldlevels.Add(group.Key + ":" + string.Join(",", linenums.ToArray()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to collection
|
|
|
|
if(foldlevels.Count > 0) data.Add("foldlevels", string.Join(";", foldlevels.ToArray()));
|
|
|
|
|
|
|
|
// Write to config
|
|
|
|
mapconfig.WriteSetting(prefix, data);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This adds a resource location and returns the index where the item was added
|
2009-07-29 17:15:48 +00:00
|
|
|
internal int AddResource(DataLocation res)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Get a fully qualified path
|
|
|
|
res.location = Path.GetFullPath(res.location);
|
|
|
|
|
|
|
|
// Go for all items in the list
|
|
|
|
for(int i = 0; i < resources.Count; i++)
|
|
|
|
{
|
|
|
|
// Check if location is already added
|
|
|
|
if(Path.GetFullPath(resources[i].location) == res.location)
|
|
|
|
{
|
|
|
|
// Update the item in the list
|
|
|
|
resources[i] = res;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to list
|
|
|
|
resources.Add(res);
|
|
|
|
return resources.Count - 1;
|
|
|
|
}
|
|
|
|
|
2012-06-01 19:53:14 +00:00
|
|
|
/// <summary>
|
|
|
|
/// This returns the resource locations as configured.
|
|
|
|
/// </summary>
|
|
|
|
public DataLocationList GetResources()
|
|
|
|
{
|
|
|
|
return new DataLocationList(resources);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// This clears all reasource
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void ClearResources()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Clear list
|
|
|
|
resources.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This removes a resource by index
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void RemoveResource(int index)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Remove the item
|
|
|
|
resources.RemoveAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This copies resources from a list
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void CopyResources(DataLocationList fromlist)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Clear this list
|
|
|
|
resources.Clear();
|
|
|
|
resources.AddRange(fromlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This loads the grid settings
|
|
|
|
internal void ApplyGridSettings()
|
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
General.Map.Grid.ReadFromConfig(mapconfig, "grid", General.Map.Config.UseLongTextureNames);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2014-07-16 09:45:04 +00:00
|
|
|
|
|
|
|
//mxd. This reads stored selection groups from the map configuration
|
|
|
|
internal void ReadSelectionGroups()
|
|
|
|
{
|
|
|
|
General.Map.Map.ReadSelectionGroups(mapconfig);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This displays the current map name
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return currentname;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the UDMF field type
|
2009-07-29 17:15:48 +00:00
|
|
|
internal int GetUniversalFieldType(string elementname, string fieldname, int defaulttype)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Check if the field type is set in the game configuration
|
2014-07-16 09:45:04 +00:00
|
|
|
int type = General.Map.Config.ReadSetting("universalfields." + elementname + "." + fieldname + ".type", -1);
|
2009-04-19 18:07:22 +00:00
|
|
|
if(type == -1)
|
|
|
|
{
|
|
|
|
// Read from map configuration
|
|
|
|
type = mapconfig.ReadSetting("fieldtypes." + elementname + "." + fieldname, defaulttype);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This stores the UDMF field type
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void SetUniversalFieldType(string elementname, string fieldname, int type)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Check if the type of this field is not set in the game configuration
|
|
|
|
if(General.Map.Config.ReadSetting("universalfields." + elementname + "." + fieldname + ".type", -1) == -1)
|
|
|
|
{
|
|
|
|
// Write type to map configuration
|
|
|
|
mapconfig.WriteSetting("fieldtypes." + elementname + "." + fieldname, type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This removes all UDMF field types
|
2009-07-29 17:15:48 +00:00
|
|
|
internal void ForgetUniversalFieldTypes()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
mapconfig.DeleteSetting("fieldtypes");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|