Add plumbing for mod-defined terrain loaders.
This commit is contained in:
@@ -20,6 +20,17 @@ namespace OpenRA
|
||||
{
|
||||
public interface IGlobalModData { }
|
||||
|
||||
public sealed class TerrainFormat : IGlobalModData
|
||||
{
|
||||
public readonly string Type;
|
||||
public readonly IReadOnlyDictionary<string, MiniYaml> Metadata;
|
||||
public TerrainFormat(MiniYaml yaml)
|
||||
{
|
||||
Type = yaml.Value;
|
||||
Metadata = new ReadOnlyDictionary<string, MiniYaml>(yaml.ToDictionary());
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SpriteSequenceFormat : IGlobalModData
|
||||
{
|
||||
public readonly string Type;
|
||||
|
||||
@@ -19,6 +19,11 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public interface ITerrainLoader
|
||||
{
|
||||
ITerrainInfo ParseTerrain(IReadOnlyFileSystem fileSystem, string path);
|
||||
}
|
||||
|
||||
public interface ITerrainInfo
|
||||
{
|
||||
string Id { get; }
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace OpenRA
|
||||
public readonly IPackageLoader[] PackageLoaders;
|
||||
public readonly ISoundLoader[] SoundLoaders;
|
||||
public readonly ISpriteLoader[] SpriteLoaders;
|
||||
public readonly ITerrainLoader TerrainLoader;
|
||||
public readonly ISpriteSequenceLoader SpriteSequenceLoader;
|
||||
public readonly IModelSequenceLoader ModelSequenceLoader;
|
||||
public readonly IVideoLoader[] VideoLoaders;
|
||||
@@ -75,6 +76,14 @@ namespace OpenRA
|
||||
SpriteLoaders = ObjectCreator.GetLoaders<ISpriteLoader>(Manifest.SpriteFormats, "sprite");
|
||||
VideoLoaders = ObjectCreator.GetLoaders<IVideoLoader>(Manifest.VideoFormats, "video");
|
||||
|
||||
var terrainFormat = Manifest.Get<TerrainFormat>();
|
||||
var terrainLoader = ObjectCreator.FindType(terrainFormat.Type + "Loader");
|
||||
var terrainCtor = terrainLoader?.GetConstructor(new[] { typeof(ModData) });
|
||||
if (terrainLoader == null || !terrainLoader.GetInterfaces().Contains(typeof(ITerrainLoader)) || terrainCtor == null)
|
||||
throw new InvalidOperationException("Unable to find a terrain loader for type '{0}'.".F(terrainFormat.Type));
|
||||
|
||||
TerrainLoader = (ITerrainLoader)terrainCtor.Invoke(new[] { this });
|
||||
|
||||
var sequenceFormat = Manifest.Get<SpriteSequenceFormat>();
|
||||
var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader");
|
||||
var sequenceCtor = sequenceLoader != null ? sequenceLoader.GetConstructor(new[] { typeof(ModData) }) : null;
|
||||
@@ -101,7 +110,7 @@ namespace OpenRA
|
||||
|
||||
foreach (var file in Manifest.TileSets)
|
||||
{
|
||||
var t = new TileSet(DefaultFileSystem, file);
|
||||
var t = TerrainLoader.ParseTerrain(DefaultFileSystem, file);
|
||||
items.Add(t.Id, t);
|
||||
}
|
||||
|
||||
|
||||
26
OpenRA.Mods.Common/Terrain/DefaultTerrain.cs
Normal file
26
OpenRA.Mods.Common/Terrain/DefaultTerrain.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2020 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.Terrain
|
||||
{
|
||||
public class DefaultTerrainLoader : ITerrainLoader
|
||||
{
|
||||
public DefaultTerrainLoader(ModData modData) { }
|
||||
|
||||
public ITerrainInfo ParseTerrain(IReadOnlyFileSystem fileSystem, string path)
|
||||
{
|
||||
return new TileSet(fileSystem, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ SoundFormats:
|
||||
|
||||
SpriteFormats:
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: DefaultSpriteSequence
|
||||
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
@@ -214,6 +214,8 @@ SpriteFormats: ShpTD, TmpTD, ShpTS, TmpRA
|
||||
|
||||
VideoFormats: Vqa
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: ClassicTilesetSpecificSpriteSequence
|
||||
TilesetExtensions:
|
||||
TEMPERAT: .tem
|
||||
|
||||
@@ -196,6 +196,8 @@ SpriteFormats: R8, ShpTD, TmpRA
|
||||
|
||||
VideoFormats: Vqa
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: DefaultSpriteSequence
|
||||
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
@@ -65,6 +65,8 @@ SoundFormats:
|
||||
|
||||
SpriteFormats: PngSheet
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: DefaultSpriteSequence
|
||||
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
@@ -220,6 +220,8 @@ SpriteFormats: ShpD2, ShpTD, TmpRA, TmpTD, ShpTS
|
||||
|
||||
VideoFormats: Vqa
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: ClassicTilesetSpecificSpriteSequence
|
||||
TilesetExtensions:
|
||||
TEMPERAT: .tem
|
||||
|
||||
@@ -249,6 +249,8 @@ SpriteFormats: ShpTS, TmpTS, ShpTD
|
||||
|
||||
VideoFormats: Vqa
|
||||
|
||||
TerrainFormat: DefaultTerrain
|
||||
|
||||
SpriteSequenceFormat: TilesetSpecificSpriteSequence
|
||||
TilesetExtensions:
|
||||
TEMPERATE: .tem
|
||||
|
||||
Reference in New Issue
Block a user