Skip to content

Commit 6d6bbf0

Browse files
authored
Add custom palette support for TerrainTypes
1 parent 9b65580 commit 6d6bbf0

4 files changed

Lines changed: 46 additions & 21 deletions

File tree

src/TSMapEditor/Initialization/Initializer.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Initializer(IMap map)
4444
private Dictionary<Type, Action<IMap, AbstractObject, IniFile, IniSection>> objectTypeArtInitializers
4545
= new Dictionary<Type, Action<IMap, AbstractObject, IniFile, IniSection>>()
4646
{
47-
{ typeof(TerrainType), InitTerrainTypeArt },
47+
{ typeof(TerrainType), InitArtConfigGeneric },
4848
{ typeof(SmudgeType), InitSmudgeTypeArt },
4949
{ typeof(BuildingType), InitBuildingArtConfig },
5050
{ typeof(OverlayType), InitArtConfigGeneric },
@@ -224,13 +224,6 @@ private static void InitTerrainType(INIDefineable obj, IniFile rulesIni, IniSect
224224
terrainType.SnowOccupationBits = (TerrainOccupation)section.GetIntValue("SnowOccupationBits", 0);
225225
terrainType.TemperateOccupationBits = (TerrainOccupation)section.GetIntValue("TemperateOccupationBits", 0);
226226
}
227-
228-
private static void InitTerrainTypeArt(IMap map, AbstractObject obj, IniFile artIni, IniSection artSection)
229-
{
230-
var terrainType = (TerrainType)obj;
231-
terrainType.Theater = artSection.GetBooleanValue("Theater", terrainType.Theater);
232-
terrainType.Image = artSection.GetStringValue("Image", terrainType.Image);
233-
}
234227

235228
private static void InitSmudgeType(INIDefineable obj, IniFile rulesIni, IniSection section)
236229
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Rampastring.Tools;
2+
3+
namespace TSMapEditor.Models.ArtConfig
4+
{
5+
public class TerrainArtConfig : IArtConfig
6+
{
7+
/// <summary>
8+
/// Defined in Art.ini. If set to true,
9+
/// the art for this terrain type is theater-specific;
10+
/// if false, the art is a generic .SHP used for every theater.
11+
/// </summary>
12+
public bool Theater { get; set; }
13+
14+
public string Image { get; set; }
15+
public bool Remapable => false;
16+
17+
/// <summary>
18+
/// Palette override for TerrainTypes in Phobos
19+
/// </summary>
20+
public string Palette { get; set; }
21+
22+
public void ReadFromIniSection(IniSection iniSection)
23+
{
24+
Theater = iniSection.GetBooleanValue(nameof(Theater), Theater);
25+
Image = iniSection.GetStringValue(nameof(Image), Image);
26+
Palette = iniSection.GetStringValue(nameof(Palette), Palette);
27+
}
28+
}
29+
}

src/TSMapEditor/Models/TerrainType.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using TSMapEditor.GameMath;
3+
using TSMapEditor.Models.ArtConfig;
34
using TSMapEditor.Models.Enums;
45

56
namespace TSMapEditor.Models
@@ -12,6 +13,8 @@ public TerrainType(string iniName) : base(iniName)
1213

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

16+
public TerrainArtConfig ArtConfig { get; } = new TerrainArtConfig();
17+
1518
public TerrainOccupation TemperateOccupationBits { get; set; }
1619
public TerrainOccupation SnowOccupationBits { get; set; }
1720

@@ -24,15 +27,6 @@ public TerrainType(string iniName) : base(iniName)
2427

2528
public int YDrawFudge { get; set; }
2629

27-
/// <summary>
28-
/// Defined in Art.ini. If set to true,
29-
/// the art for this terrain type is theater-specific;
30-
/// if false, the art is a generic .SHP used for every theater.
31-
/// </summary>
32-
public bool Theater { get; set; }
33-
34-
public string Image { get; set; }
35-
3630
/// <summary>
3731
/// Impassable cell data for automatically placing impassable overlay
3832
/// under terrain objects.

src/TSMapEditor/Rendering/TheaterGraphics.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,19 @@ public void ReadTerrainObjectTextures(List<TerrainType> terrainTypes)
621621
TerrainObjectTextures = new ShapeImage[terrainTypes.Count];
622622
for (int i = 0; i < terrainTypes.Count; i++)
623623
{
624-
string shpFileName = terrainTypes[i].Image != null ? terrainTypes[i].Image : terrainTypes[i].ININame;
624+
var terrainType = terrainTypes[i];
625+
626+
string shpFileName = terrainType.ArtConfig.Image != null ? terrainType.ArtConfig.Image : terrainType.ININame;
625627
string pngFileName = shpFileName + PNG_FILE_EXTENSION;
626628

627-
if (terrainTypes[i].Theater)
629+
if (terrainType.ArtConfig.Theater)
628630
shpFileName += Theater.FileExtension;
629631
else
630632
shpFileName += SHP_FILE_EXTENSION;
631633

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

634-
bool subjectToLighting = !terrainTypes[i].SpawnsTiberium || Constants.TiberiumTreesAffectedByLighting;
636+
bool subjectToLighting = !terrainType.SpawnsTiberium || Constants.TiberiumTreesAffectedByLighting;
635637

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

651653
var shpFile = new ShpFile(shpFileName);
652654
shpFile.ParseFromBuffer(data);
655+
656+
var palette = TheaterPalette;
657+
if (terrainType.SpawnsTiberium)
658+
palette = unitPalette;
659+
else if (!string.IsNullOrEmpty(terrainType.ArtConfig.Palette))
660+
palette = GetPaletteOrDefault(terrainType.ArtConfig.Palette + Theater.FileExtension[1..] + ".pal", palette, true);
661+
653662
TerrainObjectTextures[i] = new ShapeImage(graphicsDevice, shpFile, data,
654-
terrainTypes[i].SpawnsTiberium ? unitPalette : TheaterPalette, subjectToLighting);
663+
palette, subjectToLighting);
655664
}
656665
}
657666

0 commit comments

Comments
 (0)