Replace ITileCache with IDumpSheetsTerrainInfo.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
5d8e35088f
commit
44c6747dec
@@ -14,7 +14,9 @@ using System.Collections.Immutable;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.MapGenerator;
|
using OpenRA.Mods.Common.MapGenerator;
|
||||||
|
using OpenRA.Mods.Common.UtilityCommands;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
|
|
||||||
@@ -66,7 +68,7 @@ namespace OpenRA.Mods.Common.Terrain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DefaultTerrain : ITemplatedTerrainInfo, ITerrainInfoNotifyMapCreated
|
public class DefaultTerrain : ITemplatedTerrainInfo, IDumpSheetsTerrainInfo, ITerrainInfoNotifyMapCreated
|
||||||
{
|
{
|
||||||
[FluentReference]
|
[FluentReference]
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
@@ -180,12 +182,24 @@ namespace OpenRA.Mods.Common.Terrain
|
|||||||
IEnumerable<Color> ITerrainInfo.RestrictedPlayerColors { get { return TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); } }
|
IEnumerable<Color> ITerrainInfo.RestrictedPlayerColors { get { return TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color); } }
|
||||||
float ITerrainInfo.MinHeightColorBrightness => MinHeightColorBrightness;
|
float ITerrainInfo.MinHeightColorBrightness => MinHeightColorBrightness;
|
||||||
float ITerrainInfo.MaxHeightColorBrightness => MaxHeightColorBrightness;
|
float ITerrainInfo.MaxHeightColorBrightness => MaxHeightColorBrightness;
|
||||||
|
|
||||||
TerrainTile ITerrainInfo.DefaultTerrainTile => new(Templates.First().Key, 0);
|
TerrainTile ITerrainInfo.DefaultTerrainTile => new(Templates.First().Key, 0);
|
||||||
|
|
||||||
string[] ITemplatedTerrainInfo.EditorTemplateOrder => EditorTemplateOrder;
|
string[] ITemplatedTerrainInfo.EditorTemplateOrder => EditorTemplateOrder;
|
||||||
IReadOnlyDictionary<ushort, TerrainTemplateInfo> ITemplatedTerrainInfo.Templates => Templates;
|
IReadOnlyDictionary<ushort, TerrainTemplateInfo> ITemplatedTerrainInfo.Templates => Templates;
|
||||||
IReadOnlyDictionary<string, IEnumerable<MultiBrushInfo>> ITemplatedTerrainInfo.MultiBrushCollections => MultiBrushCollections;
|
IReadOnlyDictionary<string, IEnumerable<MultiBrushInfo>> ITemplatedTerrainInfo.MultiBrushCollections => MultiBrushCollections;
|
||||||
|
|
||||||
|
void IDumpSheetsTerrainInfo.DumpSheets(string terrainName, ImmutablePalette palette, ref int sheetCount)
|
||||||
|
{
|
||||||
|
var tileCache = new DefaultTileCache(this);
|
||||||
|
var sb = tileCache.GetSheetBuilder(SheetType.Indexed);
|
||||||
|
foreach (var s in sb.AllSheets)
|
||||||
|
DumpSequenceSheetsCommand.CommitSheet(sb, s, terrainName, palette, ref sheetCount);
|
||||||
|
|
||||||
|
foreach (var s in tileCache.GetSheetBuilder(SheetType.BGRA).AllSheets)
|
||||||
|
DumpSequenceSheetsCommand.CommitSheet(null, s, terrainName, palette, ref sheetCount);
|
||||||
|
}
|
||||||
|
|
||||||
void ITerrainInfoNotifyMapCreated.MapCreated(Map map)
|
void ITerrainInfoNotifyMapCreated.MapCreated(Map map)
|
||||||
{
|
{
|
||||||
// Randomize PickAny tile variants.
|
// Randomize PickAny tile variants.
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Terrain
|
|||||||
{
|
{
|
||||||
public record TheaterTemplate(Sprite[] Sprites, int Stride, int Variants);
|
public record TheaterTemplate(Sprite[] Sprites, int Stride, int Variants);
|
||||||
|
|
||||||
public sealed class DefaultTileCache : ITileCache, IDisposable
|
public sealed class DefaultTileCache : IDisposable
|
||||||
{
|
{
|
||||||
readonly Cache<SheetType, SheetBuilder> sheetBuilders;
|
readonly Cache<SheetType, SheetBuilder> sheetBuilders;
|
||||||
readonly Dictionary<ushort, TheaterTemplate> templates = [];
|
readonly Dictionary<ushort, TheaterTemplate> templates = [];
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright (c) The OpenRA Developers and Contributors
|
|
||||||
* 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.Graphics;
|
|
||||||
|
|
||||||
namespace OpenRA
|
|
||||||
{
|
|
||||||
public interface ITileCache
|
|
||||||
{
|
|
||||||
bool HasTileSprite(TerrainTile r, int? variant = null);
|
|
||||||
Sprite TileSprite(TerrainTile r, int? variant = null);
|
|
||||||
SheetBuilder GetSheetBuilder(SheetType sheetType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||||
public class TerrainRendererInfo : TraitInfo, ITiledTerrainRendererInfo
|
public class TerrainRendererInfo : TraitInfo, ITiledTerrainRendererInfo
|
||||||
{
|
{
|
||||||
bool ITiledTerrainRendererInfo.ValidateTileSprites(ITemplatedTerrainInfo terrainInfo, Action<string> onError, out ITileCache tileCache)
|
bool ITiledTerrainRendererInfo.ValidateTileSprites(ITemplatedTerrainInfo terrainInfo, Action<string> onError)
|
||||||
{
|
{
|
||||||
var missingImages = new HashSet<string>();
|
var missingImages = new HashSet<string>();
|
||||||
var failed = false;
|
var failed = false;
|
||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, OnMissingImage);
|
var tileCache = new DefaultTileCache((DefaultTerrain)terrainInfo, OnMissingImage);
|
||||||
foreach (var t in terrainInfo.Templates)
|
foreach (var t in terrainInfo.Templates)
|
||||||
{
|
{
|
||||||
var templateInfo = (DefaultTerrainTemplateInfo)t.Value;
|
var templateInfo = (DefaultTerrainTemplateInfo)t.Value;
|
||||||
|
|||||||
@@ -783,7 +783,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface ITiledTerrainRendererInfo : ITraitInfoInterface
|
public interface ITiledTerrainRendererInfo : ITraitInfoInterface
|
||||||
{
|
{
|
||||||
bool ValidateTileSprites(ITemplatedTerrainInfo terrainInfo, Action<string> onError, out ITileCache tileCache);
|
bool ValidateTileSprites(ITemplatedTerrainInfo terrainInfo, Action<string> onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
Console.WriteLine("Tileset: " + tileset);
|
Console.WriteLine("Tileset: " + tileset);
|
||||||
if (terrainInfo is ITemplatedTerrainInfo templatedTerrainInfo)
|
if (terrainInfo is ITemplatedTerrainInfo templatedTerrainInfo)
|
||||||
foreach (var ttr in modData.DefaultRules.Actors[SystemActors.World].TraitInfos<ITiledTerrainRendererInfo>())
|
foreach (var ttr in modData.DefaultRules.Actors[SystemActors.World].TraitInfos<ITiledTerrainRendererInfo>())
|
||||||
failed |= ttr.ValidateTileSprites(templatedTerrainInfo, Console.WriteLine, out _);
|
failed |= ttr.ValidateTileSprites(templatedTerrainInfo, Console.WriteLine);
|
||||||
|
|
||||||
var sequences = new SequenceSet(modData.DefaultFileSystem, modData, tileset, null);
|
var sequences = new SequenceSet(modData.DefaultFileSystem, modData, tileset, null);
|
||||||
sequences.SpriteCache.LoadReservations(modData);
|
sequences.SpriteCache.LoadReservations(modData);
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ using System.Collections.Generic;
|
|||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.FileSystem;
|
using OpenRA.FileSystem;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.Common.Terrain;
|
|
||||||
using OpenRA.Mods.Common.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.UtilityCommands
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
{
|
{
|
||||||
|
public interface IDumpSheetsTerrainInfo : ITerrainInfo
|
||||||
|
{
|
||||||
|
void DumpSheets(string terrainName, ImmutablePalette palette, ref int sheetCount);
|
||||||
|
}
|
||||||
|
|
||||||
sealed class DumpSequenceSheetsCommand : IUtilityCommand
|
sealed class DumpSequenceSheetsCommand : IUtilityCommand
|
||||||
{
|
{
|
||||||
static readonly int[] ChannelMasks = [2, 1, 0, 3];
|
static readonly int[] ChannelMasks = [2, 1, 0, 3];
|
||||||
@@ -88,27 +91,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
CommitSheet(null, sheet, sequencesName, palette, ref sheetCount);
|
CommitSheet(null, sheet, sequencesName, palette, ref sheetCount);
|
||||||
|
|
||||||
modData.DefaultTerrainInfo.TryGetValue(sequence.TileSet, out var terrainInfo);
|
modData.DefaultTerrainInfo.TryGetValue(sequence.TileSet, out var terrainInfo);
|
||||||
if (terrainInfo is ITemplatedTerrainInfo templatedTerrainInfo)
|
if (terrainInfo is IDumpSheetsTerrainInfo dsi)
|
||||||
{
|
dsi.DumpSheets(terrainName, palette, ref sheetCount);
|
||||||
foreach (var ttr in modData.DefaultRules.Actors[SystemActors.World].TraitInfos<ITiledTerrainRendererInfo>())
|
|
||||||
{
|
|
||||||
if (!ttr.ValidateTileSprites(templatedTerrainInfo, Console.WriteLine, out var tileCache))
|
|
||||||
{
|
|
||||||
sheetBuilder = tileCache.GetSheetBuilder(SheetType.Indexed);
|
|
||||||
foreach (var sheet in sheetBuilder.AllSheets)
|
|
||||||
CommitSheet(sheetBuilder, sheet, terrainName, palette, ref sheetCount);
|
|
||||||
|
|
||||||
foreach (var sheet in tileCache.GetSheetBuilder(SheetType.BGRA).AllSheets)
|
|
||||||
CommitSheet(null, sheet, terrainName, palette, ref sheetCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sequence.Dispose();
|
sequence.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CommitSheet(SheetBuilder builder, Sheet sheet, string name, ImmutablePalette palette, ref int count)
|
public static void CommitSheet(SheetBuilder builder, Sheet sheet, string name, ImmutablePalette palette, ref int count)
|
||||||
{
|
{
|
||||||
if (builder == null)
|
if (builder == null)
|
||||||
sheet.AsPng().Save($"{count++}.{name}.png", Png.Compression.BEST_SPEED);
|
sheet.AsPng().Save($"{count++}.{name}.png", Png.Compression.BEST_SPEED);
|
||||||
|
|||||||
Reference in New Issue
Block a user