Skip to content

Commit

Permalink
map renderer fixes (#29523)
Browse files Browse the repository at this point in the history
* map renderer fixes

* remove useless casts
  • Loading branch information
EmoGarbage404 authored Jun 28, 2024
1 parent bc17033 commit c7fcbe8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Content.MapRenderer/Painters/DecalPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ private void Run(Image canvas, DecalData data)

image.Mutate(o => o.Rotate((float) -decal.Angle.Degrees));
var coloredImage = new Image<Rgba32>(image.Width, image.Height);
Color color = decal.Color?.ConvertImgSharp() ?? Color.White;
Color color = decal.Color?.WithAlpha(byte.MaxValue).ConvertImgSharp() ?? Color.White; // remove the encoded color alpha here
var alpha = decal.Color?.A ?? 1; // get the alpha separately so we can use it in DrawImage
coloredImage.Mutate(o => o.BackgroundColor(color));

image.Mutate(o => o
Expand All @@ -95,6 +96,6 @@ private void Run(Image canvas, DecalData data)

// Very unsure why the - 1 is needed in the first place but all decals are off by exactly one pixel otherwise
// Woohoo!
canvas.Mutate(o => o.DrawImage(image, new Point((int) data.X, (int) data.Y - 1), 1.0f));
canvas.Mutate(o => o.DrawImage(image, new Point((int) data.X, (int) data.Y - 1), alpha));
}
}
15 changes: 12 additions & 3 deletions Content.MapRenderer/Painters/EntityPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,28 @@ public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSyst

image.Mutate(o => o.Crop(rect));

var spriteRotation = 0f;
if (!entity.Sprite.NoRotation && !entity.Sprite.SnapCardinals && entity.Sprite.GetLayerDirectionCount(layer) == 1)
{
spriteRotation = (float) worldRotation.Degrees;
}

var colorMix = entity.Sprite.Color * layer.Color;
var imageColor = Color.FromRgba(colorMix.RByte, colorMix.GByte, colorMix.BByte, colorMix.AByte);
var coloredImage = new Image<Rgba32>(image.Width, image.Height);
coloredImage.Mutate(o => o.BackgroundColor(imageColor));

var (imgX, imgY) = rsi?.Size ?? (EyeManager.PixelsPerMeter, EyeManager.PixelsPerMeter);
var offsetX = (int) (entity.Sprite.Offset.X * EyeManager.PixelsPerMeter);
var offsetY = (int) (entity.Sprite.Offset.Y * EyeManager.PixelsPerMeter);
image.Mutate(o => o
.DrawImage(coloredImage, PixelColorBlendingMode.Multiply, PixelAlphaCompositionMode.SrcAtop, 1)
.Resize(imgX, imgY)
.Flip(FlipMode.Vertical));
.Flip(FlipMode.Vertical)
.Rotate(spriteRotation));

var pointX = (int) entity.X - imgX / 2 + EyeManager.PixelsPerMeter / 2;
var pointY = (int) entity.Y - imgY / 2 + EyeManager.PixelsPerMeter / 2;
var pointX = (int) entity.X + offsetX - imgX / 2;
var pointY = (int) entity.Y + offsetY - imgY / 2;
canvas.Mutate(o => o.DrawImage(image, new Point(pointX, pointY), 1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Content.MapRenderer/Painters/GridPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private static (float x, float y) TransformLocalPosition(Vector2 position, MapGr
var yOffset = (int) -grid.LocalAABB.Bottom;
var tileSize = grid.TileSize;

var x = ((float) Math.Floor(position.X) + xOffset) * tileSize * TilePainter.TileImageSize;
var y = ((float) Math.Floor(position.Y) + yOffset) * tileSize * TilePainter.TileImageSize;
var x = (position.X + xOffset) * tileSize * TilePainter.TileImageSize;
var y = (position.Y + yOffset) * tileSize * TilePainter.TileImageSize;

return (x, y);
}
Expand Down

0 comments on commit c7fcbe8

Please sign in to comment.