Map converter saves to package

This commit is contained in:
Paul Chote
2010-04-03 21:50:03 +13:00
committed by Bob
parent 70dad96ad6
commit b135a059ee
7 changed files with 141 additions and 45 deletions

View File

@@ -7,21 +7,7 @@ namespace MapConverter
{ {
public static void Main (string[] args) public static void Main (string[] args)
{ {
if (args.Length != 3) new MapConverter(args);
{
Console.WriteLine("usage: MapConverter mod[,mod]* input-map.ini output-map.yaml");
return;
}
var mods = args[0].Split(',');
var manifest = new Manifest(mods);
foreach (var folder in manifest.Folders) FileSystem.Mount(folder);
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg);
var converter = new MapConverter(args[1]);
converter.Map.DebugContents();
converter.Save(args[2]);
} }
} }
} }

View File

@@ -23,6 +23,8 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using OpenRA; using OpenRA;
using OpenRA.FileFormats; using OpenRA.FileFormats;
@@ -40,7 +42,7 @@ namespace MapConverter
"fpls", "wcrate", "scrate", "barb", "sbag", "fpls", "wcrate", "scrate", "barb", "sbag",
}; };
Dictionary< string, Pair<byte,byte> > overlayResourceMapping = new Dictionary<string, Pair<byte, byte>>() static Dictionary< string, Pair<byte,byte> > overlayResourceMapping = new Dictionary<string, Pair<byte, byte>>()
{ {
// RA Gems, Gold // RA Gems, Gold
{ "gold01", new Pair<byte,byte>(1,0) }, { "gold01", new Pair<byte,byte>(1,0) },
@@ -68,7 +70,7 @@ namespace MapConverter
{ "ti12", new Pair<byte,byte>(1,11) }, { "ti12", new Pair<byte,byte>(1,11) },
}; };
Dictionary<string, string> overlayActorMapping = new Dictionary<string,string>() { static Dictionary<string, string> overlayActorMapping = new Dictionary<string,string>() {
// Fences // Fences
{"sbag","sbag"}, {"sbag","sbag"},
{"cycl","cycl"}, {"cycl","cycl"},
@@ -92,11 +94,44 @@ namespace MapConverter
int MapSize; int MapSize;
int ActorCount = 0; int ActorCount = 0;
public Map Map = new Map(); Map Map = new Map();
Manifest manifest;
public MapConverter(string filename) public MapConverter(string[] args)
{ {
IniFile file = new IniFile(FileSystem.Open(filename)); if (args.Length != 3)
{
Console.WriteLine("usage: MapConverter mod[,mod]* input-map.ini output-map.yaml");
return;
}
var mods = args[0].Split(',');
manifest = new Manifest(mods);
foreach (var folder in manifest.Folders) FileSystem.Mount(folder);
foreach (var pkg in manifest.Packages) FileSystem.Mount(pkg);
ConvertIniMap(args[1]);
Map.DebugContents();
Save(args[2]);
}
static Dictionary<Pair<string,string>,Pair<string,string> > fileMapping = new Dictionary<Pair<string,string>,Pair<string,string> >()
{
{Pair.New("ra","TEMPERAT"),Pair.New("tem","temperat.col")},
{Pair.New("ra","SNOW"),Pair.New("sno","snow.col")},
{Pair.New("ra","INTERIOR"),Pair.New("int","temperat.col")},
{Pair.New("cnc","DESERT"),Pair.New("des","desert.col")},
{Pair.New("cnc","TEMPERAT"),Pair.New("tem","temperat.col")},
{Pair.New("cnc","WINTER"),Pair.New("win","winter.col")},
};
TerrainColorSet terrainTypeColors;
TileSet tileset;
public void ConvertIniMap(string iniFile)
{
IniFile file = new IniFile(FileSystem.Open(iniFile));
IniSection basic = file.GetSection("Basic"); IniSection basic = file.GetSection("Basic");
IniSection map = file.GetSection("Map"); IniSection map = file.GetSection("Map");
var INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0")); var INIFormat = int.Parse(basic.GetValue("NewINIFormat", "0"));
@@ -119,12 +154,16 @@ namespace MapConverter
UnpackRATileData(ReadPackedSection(file.GetSection("MapPack"))); UnpackRATileData(ReadPackedSection(file.GetSection("MapPack")));
UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack"))); UnpackRAOverlayData(ReadPackedSection(file.GetSection("OverlayPack")));
ReadRATrees(file); ReadRATrees(file);
terrainTypeColors = new TerrainColorSet(fileMapping[Pair.New("ra",Map.Tileset)].Second);
tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("ra",Map.Tileset)].First);
} }
else // CNC else // CNC
{ {
UnpackCncTileData(FileSystem.Open(filename.Substring(0,filename.Length-4)+".bin")); UnpackCncTileData(FileSystem.Open(iniFile.Substring(0,iniFile.Length-4)+".bin"));
ReadCncOverlay(file); ReadCncOverlay(file);
ReadCncTrees(file); ReadCncTrees(file);
terrainTypeColors = new TerrainColorSet(fileMapping[Pair.New("cnc",Map.Tileset)].Second);
tileset = new TileSet("tileSet.til","templates.ini",fileMapping[Pair.New("cnc",Map.Tileset)].First);
} }
LoadActors(file, "STRUCTURES"); LoadActors(file, "STRUCTURES");
@@ -324,8 +363,29 @@ namespace MapConverter
return s.Length <= maxLength ? s : s.Substring(0,maxLength ); return s.Length <= maxLength ? s : s.Substring(0,maxLength );
} }
public void SavePreviewImage(string filepath)
{
var xs = Map.TopLeft.X;
var ys = Map.TopLeft.Y;
var bitmap = new Bitmap(Map.Width, Map.Height);
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(tileset.GetTerrainType(Map.MapTiles[x+xs, y+ys])));
for (var x = 0; x < Map.Width; x++)
for (var y = 0; y < Map.Height; y++)
if (Map.MapResources[x+xs, y+ys].type > 0)
bitmap.SetPixel(x, y, terrainTypeColors.ColorForTerrainType(TerrainType.Ore));
bitmap.Save(filepath,ImageFormat.Png);
}
public void Save(string filepath) public void Save(string filepath)
{ {
Directory.CreateDirectory(filepath);
SavePreviewImage(Path.Combine(filepath,"preview.png"));
Map.UpdateUid();
Map.Save(filepath); Map.Save(filepath);
} }
} }

