Skip to content

Commit

Permalink
Fix warnings in MapRenderer module (#17865)
Browse files Browse the repository at this point in the history
  • Loading branch information
TemporalOroboros authored Aug 8, 2023
1 parent 75b349a commit 7cdc7ab
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Content.MapRenderer/CommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ This option tells the map renderer that you supplied a list of map file names in
}
}

public class CommandLineArgumentException : Exception
public sealed class CommandLineArgumentException : Exception
{
public CommandLineArgumentException(string? message) : base(message)
{
Expand Down
8 changes: 4 additions & 4 deletions Content.MapRenderer/Painters/EntityPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSyst
return (targetX * rsi.Size.X, targetY * rsi.Size.Y, rsi.Size.X, rsi.Size.Y);
}

var dir = entity.Sprite.GetLayerDirectionCount(layer) switch
var dir = entity.Sprite.GetLayerDirectionCount(layer) switch
{
0 => 0,
_ => (int)layer.EffectiveDirection(worldRotation)
_ => (int) layer.EffectiveDirection(worldRotation)
};

var (x, y, width, height) = GetRsiFrame(rsi, image, entity, layer, dir);
Expand All @@ -133,8 +133,8 @@ public void Run(Image canvas, EntityData entity, SharedTransformSystem xformSyst
.Resize(imgX, imgY)
.Flip(FlipMode.Vertical));

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 - imgX / 2 + EyeManager.PixelsPerMeter / 2;
var pointY = (int) entity.Y - imgY / 2 + EyeManager.PixelsPerMeter / 2;
canvas.Mutate(o => o.DrawImage(image, new Point(pointX, pointY), 1));
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.MapRenderer/Painters/GridPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private Dictionary<EntityUid, List<DecalData>> GetDecals()
return decals;
}

private (float x, float y) TransformLocalPosition(Vector2 position, MapGridComponent grid)
private static (float x, float y) TransformLocalPosition(Vector2 position, MapGridComponent grid)
{
var xOffset = (int) -grid.LocalAABB.Left;
var yOffset = (int) -grid.LocalAABB.Bottom;
Expand Down
26 changes: 13 additions & 13 deletions Content.MapRenderer/Painters/MapPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Content.MapRenderer.Painters
{
public sealed class MapPainter
{
public async IAsyncEnumerable<RenderedGridImage<Rgba32>> Paint(string map)
public static async IAsyncEnumerable<RenderedGridImage<Rgba32>> Paint(string map)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
Expand Down Expand Up @@ -78,29 +78,29 @@ await server.WaitPost(() =>
var mapId = sMapManager.GetAllMapIds().Last();
grids = sMapManager.GetAllMapGrids(mapId).Select(o => (o.Owner, o)).ToArray();

foreach (var grid in grids)
foreach (var (uid, _) in grids)
{
var gridXform = xformQuery.GetComponent(grid.Uid);
var gridXform = xformQuery.GetComponent(uid);
xformSystem.SetWorldRotation(gridXform, Angle.Zero);
}
});

await PoolManager.RunTicksSync(pairTracker.Pair, 10);
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());

foreach (var grid in grids)
foreach (var (uid, grid) in grids)
{
// Skip empty grids
if (grid.Grid.LocalAABB.IsEmpty())
if (grid.LocalAABB.IsEmpty())
{
Console.WriteLine($"Warning: Grid {grid.Uid} was empty. Skipping image rendering.");
Console.WriteLine($"Warning: Grid {uid} was empty. Skipping image rendering.");
continue;
}

var tileXSize = grid.Grid.TileSize * TilePainter.TileImageSize;
var tileYSize = grid.Grid.TileSize * TilePainter.TileImageSize;
var tileXSize = grid.TileSize * TilePainter.TileImageSize;
var tileYSize = grid.TileSize * TilePainter.TileImageSize;

var bounds = grid.Grid.LocalAABB;
var bounds = grid.LocalAABB;

var left = bounds.Left;
var right = bounds.Right;
Expand All @@ -114,16 +114,16 @@ await server.WaitPost(() =>

await server.WaitPost(() =>
{
tilePainter.Run(gridCanvas, grid.Uid, grid.Grid);
entityPainter.Run(gridCanvas, grid.Uid, grid.Grid);
tilePainter.Run(gridCanvas, uid, grid);
entityPainter.Run(gridCanvas, uid, grid);

gridCanvas.Mutate(e => e.Flip(FlipMode.Vertical));
});

var renderedImage = new RenderedGridImage<Rgba32>(gridCanvas)
{
GridUid = grid.Uid,
Offset = xformSystem.GetWorldPosition(grid.Uid),
GridUid = uid,
Offset = xformSystem.GetWorldPosition(uid),
};

yield return renderedImage;
Expand Down
4 changes: 2 additions & 2 deletions Content.MapRenderer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Content.MapRenderer
{
internal class Program
internal sealed class Program
{
private const string NoMapsChosenMessage = "No maps were chosen";
private static readonly Func<string, string> ChosenMapIdNotIntMessage = id => $"The chosen id is not a valid integer: {id}";
Expand Down Expand Up @@ -166,7 +166,7 @@ private static async Task Run(CommandLineArguments arguments)
Directory.CreateDirectory(directory);

var fileName = Path.GetFileNameWithoutExtension(map);
var savePath = $"{directory}{Path.DirectorySeparatorChar}{fileName}-{i}.{arguments.Format.ToString()}";
var savePath = $"{directory}{Path.DirectorySeparatorChar}{fileName}-{i}.{arguments.Format}";

Console.WriteLine($"Writing grid of size {grid.Width}x{grid.Height} to {savePath}");

Expand Down
2 changes: 1 addition & 1 deletion Content.MapRenderer/RenderedGridImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Content.MapRenderer;

public sealed class RenderedGridImage <T> where T : unmanaged, IPixel<T>
public sealed class RenderedGridImage<T> where T : unmanaged, IPixel<T>
{
public Image<T> Image;
public Vector2 Offset { get; set; } = Vector2.Zero;
Expand Down

0 comments on commit 7cdc7ab

Please sign in to comment.