Add selecting maps to render when running MapRenderer, fix rendering multiple maps (#11783)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
||||||
namespace Content.MapRenderer;
|
namespace Content.MapRenderer;
|
||||||
@@ -45,27 +44,27 @@ public sealed class LayerGroup
|
|||||||
|
|
||||||
public static LayerGroup DefaultParallax()
|
public static LayerGroup DefaultParallax()
|
||||||
{
|
{
|
||||||
return new LayerGroup()
|
return new LayerGroup
|
||||||
{
|
{
|
||||||
Scale = new Position(0.1f, 0.1f),
|
Scale = new Position(0.1f, 0.1f),
|
||||||
Source = new GroupSource()
|
Source = new GroupSource
|
||||||
{
|
{
|
||||||
Url = "https://i.imgur.com/3YO8KRd.png",
|
Url = "https://i.imgur.com/3YO8KRd.png",
|
||||||
Extent = new Extent(6000, 4000)
|
Extent = new Extent(6000, 4000)
|
||||||
},
|
},
|
||||||
Layers = new List<Layer>()
|
Layers = new List<Layer>
|
||||||
{
|
{
|
||||||
new Layer()
|
new()
|
||||||
{
|
{
|
||||||
Url = "https://i.imgur.com/IannmmK.png"
|
Url = "https://i.imgur.com/IannmmK.png"
|
||||||
},
|
},
|
||||||
new Layer()
|
new()
|
||||||
{
|
{
|
||||||
Url = "https://i.imgur.com/T3W6JsE.png",
|
Url = "https://i.imgur.com/T3W6JsE.png",
|
||||||
Composition = "lighter",
|
Composition = "lighter",
|
||||||
ParallaxScale = new Position(0.2f, 0.2f)
|
ParallaxScale = new Position(0.2f, 0.2f)
|
||||||
},
|
},
|
||||||
new Layer()
|
new()
|
||||||
{
|
{
|
||||||
Url = "https://i.imgur.com/T3W6JsE.png",
|
Url = "https://i.imgur.com/T3W6JsE.png",
|
||||||
Composition = "lighter",
|
Composition = "lighter",
|
||||||
|
|||||||
@@ -24,7 +24,12 @@ namespace Content.MapRenderer.Painters
|
|||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings(){ Map = map });
|
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings
|
||||||
|
{
|
||||||
|
Fresh = true,
|
||||||
|
Map = map
|
||||||
|
});
|
||||||
|
|
||||||
var server = pairTracker.Pair.Server;
|
var server = pairTracker.Pair.Server;
|
||||||
var client = pairTracker.Pair.Client;
|
var client = pairTracker.Pair.Client;
|
||||||
|
|
||||||
@@ -64,7 +69,8 @@ namespace Content.MapRenderer.Painters
|
|||||||
sEntityManager.DeleteEntity(playerEntity.Value);
|
sEntityManager.DeleteEntity(playerEntity.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
grids = sMapManager.GetAllMapGrids(new MapId(1)).ToArray();
|
var mapId = sMapManager.GetAllMapIds().Last();
|
||||||
|
grids = sMapManager.GetAllMapGrids(mapId).ToArray();
|
||||||
|
|
||||||
foreach (var grid in grids)
|
foreach (var grid in grids)
|
||||||
{
|
{
|
||||||
@@ -107,9 +113,11 @@ namespace Content.MapRenderer.Painters
|
|||||||
gridCanvas.Mutate(e => e.Flip(FlipMode.Vertical));
|
gridCanvas.Mutate(e => e.Flip(FlipMode.Vertical));
|
||||||
});
|
});
|
||||||
|
|
||||||
var renderedImage = new RenderedGridImage<Rgba32>(gridCanvas);
|
var renderedImage = new RenderedGridImage<Rgba32>(gridCanvas)
|
||||||
renderedImage.GridUid = grid.GridEntityId;
|
{
|
||||||
renderedImage.Offset = grid.WorldPosition;
|
GridUid = grid.GridEntityId,
|
||||||
|
Offset = grid.WorldPosition
|
||||||
|
};
|
||||||
|
|
||||||
yield return renderedImage;
|
yield return renderedImage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Maps;
|
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.ResourceManagement;
|
using Robust.Client.ResourceManagement;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.MapRenderer.Extensions;
|
using Content.IntegrationTests;
|
||||||
using Content.MapRenderer.Painters;
|
using Content.MapRenderer.Painters;
|
||||||
|
using Content.Server.Maps;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Formats.Webp;
|
using SixLabors.ImageSharp.Formats.Webp;
|
||||||
|
|
||||||
@@ -15,8 +17,9 @@ namespace Content.MapRenderer
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
private const string MapsAddedEnvKey = "FILES_ADDED";
|
private const string NoMapsChosenMessage = "No maps were chosen";
|
||||||
private const string MapsModifiedEnvKey = "FILES_MODIFIED";
|
private static readonly Func<string, string> ChosenMapIdNotIntMessage = id => $"The chosen id is not a valid integer: {id}";
|
||||||
|
private static readonly Func<int, string> NoMapFoundWithIdMessage = id => $"No map found with chosen id: {id}";
|
||||||
|
|
||||||
private static readonly MapPainter MapPainter = new();
|
private static readonly MapPainter MapPainter = new();
|
||||||
|
|
||||||
@@ -24,7 +27,73 @@ namespace Content.MapRenderer
|
|||||||
{
|
{
|
||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Didn't specify any maps to paint! Provide map names (as map prototype names).");
|
await using var server = await PoolManager.GetServerClient();
|
||||||
|
var mapIds = server.Pair.Server
|
||||||
|
.ResolveDependency<IPrototypeManager>()
|
||||||
|
.EnumeratePrototypes<GameMapPrototype>()
|
||||||
|
.Select(map => map.ID)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
Array.Sort(mapIds);
|
||||||
|
|
||||||
|
Console.WriteLine("Didn't specify any maps to paint, select one, multiple separated by commas or \"all\":");
|
||||||
|
Console.WriteLine(string.Join('\n', mapIds.Select((id, i) => $"({i}): {id}")));
|
||||||
|
var input = Console.ReadLine();
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine(NoMapsChosenMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedIds = new List<int>();
|
||||||
|
if (input is "all" or "\"all\"")
|
||||||
|
{
|
||||||
|
selectedIds = Enumerable.Range(0, mapIds.Length).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var inputArray = input.Split(',');
|
||||||
|
if (inputArray.Length == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine(NoMapsChosenMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var idString in inputArray)
|
||||||
|
{
|
||||||
|
if (!int.TryParse(idString.Trim(), out var id))
|
||||||
|
{
|
||||||
|
Console.WriteLine(ChosenMapIdNotIntMessage(idString));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedIds.Add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedMapPrototypes = new List<string>();
|
||||||
|
foreach (var id in selectedIds)
|
||||||
|
{
|
||||||
|
if (id < 0 || id >= mapIds.Length)
|
||||||
|
{
|
||||||
|
Console.WriteLine(NoMapFoundWithIdMessage(id));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedMapPrototypes.Add(mapIds[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var argsLength = args.Length;
|
||||||
|
Array.Resize(ref args, argsLength + selectedMapPrototypes.Count);
|
||||||
|
selectedMapPrototypes.CopyTo(args, argsLength);
|
||||||
|
|
||||||
|
if (selectedMapPrototypes.Count == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine(NoMapsChosenMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Selected maps: {string.Join(", ", selectedMapPrototypes)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CommandLineArguments.TryParse(args, out var arguments))
|
if (!CommandLineArguments.TryParse(args, out var arguments))
|
||||||
@@ -35,7 +104,6 @@ namespace Content.MapRenderer
|
|||||||
|
|
||||||
private static async Task Run(CommandLineArguments arguments)
|
private static async Task Run(CommandLineArguments arguments)
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine($"Creating images for {arguments.Maps.Count} maps");
|
Console.WriteLine($"Creating images for {arguments.Maps.Count} maps");
|
||||||
|
|
||||||
var mapNames = new List<string>();
|
var mapNames = new List<string>();
|
||||||
@@ -43,7 +111,7 @@ namespace Content.MapRenderer
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"Painting map {map}");
|
Console.WriteLine($"Painting map {map}");
|
||||||
|
|
||||||
var mapViewerData = new MapViewerData()
|
var mapViewerData = new MapViewerData
|
||||||
{
|
{
|
||||||
Id = map,
|
Id = map,
|
||||||
Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(map)
|
Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(map)
|
||||||
@@ -53,7 +121,7 @@ namespace Content.MapRenderer
|
|||||||
var directory = Path.Combine(arguments.OutputPath, map);
|
var directory = Path.Combine(arguments.OutputPath, map);
|
||||||
Directory.CreateDirectory(directory);
|
Directory.CreateDirectory(directory);
|
||||||
|
|
||||||
int i = 0;
|
var i = 0;
|
||||||
await foreach (var renderedGrid in MapPainter.Paint(map))
|
await foreach (var renderedGrid in MapPainter.Paint(map))
|
||||||
{
|
{
|
||||||
var grid = renderedGrid.Image;
|
var grid = renderedGrid.Image;
|
||||||
|
|||||||
Reference in New Issue
Block a user