-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderScrCommand.cs
More file actions
31 lines (28 loc) · 1.01 KB
/
Copy pathRenderScrCommand.cs
File metadata and controls
31 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Subterra.Spectrum;
namespace Subterra.Tools;
internal static class RenderScrCommand
{
public static int Run(string[] args)
{
if (args.Length != 1)
{
Console.Error.WriteLine("usage: render-scr <path/to/file.scr>");
return 2;
}
var srcPath = args[0];
var raw = File.ReadAllBytes(srcPath);
if (raw.Length < SpectrumScreen.ScrBytes)
{
Console.Error.WriteLine(
$"{srcPath}: expected at least {SpectrumScreen.ScrBytes} bytes, got {raw.Length}.");
return 1;
}
var rgba = SpectrumScreen.DecodeRgba(raw);
var repoRoot = RenderTarget.FindRepoRoot(AppContext.BaseDirectory);
var descriptor = $"scr-{Path.GetFileNameWithoutExtension(srcPath).ToLowerInvariant()}";
var outPath = RenderTarget.ForPng(repoRoot, descriptor);
PngWriter.WriteRgba(outPath, rgba, SpectrumScreen.Width, SpectrumScreen.Height);
Console.WriteLine(outPath);
return 0;
}
}