From 60bc0c3f69c60a2490470625ee86afc386776d48 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 8 Apr 2010 19:38:53 +1200 Subject: [PATCH] Convert and store smudges in map --- MapConverter/MapConverter.cs | 11 ++++++ OpenRA.FileFormats/Map/Map.cs | 25 +++++++++--- OpenRA.FileFormats/Map/SmudgeReference.cs | 41 ++++++++++++++++++++ OpenRA.FileFormats/MiniYaml.cs | 14 +++---- OpenRA.FileFormats/OpenRA.FileFormats.csproj | 5 ++- 5 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 OpenRA.FileFormats/Map/SmudgeReference.cs diff --git a/MapConverter/MapConverter.cs b/MapConverter/MapConverter.cs index 8c0e9ad32d..c705cf4279 100644 --- a/MapConverter/MapConverter.cs +++ b/MapConverter/MapConverter.cs @@ -169,6 +169,7 @@ namespace MapConverter LoadActors(file, "STRUCTURES"); LoadActors(file, "UNITS"); LoadActors(file, "INFANTRY"); + LoadSmudges(file, "SMUDGE"); var wp = file.GetSection("Waypoints") .Where(kv => int.Parse(kv.Value) > 0) @@ -358,6 +359,16 @@ namespace MapConverter } } + void LoadSmudges(IniFile file, string section) + { + foreach (var s in file.GetSection(section, true)) + { + //loc=type,loc,depth + var parts = s.Value.Split( ',' ); + var loc = int.Parse(parts[1]); + Map.Smudges.Add(new SmudgeReference(parts[0].ToLowerInvariant(),new int2(loc % MapSize, loc / MapSize),int.Parse(parts[2]))); + } + } static string Truncate( string s, int maxLength ) { return s.Length <= maxLength ? s : s.Substring(0,maxLength ); diff --git a/OpenRA.FileFormats/Map/Map.cs b/OpenRA.FileFormats/Map/Map.cs index 45605f9d3f..8685e7a2e1 100644 --- a/OpenRA.FileFormats/Map/Map.cs +++ b/OpenRA.FileFormats/Map/Map.cs @@ -40,6 +40,7 @@ namespace OpenRA.FileFormats public string Tileset; public Dictionary Actors = new Dictionary(); + public List Smudges = new List(); public Dictionary Waypoints = new Dictionary(); public Dictionary Rules = new Dictionary(); @@ -86,14 +87,21 @@ namespace OpenRA.FileFormats // TODO: Players // Actors - foreach (var kv in yaml["Actors"].Nodes.ToPairs()) + foreach (var kv in yaml["Actors"].Nodes) { - string[] vals = kv.Second.Split(' '); - string[] loc = vals[2].Split(','); - var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]),int.Parse(loc[1])) ,vals[1]); - Actors.Add(kv.First,a); + string[] vals = kv.Value.Value.Split(' '); + string[] loc = vals[1].Split(','); + var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]),int.Parse(loc[1])) ,vals[2]); + Actors.Add(kv.Key,a); } + // Smudges + foreach (var kv in yaml["Smudges"].Nodes) + { + string[] vals = kv.Key.Split(' '); + string[] loc = vals[2].Split(','); + Smudges.Add(new SmudgeReference(vals[0], new int2(int.Parse(loc[0]),int.Parse(loc[1])) ,int.Parse(vals[1]))); + } // Rules Rules = yaml["Rules"].Nodes; @@ -120,7 +128,7 @@ namespace OpenRA.FileFormats } root.Add("Actors",MiniYaml.FromDictionary(Actors)); root.Add("Waypoints",MiniYaml.FromDictionary(Waypoints)); - + root.Add("Smudges",MiniYaml.FromList(Smudges)); // TODO: Players root.Add("Rules",new MiniYaml(null,Rules)); SaveBinaryData(Path.Combine(filepath,"map.bin")); @@ -229,6 +237,11 @@ namespace OpenRA.FileFormats Console.WriteLine("Loaded Actors:"); foreach (var wp in Actors) Console.WriteLine("\t{0} => {1} {2} {3}",wp.Key,wp.Value.Name, wp.Value.Owner,wp.Value.Location); + + Console.WriteLine("Loaded Smudges:"); + foreach (var s in Smudges) + Console.WriteLine("\t{0} {1} {2}",s.Type,s.Location,s.Depth); + } } } diff --git a/OpenRA.FileFormats/Map/SmudgeReference.cs b/OpenRA.FileFormats/Map/SmudgeReference.cs new file mode 100644 index 0000000000..d4534d14bc --- /dev/null +++ b/OpenRA.FileFormats/Map/SmudgeReference.cs @@ -0,0 +1,41 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA 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. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion + +namespace OpenRA.FileFormats +{ + public struct SmudgeReference + { + public readonly string Type; + public readonly int2 Location; + public readonly int Depth; + public SmudgeReference( string type, int2 location, int depth ) + { + Type = type; + Location = location; + Depth = depth; + } + + public override string ToString () + { + return string.Format("{0} {1},{2} {3}", Type, Location.X,Location.Y, Depth); + } + + } +} diff --git a/OpenRA.FileFormats/MiniYaml.cs b/OpenRA.FileFormats/MiniYaml.cs index 235097b02c..3200c32f71 100755 --- a/OpenRA.FileFormats/MiniYaml.cs +++ b/OpenRA.FileFormats/MiniYaml.cs @@ -45,6 +45,12 @@ namespace OpenRA.FileFormats return new MiniYaml( null, dict.ToDictionary( x=>x.Key.ToString(), x=>new MiniYaml(x.Value.ToString()))); } + public static MiniYaml FromList(Listlist) + { + var d = new Dictionary(); + return new MiniYaml( null, list.ToDictionary( x=>x.ToString(), x=>new MiniYaml(null))); + } + static Dictionary FromLines(string[] lines) { var levels = new List>(); @@ -186,13 +192,5 @@ namespace OpenRA.FileFormats yield return ""; } } - - public static IEnumerable< Pair >ToPairs(this MiniYamlNodes y) - { - foreach (var kv in y) - { - yield return Pair.New(kv.Key,kv.Value.Value); - } - } } } diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index 22726b9a1d..62cba73380 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -1,4 +1,4 @@ - + Debug @@ -46,7 +46,7 @@ - + False ..\thirdparty\Tao\Tao.Sdl.dll @@ -102,6 +102,7 @@ +