Reorganise FileFormats

This commit is contained in:
Paul Chote
2010-04-01 14:25:08 +13:00
committed by Bob
parent 5a95c8a071
commit 8a64209d89
27 changed files with 124 additions and 28 deletions

View File

@@ -1 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BA2B4C61-D5EE-4C3E-9BA1-EB32C531FA36}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MapConverter</RootNamespace>
<AssemblyName>MapConverter</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="IniMap.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
<Name>OpenRA.FileFormats</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -29,7 +29,7 @@ namespace OpenRA.FileFormats
public class NewMap
{
// General info
public int MapFormat;
public byte MapFormat = 1;
public string Title;
public string Description;
public string Author;
@@ -38,6 +38,7 @@ namespace OpenRA.FileFormats
// 'Simple' map data
public string Tiledata;
public byte TileFormat = 1;
public string Tileset;
public int2 Size;
public int[] Bounds;
@@ -85,6 +86,54 @@ namespace OpenRA.FileFormats
Rules = yaml["Rules"].Nodes;
}
public void SaveBinaryData(string filepath)
{
FileStream dataStream = new FileStream(filepath+".tmp", FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter( dataStream );
writer.BaseStream.Seek(0, SeekOrigin.Begin);
// File header consists of a version byte, followed by 2 ushorts for width and height
writer.Write(TileFormat);
writer.Write((ushort)Size.X);
writer.Write((ushort)Size.Y);
// Tile data is stored as a base-64 encoded stream of
// {(2-byte) tile index, (1-byte) image index} pairs
for( int i = 0 ; i < Size.X ; i++ )
for( int j = 0 ; j < Size.Y ; j++ )
{
writer.Write( MapTiles[j,i].tile );
// Semi-hack: Convert clear and water tiles to "pick an image for me" magic number
byte image = (MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff) ? byte.MaxValue : MapTiles[j,i].image;
writer.Write(image);
}
// TODO: Need a proper resources array to write
/*
// Resource data is stored as a base-64 encoded stream of
// {(1-byte) resource index, (1-byte) image index} pairs
for( int i = 0 ; i < Size.X ; i++ )
for( int j = 0 ; j < Size.Y ; j++ )
{
byte type = 0;
byte image = 0;
if (MapTiles[j,i].overlay != null)
{
var res = resourceMapping[MapTiles[j,i].overlay];
type = res.First;
image = res.Second;
}
writer.Write(type);
writer.Write(image);
}
*/
writer.Flush();
}
public void DebugContents()
{
foreach (var field in SimpleFields)

View File

@@ -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>
@@ -52,56 +52,56 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AudLoader.cs" />
<Compile Include="Blowfish.cs" />
<Compile Include="BlowfishKeyProvider.cs" />
<Compile Include="Cache.cs" />
<Compile Include="Collections\Set.cs" />
<Compile Include="ConnectedComponents.cs" />
<Compile Include="DisposableAction.cs" />
<Compile Include="Dune2ShpReader.cs" />
<Compile Include="Evaluator.cs" />
<Compile Include="Exts.cs" />
<Compile Include="FieldLoader.cs" />
<Compile Include="FileSystem.cs" />
<Compile Include="float2.cs" />
<Compile Include="Folder.cs" />
<Compile Include="Format2.cs" />
<Compile Include="Format40.cs" />
<Compile Include="Format80.cs" />
<Compile Include="Graphics\IGraphicsDevice.cs" />
<Compile Include="Graphics\Vertex.cs" />
<Compile Include="IniFile.cs" />
<Compile Include="int2.cs" />
<Compile Include="IPaletteRemap.cs" />
<Compile Include="Lazy.cs" />
<Compile Include="Map.cs" />
<Compile Include="MiniYaml.cs" />
<Compile Include="PackageEntry.cs" />
<Compile Include="Package.cs" />
<Compile Include="Pair.cs" />
<Compile Include="Palette.cs" />
<Compile Include="PlayerColorRemap.cs" />
<Compile Include="PriorityQueue.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtocolVersion.cs" />
<Compile Include="Thirdparty\Random.cs" />
<Compile Include="Session.cs" />
<Compile Include="ShpReader.cs" />
<Compile Include="ShroudPaletteRemap.cs" />
<Compile Include="SingleColorRemap.cs" />
<Compile Include="Support\Log.cs" />
<Compile Include="Support\Stopwatch.cs" />
<Compile Include="Support\Timer.cs" />
<Compile Include="Terrain.cs" />
<Compile Include="TileReference.cs" />
<Compile Include="TileSet.cs" />
<Compile Include="Tuple.cs" />
<Compile Include="TypeDictionary.cs" />
<Compile Include="Walkability.cs" />
<Compile Include="ActorReference.cs" />
<Compile Include="TerrainColorSet.cs" />
<Compile Include="NewMap.cs" />
<Compile Include="Map\ActorReference.cs" />
<Compile Include="Map\Map.cs" />
<Compile Include="Map\NewMap.cs" />
<Compile Include="Map\TileReference.cs" />
<Compile Include="Map\Walkability.cs" />
<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" />
<Compile Include="Map\TileSet.cs" />
<Compile Include="Primitives\PriorityQueue.cs" />
<Compile Include="Primitives\Lazy.cs" />
<Compile Include="FileFormats\AudLoader.cs" />
<Compile Include="FileFormats\Blowfish.cs" />
<Compile Include="FileFormats\BlowfishKeyProvider.cs" />
<Compile Include="Primitives\Set.cs" />
<Compile Include="Graphics\Dune2ShpReader.cs" />
<Compile Include="FileFormats\Format2.cs" />
<Compile Include="FileFormats\Format40.cs" />
<Compile Include="FileFormats\Format80.cs" />
<Compile Include="FileFormats\IniFile.cs" />
<Compile Include="Graphics\ShpReader.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.