Skip to content

Commit

Permalink
Add support for directional alpha images
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku authored Feb 7, 2025
1 parent a3f570f commit e5c5b1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/TSMapEditor/Rendering/AlphaImageRenderStruct.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using TSMapEditor.GameMath;
using TSMapEditor.Models;

namespace TSMapEditor.Rendering
{
internal struct AlphaImageRenderStruct
{
public Point2D Point;
public ShapeImage AlphaImage;
public GameObject OwnerObject;

public AlphaImageRenderStruct(Point2D point, ShapeImage alphaImage)
public AlphaImageRenderStruct(Point2D point, ShapeImage alphaImage, GameObject ownerObject)
{
Point = point;
AlphaImage = alphaImage;
OwnerObject = ownerObject;
}
}
}
18 changes: 14 additions & 4 deletions src/TSMapEditor/Rendering/MapView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public void DrawTerrainTileAndRegisterObjects(MapTile tile)
AddStructureToRender(structure);

if (structure.ObjectType.AlphaShape != null && IsRenderFlagEnabled(RenderObjectFlags.AlphaLights))
alphaImagesToRender.Add(new AlphaImageRenderStruct(structure.Position, structure.ObjectType.AlphaShape));
alphaImagesToRender.Add(new AlphaImageRenderStruct(structure.Position, structure.ObjectType.AlphaShape, structure));
}
}
}
Expand All @@ -608,7 +608,7 @@ public void DrawTerrainTileAndRegisterObjects(MapTile tile)
AddGameObjectToRender(tile.TerrainObject);

if (tile.TerrainObject.TerrainType.AlphaShape != null && IsRenderFlagEnabled(RenderObjectFlags.AlphaLights))
alphaImagesToRender.Add(new AlphaImageRenderStruct(tile.TerrainObject.Position, tile.TerrainObject.TerrainType.AlphaShape));
alphaImagesToRender.Add(new AlphaImageRenderStruct(tile.TerrainObject.Position, tile.TerrainObject.TerrainType.AlphaShape, tile.TerrainObject));
}
}

Expand Down Expand Up @@ -1625,10 +1625,20 @@ private void DrawWorld()
for (int i = 0; i < alphaImagesToRender.Count; i++)
{
var alphaShape = alphaImagesToRender[i].AlphaImage;
if (alphaShape.GetFrameCount() <= 0)
int frameCount = alphaShape.GetFrameCount();

if (frameCount <= 0)
continue;

var alphaTexture = alphaShape.GetFrame(0);
int frame = 0;

if (frameCount > 1)
{
if (alphaImagesToRender[i].OwnerObject is TechnoBase ownerTechno)
frame = ownerTechno.Facing / ((Constants.FacingMax + 1) / frameCount);
}

var alphaTexture = alphaShape.GetFrame(frame);
if (alphaTexture == null)
continue;

Expand Down

0 comments on commit e5c5b1d

Please sign in to comment.