Map saving
This commit is contained in:
@@ -226,7 +226,7 @@ namespace MapConverter
|
|||||||
foreach( KeyValuePair<string, string> kv in terrain )
|
foreach( KeyValuePair<string, string> kv in terrain )
|
||||||
{
|
{
|
||||||
var loc = int.Parse( kv.Key );
|
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 )
|
foreach( KeyValuePair<string, string> kv in terrain )
|
||||||
{
|
{
|
||||||
var loc = int.Parse( kv.Key );
|
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,...
|
//num=owner,type,health,location,facing,...
|
||||||
var parts = s.Value.Split( ',' );
|
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]));
|
Map.Actors.Add("Actor"+a++, new ActorReference( parts[1].ToLowerInvariant(), new int2(loc % MapSize, loc / MapSize), parts[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -107,7 +107,7 @@ namespace OpenRA.FileFormats
|
|||||||
f => new MiniYaml(FormatValue(o, f))));
|
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);
|
var v = f.GetValue(o);
|
||||||
return f.FieldType.IsArray
|
return f.FieldType.IsArray
|
||||||
|
|||||||
@@ -31,5 +31,11 @@ namespace OpenRA.FileFormats
|
|||||||
Location = location;
|
Location = location;
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString ()
|
||||||
|
{
|
||||||
|
return string.Format("{0} {1} {2},{3}", Name, Owner, Location.X,Location.Y);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
@@ -51,7 +52,7 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
|
|
||||||
List<string> SimpleFields = new List<string>() {
|
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() {}
|
public NewMap() {}
|
||||||
@@ -94,9 +95,22 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
public void Save(string filepath)
|
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);
|
SaveBinaryData(Tiledata);
|
||||||
|
root.WriteToFile(filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte ReadByte( Stream s )
|
static byte ReadByte( Stream s )
|
||||||
@@ -169,6 +183,7 @@ namespace OpenRA.FileFormats
|
|||||||
|
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
writer.Close();
|
writer.Close();
|
||||||
|
File.Move(filepath+".tmp",filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DebugContents()
|
public void DebugContents()
|
||||||
|
|||||||
@@ -39,7 +39,12 @@ namespace OpenRA.FileFormats
|
|||||||
Value = value;
|
Value = value;
|
||||||
Nodes = nodes;
|
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)
|
static Dictionary<string, MiniYaml> FromLines(string[] lines)
|
||||||
{
|
{
|
||||||
var levels = new List<Dictionary<string, MiniYaml>>();
|
var levels = new List<Dictionary<string, MiniYaml>>();
|
||||||
|
|||||||
@@ -85,7 +85,6 @@
|
|||||||
<Compile Include="Map\Terrain.cs" />
|
<Compile Include="Map\Terrain.cs" />
|
||||||
<Compile Include="Primitives\Cache.cs" />
|
<Compile Include="Primitives\Cache.cs" />
|
||||||
<Compile Include="Primitives\float2.cs" />
|
<Compile Include="Primitives\float2.cs" />
|
||||||
<Compile Include="Properties\int2.cs" />
|
|
||||||
<Compile Include="Primitives\Pair.cs" />
|
<Compile Include="Primitives\Pair.cs" />
|
||||||
<Compile Include="Map\TerrainColorSet.cs" />
|
<Compile Include="Map\TerrainColorSet.cs" />
|
||||||
<Compile Include="Primitives\Tuple.cs" />
|
<Compile Include="Primitives\Tuple.cs" />
|
||||||
@@ -103,6 +102,7 @@
|
|||||||
<Compile Include="FileFormats\IniFile.cs" />
|
<Compile Include="FileFormats\IniFile.cs" />
|
||||||
<Compile Include="Graphics\ShpReader.cs" />
|
<Compile Include="Graphics\ShpReader.cs" />
|
||||||
<Compile Include="Map\NewTileReference.cs" />
|
<Compile Include="Map\NewTileReference.cs" />
|
||||||
|
<Compile Include="Primitives\int2.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
@@ -62,6 +62,6 @@ namespace OpenRA
|
|||||||
public PointF ToPointF() { return new PointF(X, Y); }
|
public PointF ToPointF() { return new PointF(X, Y); }
|
||||||
public float2 ToFloat2() { return new float2(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); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user