Better map format; First half of a loader for it.
This commit is contained in:
@@ -19,9 +19,11 @@ namespace MapConverter
|
||||
foreach (var folder in manifest.Folders) FileSystem.Mount(folder);
|
||||
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg);
|
||||
|
||||
var map = new NewMap(args[2]);
|
||||
map.DebugContents();
|
||||
|
||||
var map = new IniMap(args[1]);
|
||||
map.Save(args[2]);
|
||||
//var map = new IniMap(args[1]);
|
||||
//map.Save(args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,5 +169,13 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
OpenRA.FileFormats/NewMap.cs
Normal file
102
OpenRA.FileFormats/NewMap.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
#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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public class NewMap
|
||||
{
|
||||
// General info
|
||||
public int MapFormat;
|
||||
public string Title;
|
||||
public string Description;
|
||||
public string Author;
|
||||
public int PlayerCount;
|
||||
public string Preview;
|
||||
|
||||
// 'Simple' map data
|
||||
public string Tiledata;
|
||||
public string Tileset;
|
||||
public int2 Size;
|
||||
public int[] Bounds;
|
||||
|
||||
// 'Complex' map data
|
||||
public TileReference[ , ] MapTiles;
|
||||
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
|
||||
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
|
||||
public Dictionary<string, MiniYaml> Rules = new Dictionary<string, MiniYaml>();
|
||||
|
||||
List<string> SimpleFields = new List<string>() {
|
||||
"MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "Size", "Tiledata", "Preview", "Bounds"
|
||||
};
|
||||
|
||||
public NewMap(string filename)
|
||||
{
|
||||
var yaml = MiniYaml.FromFile(filename);
|
||||
|
||||
// 'Simple' metadata
|
||||
foreach (var field in SimpleFields)
|
||||
{
|
||||
if (!yaml.ContainsKey(field)) continue;
|
||||
FieldLoader.LoadField(this,field,yaml[field].Value);
|
||||
}
|
||||
|
||||
// Waypoints
|
||||
foreach (var wp in yaml["Waypoints"].Nodes)
|
||||
{
|
||||
string[] loc = wp.Value.Value.Split(',');
|
||||
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]),int.Parse(loc[1])));
|
||||
}
|
||||
|
||||
// TODO: Players
|
||||
|
||||
// Actors
|
||||
foreach (var kv in yaml["Actors"].Nodes.ToPairs())
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Rules
|
||||
Rules = yaml["Rules"].Nodes;
|
||||
}
|
||||
|
||||
public void DebugContents()
|
||||
{
|
||||
foreach (var field in SimpleFields)
|
||||
Console.WriteLine("Loaded {0}: {1}", field, this.GetType().GetField(field).GetValue(this));
|
||||
|
||||
Console.WriteLine("Loaded Waypoints:");
|
||||
foreach (var wp in Waypoints)
|
||||
Console.WriteLine("\t{0} => {1}",wp.Key,wp.Value);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -101,6 +101,7 @@
|
||||
<Compile Include="Walkability.cs" />
|
||||
<Compile Include="ActorReference.cs" />
|
||||
<Compile Include="TerrainColorSet.cs" />
|
||||
<Compile Include="NewMap.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.
|
||||
|
||||
46
mods/ra/testmap.yaml
Normal file
46
mods/ra/testmap.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
MapFormat: 1
|
||||
Title: Scripted Multiplayer map
|
||||
Description:
|
||||
Author: Me
|
||||
PlayerCount: 2
|
||||
Tileset: TEMPERAT
|
||||
Size: 100,97
|
||||
TileData: testmap.bin
|
||||
Preview: testmap.png
|
||||
|
||||
Waypoints:
|
||||
spawn0: 36,75
|
||||
spawn1: 92,29
|
||||
|
||||
Players:
|
||||
neutral:
|
||||
Color:Gray
|
||||
Type:Scripted
|
||||
NoSpawn:true
|
||||
ai:
|
||||
Type:BrutalAI
|
||||
Color:Red
|
||||
Country:Russia
|
||||
# AI player starts with a pre-placed base
|
||||
NoSpawn:true
|
||||
player0:
|
||||
player1:
|
||||
|
||||
Actors:
|
||||
tree0: TC05 neutral 93,90
|
||||
tree1: TC04 neutral 92,92
|
||||
tree2: TC01 neutral 88,92
|
||||
tree3: T11 neutral 96,93
|
||||
tree4: T08 neutral 90,94
|
||||
mine0: MINE neutral 67,103
|
||||
|
||||
# <A bunch of pre-placed stuff to give ai player an advantage>
|
||||
pwn01: 4tnk ai 1,1
|
||||
pwn02: 4tnk ai 1,2
|
||||
pwn03: 4tnk ai 1,3
|
||||
# ...
|
||||
|
||||
Rules:
|
||||
Player:
|
||||
ChronoshiftPower:
|
||||
ChargeTime:1
|
||||
Reference in New Issue
Block a user