View File

@@ -101,6 +101,13 @@ namespace OpenRA.FileFormats
LoadBinaryData(); LoadBinaryData();
} }
public void UpdateUid()
{
// TODO: Do this properly.
// Use a hash of the important data
Random foo = new Random();
Uid = foo.Next().ToString();
}
public void Save(string filepath) public void Save(string filepath)
{ {
@@ -116,10 +123,9 @@ namespace OpenRA.FileFormats
root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints)); root.Add("Waypoints",MiniYaml.FromDictionary<string,int2>(Waypoints));
// TODO: Players // TODO: Players
root.Add("Rules",new MiniYaml(null,Rules)); root.Add("Rules",new MiniYaml(null,Rules));
SaveBinaryData(filepath+"map.bin"); SaveBinaryData(Path.Combine(filepath,"map.bin"));
root.WriteToFile(filepath+"map.yaml"); root.WriteToFile(Path.Combine(filepath,"map.yaml"));
} }
static byte ReadByte( Stream s ) static byte ReadByte( Stream s )

View File

@@ -320,9 +320,8 @@ namespace OpenRA
int maxListItems = ((r.Bottom - 60 - y ) / 20); int maxListItems = ((r.Bottom - 60 - y ) / 20);
//for(int i = mapOffset; i < Math.Min(maxListItems + mapOffset, Game.AvailableMaps.Count()); i++, y += 20) // Don't bother showing a subset of the data
// This will be fixed properly when we move the map list to widgets
// TODO: Show the appropriate subset of data
foreach (var kv in Game.AvailableMaps) foreach (var kv in Game.AvailableMaps)
{ {
var map = kv.Value; var map = kv.Value;
@@ -352,21 +351,6 @@ namespace OpenRA
DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount), DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount),
new int2(mapRect.Left + mapRect.Width / 2, y), Color.White); new int2(mapRect.Left + mapRect.Width / 2, y), Color.White);
/*
y += 30;
AddUiButton(new int2(mapRect.Left + mapRect.Width / 2, y), "^",
_ =>
{
mapOffset = (mapOffset - 1 < 0) ? 0 : mapOffset - 1;
});
y += 30;
AddUiButton(new int2(mapRect.Left + mapRect.Width / 2, y), "\\/",
_ =>
{
mapOffset = (mapOffset + 1 > mapList.Value.Count() - maxListItems) ? mapOffset : mapOffset + 1;
});
*/
AddButton(r, _ => { }); AddButton(r, _ => { });
} }
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); } bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }

Binary file not shown.

View File

@@ -0,0 +1,60 @@
Uid: 305604695
MapFormat: 1
Title: Sand Trap
Author: Westwood Studios
PlayerCount: 8
Tileset: DESERT
MapSize: 64,64
TopLeft: 3,3
BottomRight: 60,61
Actors:
Actor0: split3 Neutral 21,55
Actor1: split3 Neutral 19,19
Actor2: split3 Neutral 8,4
Actor3: t18 Neutral 3,31
Actor4: t18 Neutral 22,34
Actor5: t18 Neutral 26,37
Actor6: t08 Neutral 4,37
Actor7: t08 Neutral 7,38
Actor8: t08 Neutral 5,37
Actor9: rock1 Neutral 29,14
Actor10: rock1 Neutral 3,5
Actor11: rock6 Neutral 44,5
Actor12: t08 Neutral 53,42
Actor13: t08 Neutral 54,17
Actor14: t08 Neutral 53,55
Actor15: t08 Neutral 37,32
Actor16: t08 Neutral 39,33
Actor17: t08 Neutral 38,32
Actor18: t08 Neutral 46,31
Actor19: rock1 Neutral 3,12
Actor20: rock1 Neutral 38,30
Actor21: t08 Neutral 27,35
Actor22: split3 Neutral 7,43
Actor23: split3 Neutral 19,39
Actor24: split3 Neutral 44,53
Actor25: split3 Neutral 44,13
Actor26: split3 Neutral 41,33
Actor27: split3 Neutral 41,3
Waypoints:
spawn7: 20,5
spawn6: 56,5
spawn5: 52,35
spawn4: 6,52
spawn3: 25,58
spawn2: 48,58
spawn1: 33,16
spawn0: 6,16
Rules:

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B