Map saving

This commit is contained in:
Paul Chote
2010-04-01 17:37:46 +13:00
committed by Bob
parent 585f15d4ca
commit 382efbcdfb
7 changed files with 38 additions and 10 deletions

View File

@@ -226,7 +226,7 @@ namespace MapConverter
foreach( KeyValuePair<string, string> kv in terrain )
{
var loc = int.Parse( kv.Key );
Map.Actors.Add("Actor"+a++, new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), null ) );
Map.Actors.Add("Actor"+a++, new ActorReference(kv.Value, new int2(loc % MapSize, loc / MapSize), "Neutral" ) );
}
}
@@ -268,7 +268,7 @@ namespace MapConverter
foreach( KeyValuePair<string, string> kv in terrain )
{
var loc = int.Parse( kv.Key );
Map.Actors.Add("Actor"+a++, new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),null));
Map.Actors.Add("Actor"+a++, new ActorReference( kv.Value.Split(',')[0], new int2(loc % MapSize, loc / MapSize),"Neutral"));
}
}
@@ -279,7 +279,9 @@ namespace MapConverter
{
//num=owner,type,health,location,facing,...
var parts = s.Value.Split( ',' );
var loc = int.Parse(parts[3]);
var loc = int.Parse(parts[3]);
if (parts[0] == "")
parts[0] = "Neutral";
Map.Actors.Add("Actor"+a++, new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
}
}

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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.
@@ -107,7 +107,7 @@ namespace OpenRA.FileFormats
f => new MiniYaml(FormatValue(o, f))));
}
static string FormatValue(object o, FieldInfo f)
public static string FormatValue(object o, FieldInfo f)
{
var v = f.GetValue(o);
return f.FieldType.IsArray

View File

@@ -31,5 +31,11 @@ namespace OpenRA.FileFormats
Location = location;
Owner = owner;
}
public override string ToString ()
{
return string.Format("{0} {1} {2},{3}", Name, Owner, Location.X,Location.Y);
}
}
}

View File

@@ -23,6 +23,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Reflection;
namespace OpenRA.FileFormats
{
@@ -51,7 +52,7 @@ namespace OpenRA.FileFormats
List<string> SimpleFields = new List<string>() {
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "Bounds"
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Tiledata", "Preview", "Size", "Bounds"
};
public NewMap() {}
@@ -94,9 +95,22 @@ namespace OpenRA.FileFormats
public void Save(string filepath)
{
// Do stuff
Dictionary<string, MiniYaml> root = new Dictionary<string, MiniYaml>();
var d = new Dictionary<string, MiniYaml>();
foreach (var field in SimpleFields)
{
FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue;
root.Add(field,new MiniYaml(FieldSaver.FormatValue(this,f),null));
}
root.Add("Actors",MiniYaml.FromDictionary<string,ActorReference>(Actors));
root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints));
// TODO: Players
root.Add("Rules",new MiniYaml(null,Rules));
SaveBinaryData(Tiledata);
root.WriteToFile(filepath);
}
static byte ReadByte( Stream s )
@@ -169,6 +183,7 @@ namespace OpenRA.FileFormats
writer.Flush();
writer.Close();
File.Move(filepath+".tmp",filepath);
}
public void DebugContents()

View File

@@ -39,7 +39,12 @@ namespace OpenRA.FileFormats
Value = value;
Nodes = nodes;
}
public static MiniYaml FromDictionary<K,V>(Dictionary<K,V>dict)
{
return new MiniYaml( null, dict.ToDictionary( x=>x.Key.ToString(), x=>new MiniYaml(x.Value.ToString())));
}
static Dictionary<string, MiniYaml> FromLines(string[] lines)
{
var levels = new List<Dictionary<string, MiniYaml>>();

View File

@@ -85,7 +85,6 @@
<Compile Include="Map\Terrain.cs" />
<Compile Include="Primitives\Cache.cs" />
<Compile Include="Primitives\float2.cs" />
<Compile Include="Properties\int2.cs" />
<Compile Include="Primitives\Pair.cs" />
<Compile Include="Map\TerrainColorSet.cs" />
<Compile Include="Primitives\Tuple.cs" />
@@ -103,6 +102,7 @@
<Compile Include="FileFormats\IniFile.cs" />
<Compile Include="Graphics\ShpReader.cs" />
<Compile Include="Map\NewTileReference.cs" />
<Compile Include="Primitives\int2.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.

View File

@@ -62,6 +62,6 @@ namespace OpenRA
public PointF ToPointF() { return new PointF(X, Y); }
public float2 ToFloat2() { return new float2(X, Y); }
public override string ToString() { return string.Format("({0},{1})", X, Y); }
public override string ToString() { return string.Format("{0},{1}", X, Y); }
}
}