Add an early TS tileset importer and temperate tileset.

This commit is contained in:
Paul Chote
2014-07-05 01:29:09 +12:00
parent 446d98e625
commit d610c02642
8 changed files with 6741 additions and 21 deletions

View File

@@ -57,6 +57,7 @@
<Compile Include="Render\WithVoxelWalkerBody.cs" /> <Compile Include="Render\WithVoxelWalkerBody.cs" />
<Compile Include="Render\WithVoxelUnloadBody.cs" /> <Compile Include="Render\WithVoxelUnloadBody.cs" />
<Compile Include="SpriteLoaders\TmpTSLoader.cs" /> <Compile Include="SpriteLoaders\TmpTSLoader.cs" />
<Compile Include="UtilityCommands\LegacyTilesetImporter.cs" />
</ItemGroup> </ItemGroup>
<!-- 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.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -0,0 +1,118 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System;
using OpenRA.FileFormats;
using OpenRA.FileSystem;
namespace OpenRA.Mods.TS.UtilityCommands
{
class ImportLegacyTilesetCommand : IUtilityCommand
{
public string Name { get { return "--tileset-import"; } }
[Desc("FILENAME", "Convert a legacy tileset to the OpenRA format.")]
public void Run(ModData modData, string[] args)
{
// HACK: The engine code assumes that Game.modData is set.
Game.modData = modData;
GlobalFileSystem.LoadFromManifest(Game.modData.Manifest);
var file = new IniFile(File.Open(args[1], FileMode.Open));
var templateIndex = 0;
var extension = "tem";
var terrainTypes = new Dictionary<int, string>()
{
{ 1, "Clear" }, // Desert sand(?)
{ 5, "Road" }, // Paved road
{ 6, "Rail" }, // Monorail track
{ 7, "Impassable" }, // Building
{ 9, "Water" }, // Deep water(?)
{ 10, "Water" }, // Shallow water
{ 11, "Road" }, // Paved road (again?)
{ 12, "DirtRoad" }, // Dirt road
{ 13, "Clear" }, // Regular clear terrain
{ 14, "Rough" }, // Rough terrain (cracks etc)
{ 15, "Cliff" }, // Cliffs
};
// Loop over template sets
try
{
for (var tilesetGroupIndex = 0; ; tilesetGroupIndex++)
{
var section = file.GetSection("TileSet{0:D4}".F(tilesetGroupIndex));
var sectionCount = int.Parse(section.GetValue("TilesInSet", "1"));
var sectionFilename = section.GetValue("FileName", "");
var sectionCategory = section.GetValue("SetName", "");
// Loop over templates
for (var i = 1; i <= sectionCount; i++, templateIndex++)
{
var templateFilename = "{0}{1:D2}.{2}".F(sectionFilename, i, extension);
if (!GlobalFileSystem.Exists(templateFilename))
continue;
using (var s = GlobalFileSystem.Open(templateFilename))
{
Console.WriteLine("\tTemplate@{0}:", templateIndex);
Console.WriteLine("\t\tCategory: {0}", sectionCategory);
Console.WriteLine("\t\tId: {0}", templateIndex);
Console.WriteLine("\t\tImage: {0}{1:D2}", sectionFilename, i);
var templateWidth = s.ReadUInt32();
var templateHeight = s.ReadUInt32();
/* var tileWidth = */s.ReadInt32();
/* var tileHeight = */s.ReadInt32();
var offsets = new uint[templateWidth * templateHeight];
for (var j = 0; j < offsets.Length; j++)
offsets[j] = s.ReadUInt32();
Console.WriteLine("\t\tSize: {0}, {1}", templateWidth, templateHeight);
Console.WriteLine("\t\tTiles:");
for (var j = 0; j < offsets.Length; j++)
{
if (offsets[j] == 0)
continue;
s.Position = offsets[j] + 40;
/* var height = */s.ReadUInt8();
var terrainType = s.ReadUInt8();
/* var rampType = */s.ReadUInt8();
/* var height = */s.ReadUInt8();
if (!terrainTypes.ContainsKey(terrainType))
throw new InvalidDataException("Unknown terrain type {0} in {1}".F(terrainType, templateFilename));
Console.WriteLine("\t\t\t{0}: {1}", j, terrainTypes[terrainType]);
// Console.WriteLine("\t\t\t\tHeight: {0}", height);
// Console.WriteLine("\t\t\t\tTerrainType: {0}", terrainType);
// Console.WriteLine("\t\t\t\tRampType: {0}", rampType);
// Console.WriteLine("\t\t\t\tLeftColor: {0},{1},{2}", s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8());
// Console.WriteLine("\t\t\t\tRightColor: {0},{1},{2}", s.ReadUInt8(), s.ReadUInt8(), s.ReadUInt8());
}
}
}
}
}
catch (InvalidOperationException)
{
// GetSection will throw when we run out of sections to import
}
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -10,7 +10,7 @@
Dimensions: 1,1 Dimensions: 1,1
Footprint: x Footprint: x
BuildSounds: place2.aud BuildSounds: place2.aud
TerrainTypes: Clear, Road TerrainTypes: Clear, Road, DirtRoad, Rough
Adjacent: 4 Adjacent: 4
FrozenUnderFog: FrozenUnderFog:
GivesBuildableArea: GivesBuildableArea:
@@ -106,11 +106,12 @@
SharesCell: yes SharesCell: yes
TerrainSpeeds: TerrainSpeeds:
Clear: 90 Clear: 90
Rough: 80
Road: 100 Road: 100
Rail: 80
DirtRoad: 90
Rough: 70
Tiberium: 80 Tiberium: 80
BlueTiberium: 80 BlueTiberium: 80
Beach: 80
SelectionDecorations: SelectionDecorations:
Palette: pips Palette: pips
Selectable: Selectable:
@@ -205,12 +206,13 @@
Mobile: Mobile:
Crushes: crate Crushes: crate
TerrainSpeeds: TerrainSpeeds:
Clear: 80 Clear: 90
Rough: 60
Road: 100 Road: 100
Beach: 60 Rail: 80
Tiberium: 60 DirtRoad: 90
BlueTiberium: 60 Rough: 70
Tiberium: 80
BlueTiberium: 80
ROT: 5 ROT: 5
SelectionDecorations: SelectionDecorations:
Palette: pips Palette: pips
@@ -278,9 +280,10 @@
Crushes: wall, crate Crushes: wall, crate
TerrainSpeeds: TerrainSpeeds:
Clear: 90 Clear: 90
Rough: 70
Road: 100 Road: 100
Beach: 80 Rail: 80
DirtRoad: 90
Rough: 70
Tiberium: 80 Tiberium: 80
BlueTiberium: 80 BlueTiberium: 80
ROT: 5 ROT: 5

View File

@@ -127,9 +127,11 @@ HVR:
Speed: 99 Speed: 99
TerrainSpeeds: TerrainSpeeds:
Clear: 100 Clear: 100
Rough: 100
Road: 100 Road: 100
Beach: 100 Rail: 100
DirtRoad: 100
Rough: 100
Water: 100
Tiberium: 100 Tiberium: 100
BlueTiberium: 100 BlueTiberium: 100
Health: Health:

View File

@@ -107,7 +107,7 @@ World:
ValuePerUnit: 50 ValuePerUnit: 50
Name: Tiberium Name: Tiberium
PipColor: Green PipColor: Green
AllowedTerrainTypes: Clear AllowedTerrainTypes: Clear, Rough, DirtRoad
AllowUnderActors: false AllowUnderActors: false
TerrainType: Tiberium TerrainType: Tiberium
FixedColorPalette@BlueTiberium: FixedColorPalette@BlueTiberium:
@@ -124,7 +124,7 @@ World:
ValuePerUnit: 100 ValuePerUnit: 100
Name: BlueTiberium Name: BlueTiberium
PipColor: Blue PipColor: Blue
AllowedTerrainTypes: Clear AllowedTerrainTypes: Clear, Rough, DirtRoad
AllowUnderActors: false AllowUnderActors: false
TerrainType: BlueTiberium TerrainType: BlueTiberium
PathfinderDebugOverlay: PathfinderDebugOverlay:

File diff suppressed because it is too large Load Diff