Convert and store smudges in map
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace OpenRA.FileFormats
|
||||
public string Tileset;
|
||||
|
||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||
public List<SmudgeReference> Smudges = new List<SmudgeReference>();
|
||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||
|
||||
@@ -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<string,ActorReference>(Actors));
|
||||
root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints));
|
||||
|
||||
root.Add("Smudges",MiniYaml.FromList<SmudgeReference>(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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
OpenRA.FileFormats/Map/SmudgeReference.cs
Normal file
41
OpenRA.FileFormats/Map/SmudgeReference.cs
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<T>(List<T>list)
|
||||
{
|
||||
var d = new Dictionary<string, MiniYaml>();
|
||||
return new MiniYaml( null, list.ToDictionary( x=>x.ToString(), x=>new MiniYaml(null)));
|
||||
}
|
||||
|
||||
static Dictionary<string, MiniYaml> FromLines(string[] lines)
|
||||
{
|
||||
var levels = new List<Dictionary<string, MiniYaml>>();
|
||||
@@ -186,13 +192,5 @@ namespace OpenRA.FileFormats
|
||||
yield return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable< Pair<string,string> >ToPairs(this MiniYamlNodes y)
|
||||
{
|
||||
foreach (var kv in y)
|
||||
{
|
||||
yield return Pair.New(kv.Key,kv.Value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -46,7 +46,7 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e, processorArchitecture=MSIL">
|
||||
<Reference Include="Tao.Sdl, Version=1.2.13.0, Culture=neutral, PublicKeyToken=9c7a200e36c0094e">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\thirdparty\Tao\Tao.Sdl.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -102,6 +102,7 @@
|
||||
<Compile Include="Graphics\ShpReader.cs" />
|
||||
<Compile Include="Primitives\int2.cs" />
|
||||
<Compile Include="Map\MapStub.cs" />
|
||||
<Compile Include="Map\SmudgeReference.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
Reference in New Issue
Block a user