diff --git a/MCGalaxy/Config/ConfigElement.cs b/MCGalaxy/Config/ConfigElement.cs index c6992c32a..8b49e495f 100644 --- a/MCGalaxy/Config/ConfigElement.cs +++ b/MCGalaxy/Config/ConfigElement.cs @@ -27,8 +27,12 @@ namespace MCGalaxy { public ConfigAttribute Attrib; public FieldInfo Field; - const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | - BindingFlags.Public | BindingFlags.NonPublic; + public string Format(object instance) { + object value = Field.GetValue(instance); + return Attrib.Name + " = " + Attrib.Serialise(value); + } + + const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; public static ConfigElement[] GetAll(Type type) { List elems = new List(); @@ -59,10 +63,8 @@ namespace MCGalaxy { } /// Writes all config elements to the given stream, grouped by named sections. - public static void Serialise(ConfigElement[] elements, string suffix, - StreamWriter dst, object instance) { - Dictionary> sections - = new Dictionary>(); + public static void Serialise(ConfigElement[] elements, string suffix, StreamWriter dst, object instance) { + Dictionary> sections = new Dictionary>(); foreach (ConfigElement elem in elements) { List members; @@ -76,19 +78,10 @@ namespace MCGalaxy { foreach (var kvp in sections) { dst.WriteLine("# " + kvp.Key + suffix); foreach (ConfigElement elem in kvp.Value) { - object value = elem.Field.GetValue(instance); - dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value)); + dst.WriteLine(elem.Format(instance)); } dst.WriteLine(); } } - - /// Writes all config elements to the given stream. - public static void SerialisePlain(ConfigElement[] elements, StreamWriter dst, object instance) { - foreach (ConfigElement elem in elements) { - object value = elem.Field.GetValue(instance); - dst.WriteLine(elem.Attrib.Name + " = " + elem.Attrib.Serialise(value)); - } - } } } diff --git a/MCGalaxy/Games/CTF/CtfConfig.cs b/MCGalaxy/Games/CTF/CtfConfig.cs index 8e759871b..c2fdc6e86 100644 --- a/MCGalaxy/Games/CTF/CtfConfig.cs +++ b/MCGalaxy/Games/CTF/CtfConfig.cs @@ -101,8 +101,11 @@ namespace MCGalaxy.Games { } public void Save(string mapName) { + ConfigElement[] elements = elems; using (StreamWriter w = new StreamWriter("CTF/" + mapName + ".config")) { - ConfigElement.SerialisePlain(elems, w, this); + for (int i = 0; i < elements.Length; i++) { + w.WriteLine(elements[i].Format(this)); + } } } diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index 3b1e0de55..a81d9f1e9 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -40,14 +40,15 @@ namespace MCGalaxy { public sealed partial class Level : IDisposable { - public Level(string n, ushort x, ushort y, ushort z) { - Width = x; Height = y; Length = z; - if (Width < 16) Width = 16; - if (Height < 16) Height = 16; - if (Length < 16) Length = 16; - - for (int i = 0; i < CustomBlockDefs.Length; i++) + public Level(string name, ushort width, ushort height, ushort length) { + if (width < 1) width = 1; + if (height < 1) height = 1; + if (length < 1) length = 1; + + Width = width; Height = height; Length = length; + for (int i = 0; i < CustomBlockDefs.Length; i++) { CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i]; + } LoadCoreProps(); for (int i = 0; i < blockAABBs.Length; i++) { @@ -56,10 +57,10 @@ namespace MCGalaxy { } UpdateBlockHandlers(); - name = n; MapName = n.ToLower(); + this.name = name; MapName = name.ToLower(); BlockDB = new BlockDB(this); - Config.EdgeLevel = (short)(y / 2); - Config.CloudsHeight = (short)(y + 2); + Config.EdgeLevel = (short)(height / 2); + Config.CloudsHeight = (short)(height + 2); blocks = new byte[Width * Height * Length]; ChunksX = Utils.CeilDiv16(Width); diff --git a/MCGalaxy/util/SparseBitSet.cs b/MCGalaxy/util/SparseBitSet.cs index c2ac7a90d..d82e71e42 100644 --- a/MCGalaxy/util/SparseBitSet.cs +++ b/MCGalaxy/util/SparseBitSet.cs @@ -31,8 +31,7 @@ namespace MCGalaxy.Util { } public bool Get(int x, int y, int z) { - int index = (x >> 4) + chunksX * - ((z >> 4) + (y >> 4) * chunksZ); + int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ); byte[] chunk = bits[index]; if (chunk == null) return false; @@ -41,8 +40,7 @@ namespace MCGalaxy.Util { } public void Set(int x, int y, int z, bool bit) { - int index = (x >> 4) + chunksX * - ((z >> 4) + (y >> 4) * chunksZ); + int index = (x >> 4) + chunksX * ((z >> 4) + (y >> 4) * chunksZ); byte[] chunk = bits[index]; if (chunk == null) { chunk = new byte[(16 * 16 * 16) / 8];