Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/TSMapEditor/Initialization/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Initializer(IMap map)
private Dictionary<Type, Action<IMap, AbstractObject, IniFile, IniSection>> objectTypeArtInitializers
= new Dictionary<Type, Action<IMap, AbstractObject, IniFile, IniSection>>()
{
{ typeof(TerrainType), InitTerrainTypeArt },
{ typeof(TerrainType), InitArtConfigGeneric },
{ typeof(SmudgeType), InitSmudgeTypeArt },
{ typeof(BuildingType), InitBuildingArtConfig },
{ typeof(OverlayType), InitArtConfigGeneric },
Expand Down Expand Up @@ -224,13 +224,6 @@ private static void InitTerrainType(INIDefineable obj, IniFile rulesIni, IniSect
terrainType.SnowOccupationBits = (TerrainOccupation)section.GetIntValue("SnowOccupationBits", 0);
terrainType.TemperateOccupationBits = (TerrainOccupation)section.GetIntValue("TemperateOccupationBits", 0);
}

private static void InitTerrainTypeArt(IMap map, AbstractObject obj, IniFile artIni, IniSection artSection)
{
var terrainType = (TerrainType)obj;
terrainType.Theater = artSection.GetBooleanValue("Theater", terrainType.Theater);
terrainType.Image = artSection.GetStringValue("Image", terrainType.Image);
}

private static void InitSmudgeType(INIDefineable obj, IniFile rulesIni, IniSection section)
{
Expand Down
29 changes: 29 additions & 0 deletions src/TSMapEditor/Models/ArtConfig/TerrainArtConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Rampastring.Tools;

namespace TSMapEditor.Models.ArtConfig
{
public class TerrainArtConfig : IArtConfig
{
/// <summary>
/// Defined in Art.ini. If set to true,
/// the art for this terrain type is theater-specific;
/// if false, the art is a generic .SHP used for every theater.
/// </summary>
public bool Theater { get; set; }

public string Image { get; set; }
public bool Remapable => false;

/// <summary>
/// Palette override for TerrainTypes in Phobos
/// </summary>
public string Palette { get; set; }

public void ReadFromIniSection(IniSection iniSection)
{
Theater = iniSection.GetBooleanValue(nameof(Theater), Theater);
Image = iniSection.GetStringValue(nameof(Image), Image);
Palette = iniSection.GetStringValue(nameof(Palette), Palette);
}
}
}
15 changes: 5 additions & 10 deletions src/TSMapEditor/Models/TerrainType.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.Collections.Generic;
using TSMapEditor.GameMath;
using TSMapEditor.Models.ArtConfig;
using TSMapEditor.Models.Enums;

namespace TSMapEditor.Models
{
public class TerrainType : GameObjectType
public class TerrainType : GameObjectType, IArtConfigContainer
{
public TerrainType(string iniName) : base(iniName)
{
}

public override RTTIType WhatAmI() => RTTIType.TerrainType;

public TerrainArtConfig ArtConfig { get; } = new TerrainArtConfig();
public IArtConfig GetArtConfig() => ArtConfig;

public TerrainOccupation TemperateOccupationBits { get; set; }
public TerrainOccupation SnowOccupationBits { get; set; }

Expand All @@ -24,15 +28,6 @@ public TerrainType(string iniName) : base(iniName)

public int YDrawFudge { get; set; }

/// <summary>
/// Defined in Art.ini. If set to true,
/// the art for this terrain type is theater-specific;
/// if false, the art is a generic .SHP used for every theater.
/// </summary>
public bool Theater { get; set; }

public string Image { get; set; }

/// <summary>
/// Impassable cell data for automatically placing impassable overlay
/// under terrain objects.
Expand Down
17 changes: 13 additions & 4 deletions src/TSMapEditor/Rendering/TheaterGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,17 +621,19 @@ public void ReadTerrainObjectTextures(List<TerrainType> terrainTypes)
TerrainObjectTextures = new ShapeImage[terrainTypes.Count];
for (int i = 0; i < terrainTypes.Count; i++)
{
string shpFileName = terrainTypes[i].Image != null ? terrainTypes[i].Image : terrainTypes[i].ININame;
var terrainType = terrainTypes[i];

string shpFileName = terrainType.ArtConfig.Image != null ? terrainType.ArtConfig.Image : terrainType.ININame;
string pngFileName = shpFileName + PNG_FILE_EXTENSION;

if (terrainTypes[i].Theater)
if (terrainType.ArtConfig.Theater)
shpFileName += Theater.FileExtension;
else
shpFileName += SHP_FILE_EXTENSION;

byte[] data = fileManager.LoadFile(pngFileName);

bool subjectToLighting = !terrainTypes[i].SpawnsTiberium || Constants.TiberiumTreesAffectedByLighting;
bool subjectToLighting = !terrainType.SpawnsTiberium || Constants.TiberiumTreesAffectedByLighting;

if (data != null)
{
Expand All @@ -650,8 +652,15 @@ public void ReadTerrainObjectTextures(List<TerrainType> terrainTypes)

var shpFile = new ShpFile(shpFileName);
shpFile.ParseFromBuffer(data);

var palette = TheaterPalette;
if (terrainType.SpawnsTiberium)
palette = unitPalette;
else if (!string.IsNullOrEmpty(terrainType.ArtConfig.Palette))
palette = GetPaletteOrDefault(terrainType.ArtConfig.Palette + Theater.FileExtension[1..] + ".pal", palette, true);

TerrainObjectTextures[i] = new ShapeImage(graphicsDevice, shpFile, data,
terrainTypes[i].SpawnsTiberium ? unitPalette : TheaterPalette, subjectToLighting);
palette, subjectToLighting);
}
}

Expand Down
Loading