* Fix MapRenderer integration test usage to properly show output. Added an ITestContextLike interface that can be used to properly run the integration test infrastructure OUTSIDE A TEST. * Use System.Test.Json instead of Newtonsoft.Json for MapRenderer * Fix map renderer JSON output being broken I love not testing or even reading the surrounding code. * Fix un-reusable integration instances getting leaked. The pair state was always getting set to Ready even if the instance was killed, meaning it was getting put back into the pool even if killed. * Mark map renderer integration instances as destructive to avoid memory leak. * Fix file specification handling. Map file specification is now backwards compatible again (loose filename match to search prototypes). It also supports proper direct OS filename arguments. The former is the fallback scenario is extremely important for the map server still. Cleaned up the way that target map files are passed through the application, so mixed file/prototype specifications are now handled properly (which can be caused by the fallback behavior). Fixes JSON data export to use the proper user-facing map name. This only works if a prototype ID is specified *or* the legacy file behavior is used. Restructured MapPainter into an instance that has multiple functions called on it, so not all data has to be passed through a single Paint() call. Clean up the godawful map/grid detection code. Now we just load both in a single call, because yes you can do that. This relies on LogOrphanedGrids = false in the map loader options, which I think is fine for our purposes. Improved error handling in much of the program. * Fix duplicate map names in map renderer output I'm not sure *what* this output is used for, but I'm sure having it duplicated per grid isn't intentional. * Make maprenderer command line parsing bail on unknown - options * Fix incorrect docs for --viewer maprenderer argument It doesn't change directory layout * Fix parallax layer specification to not use imgur as a fucking CDN Files are now copied to a separate folder _parallax, and these files are referenced by the parallax configuration. Parallax data is only output when instructed to via --parallax. This will break parallax on current map server builds, but it should be graceful. Also, that's fucking good considering we shouldn't be using imgur links. Purge it. * Fix incorrect assert in test pair clean return * Restore other map viewer parallax layers, fix attribution. * This isn't a valid copyright statement but the validator forces me to enter something here.
159 lines
4.1 KiB
C#
159 lines
4.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using System.Text.Json.Serialization;
|
|
using Robust.Shared.ContentPack;
|
|
using Robust.Shared.Utility;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
|
namespace Content.MapRenderer;
|
|
|
|
public sealed class MapViewerData
|
|
{
|
|
public string Id { get; set; } = string.Empty;
|
|
public string Name { get; set; } = string.Empty;
|
|
public List<GridLayer> Grids { get; set; } = new();
|
|
public string? Attributions { get; set; }
|
|
public List<LayerGroup> ParallaxLayers { get; set; } = new();
|
|
}
|
|
|
|
public sealed class GridLayer
|
|
{
|
|
public string GridId { get; set; } = string.Empty;
|
|
public Position Offset { get; set; }
|
|
public bool Tiled { get; set; } = false;
|
|
public string Url { get; set; }
|
|
public Extent Extent { get; set; }
|
|
|
|
public GridLayer(RenderedGridImage<Rgba32> gridImage, string url)
|
|
{
|
|
//Get the internal _uid as string
|
|
if (gridImage.GridUid.HasValue)
|
|
GridId = gridImage.GridUid.Value.GetHashCode().ToString();
|
|
|
|
Offset = new Position(gridImage.Offset);
|
|
Extent = new Extent(gridImage.Image.Width, gridImage.Image.Height);
|
|
Url = url;
|
|
}
|
|
}
|
|
|
|
public sealed class LayerGroup
|
|
{
|
|
public Position Scale { get; set; } = Position.One();
|
|
public Position Offset { get; set; } = Position.Zero();
|
|
public bool Static { get; set; } = false;
|
|
public float? MinScale { get; set; }
|
|
public GroupSource Source { get; set; } = new();
|
|
public List<Layer> Layers { get; set; } = new();
|
|
|
|
public static LayerGroup DefaultParallax(IResourceManager resourceManager, ParallaxOutput output)
|
|
{
|
|
return new LayerGroup
|
|
{
|
|
Scale = new Position(0.1f, 0.1f),
|
|
Source = new GroupSource
|
|
{
|
|
Url = output.ReferenceResourceFile(resourceManager, new ResPath("/Textures/Parallaxes/layer1.png")),
|
|
Extent = new Extent(6000, 4000),
|
|
},
|
|
Layers = new List<Layer>
|
|
{
|
|
new()
|
|
{
|
|
Url = output.ReferenceResourceFile(resourceManager, new ResPath("/Textures/Parallaxes/layer1.png")),
|
|
},
|
|
new()
|
|
{
|
|
Url = output.ReferenceResourceFile(resourceManager, new ResPath("/Textures/Parallaxes/layer2.png")),
|
|
Composition = "lighter",
|
|
ParallaxScale = new Position(0.2f, 0.2f)
|
|
},
|
|
new()
|
|
{
|
|
Url = output.ReferenceResourceFile(resourceManager, new ResPath("/Textures/Parallaxes/layer3.png")),
|
|
Composition = "lighter",
|
|
ParallaxScale = new Position(0.3f, 0.3f)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
public sealed class GroupSource
|
|
{
|
|
public string Url { get; set; } = string.Empty;
|
|
public Extent Extent { get; set; } = new();
|
|
}
|
|
|
|
public sealed class Layer
|
|
{
|
|
public string Url { get; set; } = string.Empty;
|
|
public string Composition { get; set; } = "source-over";
|
|
public Position ParallaxScale { get; set; } = new(0.1f, 0.1f);
|
|
}
|
|
|
|
public readonly struct Extent
|
|
{
|
|
[JsonInclude]
|
|
public readonly float X1;
|
|
[JsonInclude]
|
|
public readonly float Y1;
|
|
[JsonInclude]
|
|
public readonly float X2;
|
|
[JsonInclude]
|
|
public readonly float Y2;
|
|
|
|
public Extent()
|
|
{
|
|
X1 = 0;
|
|
Y1 = 0;
|
|
X2 = 0;
|
|
Y2 = 0;
|
|
}
|
|
|
|
public Extent(float x2, float y2)
|
|
{
|
|
X1 = 0;
|
|
Y1 = 0;
|
|
X2 = x2;
|
|
Y2 = y2;
|
|
}
|
|
|
|
public Extent(float x1, float y1, float x2, float y2)
|
|
{
|
|
X1 = x1;
|
|
Y1 = y1;
|
|
X2 = x2;
|
|
Y2 = y2;
|
|
}
|
|
}
|
|
|
|
public readonly struct Position
|
|
{
|
|
[JsonInclude]
|
|
public readonly float X;
|
|
[JsonInclude]
|
|
public readonly float Y;
|
|
|
|
public Position(float x, float y)
|
|
{
|
|
X = x;
|
|
Y = y;
|
|
}
|
|
|
|
public Position(Vector2 vector2)
|
|
{
|
|
X = vector2.X;
|
|
Y = vector2.Y;
|
|
}
|
|
|
|
public static Position Zero()
|
|
{
|
|
return new Position(0, 0);
|
|
}
|
|
|
|
public static Position One()
|
|
{
|
|
return new Position(0, 0);
|
|
}
|
|
}
|