Skip to content

Commit

Permalink
Implemented Domiii's uber-config. App.config should now be obsolete.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubeca committed Jul 31, 2010
1 parent 66e5a10 commit ab4592c
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 155 deletions.
Binary file modified Lib/WCell.Util.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions TerrainDisplay/AxisRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

Expand Down Expand Up @@ -66,7 +66,7 @@ private int[] GetRenderingIndices()

private void BuildVerticiesAndIndicies()
{
var tileId = Config.DefaultTileIdentifier;
var tileId = TerrainDisplayConfig.DefaultTileIdentifier;
var tempVertices = new List<VertexPositionNormalColored>();
var tempIndices = new List<int>();
var offset = 0;
Expand Down
101 changes: 74 additions & 27 deletions TerrainDisplay/Config/TerrainDisplayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
using System.Xml.Serialization;
using NLog;
using WCell.Util;
using WCell.Util.NLog;
using WCell.Util.Variables;

//using WCell.MPQTool;

namespace TerrainDisplay
{
public class Config : XmlFile<Config>
public class TerrainDisplayConfig : VariableConfiguration<TerrainDisplayConfig, TypeVariableDefinition>
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
public static readonly string ConfigFile = "TerrainDisplay.Config.xml";
public static readonly string ConfigFileName = "TerrainDisplay.Config.xml";

public static string TerrainDisplayRoot = "../../";
public static string RunDir = TerrainDisplayRoot + "bin/";
Expand All @@ -29,46 +32,90 @@ public class Config : XmlFile<Config>
public static string MpqPath = @"D:\Games\MPQFiles";
public static TileIdentifier DefaultTileIdentifier = TileIdentifier.Redridge;

public static string OutputDir = Path.GetFullPath(TerrainDisplayRoot + "output/");

//public string wowDir;
//public string GetWoWDir()
//{
// return wowDir ?? (wowDir = DBCTool.FindWowDir());
//}

//public string WoWFileLocation
//{
// get { return Path.Combine(GetWoWDir(), "wow.exe"); }
//}


[XmlElement]
public static string OutputDir = Path.GetFullPath(TerrainDisplayRoot + "output/");
public TerrainDisplayConfig(Action<string> onError)
: base(onError)
{
}

private static Config s_instance;
public TerrainDisplayConfig() : base(OnError)
{
RootNodeName = "TerrainDisplayConfig";
s_instance = this;
}

public static Config Instance
private static TerrainDisplayConfig s_instance;
public static TerrainDisplayConfig Instance
{
get
{
if (s_instance == null)
return s_instance;
}
}

public override string FilePath
{
get { return GetFullPath(ConfigFileName); }
set { throw new InvalidOperationException("Cannot change the config's filename!");}
}

public override bool AutoSave { get; set; }

[NotVariable]
public static bool Loaded { get; private set; }

public static bool Initialize()
{
if (!Loaded)
{
Loaded = true;
s_instance.AddVariablesOfAsm<VariableAttribute>(typeof(TerrainDisplayConfig).Assembly);

try
{
if (File.Exists(ConfigFile))
if (!s_instance.Load())
{
log.Info("Loading ToolConfig from {0}...", Path.GetFullPath(ConfigFile));
s_instance = Load(ConfigFile);
s_instance.Save(true, false);
log.Warn("Config-file \"{0}\" not found - Created new file.", Instance.FilePath);
log.Warn("Please take a little time to configure your server and then restart the Application.");
log.Warn("See http://wiki.wcell.org/index.php/Configuration for more information.");
return false;
}
else
{
s_instance = new Config {
m_filename = ConfigFile
};
if (s_instance.AutoSave)
{
//s_instance.Save(true, true);
}
}

s_instance.Save();
}
return s_instance;
catch (Exception e)
{
LogUtil.ErrorException(e, "Unable to load Configuration.");
log.Error("Please correct the invalid values in your configuration file and restart the Applicaton.");
return false;
}
}
return true;
}

internal static void OnError(string msg)
{
log.Warn("<Config>" + msg);
}

internal static void OnError(string msg, params object[] args)
{
log.Warn("<Config>" + String.Format(msg, args));
}

public static string GetFullPath(string fileName)
{
return Path.IsPathRooted(fileName)
? fileName
: Path.Combine(Environment.CurrentDirectory, fileName);
}
}
}
157 changes: 119 additions & 38 deletions TerrainDisplay/Config/TileIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,147 @@
namespace TerrainDisplay
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace TerrainDisplay
{
public class TileIdentifier
public class TileIdentifier : IXmlSerializable
{
public string TileName;
public int MapId;
public string MapName;
public int TileX;
public int TileY;

public TileIdentifier(int mapId, string mapName, int tileX, int tileY)

public TileIdentifier()
{
}

public TileIdentifier(string tileName, int mapId, string mapName, int tileX, int tileY)
{
TileName = tileName;
MapId = mapId;
MapName = mapName;
TileX = tileX;
TileY = tileY;
}

public static TileIdentifier Redridge
public static TileIdentifier Redridge = new TileIdentifier
{
get
{
const int mapId = 0;
const string mapName = "Azeroth";
const int tileX = 49;
const int tileY = 36;
return new TileIdentifier(mapId, mapName, tileX, tileY);
}
TileName = "Redridge",
MapId = 0,
MapName = "Azeroth",
TileX = 49,
TileY = 36
};

public static TileIdentifier CenterTile = new TileIdentifier
{
TileName = "Map Center",
MapId = 0,
MapName = "Azeroth",
TileX = 32,
TileY = 32
};

public static TileIdentifier Stormwind = new TileIdentifier
{
TileName = "Stormwind",
MapId = 0,
MapName = "Azeroth",
TileX = 48,
TileY = 30
};

public static TileIdentifier BurningSteppes = new TileIdentifier
{
TileName = "Burning Steppes",
MapId = 0,
MapName = "Azeroth",
TileX = 49,
TileY = 33
};

#region Implementation of IXmlSerializable

public XmlSchema GetSchema()
{
throw new NotImplementedException();
}

public static TileIdentifier CenterTile
public void ReadXml(XmlReader reader)
{
get
reader.Read();
if (!reader.IsStartElement("TileName"))
{
const int mapId = 0;
const string mapName = "Azeroth";
const int tileX = 32;
const int tileY = 32;
return new TileIdentifier(mapId, mapName, tileX, tileY);
Console.WriteLine(
"Malformed TileIdentifer entry in the config Xml. TileName should be the first element.");
TileName = "MapCenter";
}
else
{
TileName = reader.ReadElementContentAsString();
}
}

public static TileIdentifier Stormwind
{
get
reader.Read();
if (!reader.IsStartElement("MapId"))
{
Console.WriteLine(
"Malformed TileIdentifer entry in the config Xml. MapId should be the second element.");
MapId = 0;
}
else
{
MapId = reader.ReadElementContentAsInt();
}

reader.Read();
if (!reader.IsStartElement("MapName"))
{
Console.WriteLine(
"Malformed TileIdentifer entry in the config Xml. MapName should be the third element.");
MapName = "Map Center";
}
else
{
MapName = reader.ReadElementContentAsString();
}

reader.Read();
if (!reader.IsStartElement("TileX"))
{
const int mapId = 0;
const string mapName = "Azeroth";
const int tileX = 48;
const int tileY = 30;
return new TileIdentifier(mapId, mapName, tileX, tileY);
Console.WriteLine(
"Malformed TileIdentifer entry in the config Xml. TileX should be fourth element.");
TileX = 32;
}
else
{
TileX = reader.ReadElementContentAsInt();
}

reader.Read();
if (!reader.IsStartElement("TileY"))
{
Console.WriteLine(
"Malformed TileIdentifer entry in the config Xml. TileY should be the fifth element. ... (Speaking of Fifth Element, what a great show, yeah?)");
TileY = 32;
}
else
{
TileY = reader.ReadElementContentAsInt();
}
}

public static TileIdentifier BurningSteppes
public void WriteXml(XmlWriter writer)
{
get
{
const int mapId = 0;
const string mapName = "Azeroth";
const int tileX = 49;
const int tileY = 33;
return new TileIdentifier(mapId, mapName, tileX, tileY);
}
writer.WriteElementString("TileName", TileName);
writer.WriteElementString("MapId", MapId.ToString());
writer.WriteElementString("MapName", MapName);
writer.WriteElementString("TileX", TileX.ToString());
writer.WriteElementString("TileY", TileY.ToString());
}

#endregion
}
}
6 changes: 3 additions & 3 deletions TerrainDisplay/Console/KeyBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public KeyBinding(Keys key, string unmodifiedString, string shiftString, string
//defines standard character mappings
class KeyboardHelper
{
static public KeyBinding[] ItalianBindings = new KeyBinding[]
static public readonly KeyBinding[] ItalianBindings = new KeyBinding[]
{
new KeyBinding( Keys.OemPipe, "\\", "|", "", ""),
new KeyBinding( Keys.OemBackslash, "<", ">", "", ""),
Expand Down Expand Up @@ -91,7 +91,7 @@ class KeyboardHelper
new KeyBinding( Keys.Z, "z", "Z", "", "")
};

static public KeyBinding[] SwedishBindings = new KeyBinding[]
static public readonly KeyBinding[] SwedishBindings = new KeyBinding[]
{
new KeyBinding( Keys.OemPipe, "\\", "|", "", ""),
new KeyBinding( Keys.OemBackslash, "\\", "|", "", ""),
Expand Down Expand Up @@ -155,7 +155,7 @@ class KeyboardHelper
new KeyBinding( Keys.Z, "z", "Z", "", "")
};

static public KeyBinding[] AmericanBindings = new KeyBinding[]
static public readonly KeyBinding[] AmericanBindings = new KeyBinding[]
{
new KeyBinding( Keys.OemPipe, "\\", "|", "", ""),
new KeyBinding( Keys.OemBackslash, "\\", "|", "", ""),
Expand Down
2 changes: 1 addition & 1 deletion TerrainDisplay/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static Microsoft.Xna.Framework.Matrix ToXna(this Matrix mat)

public static class MathExtensions
{
public static float Epsilon = 0.0001f;
public const float Epsilon = 0.0001f;

public static bool NearlyZero(this float val)
{
Expand Down
Loading

0 comments on commit ab4592c

Please sign in to comment.