Files
h-school/tests/HSchool.Content.Tests/PackDocuments.cs
T

45 lines
1.6 KiB
C#

namespace HSchool.Content.Tests;
internal sealed class RecordingLog : IContentLog
{
public List<string> Warnings { get; } = [];
public void Warning(string message) => Warnings.Add(message);
}
internal static class PackDocuments
{
public static ContentDocument Def(string packId, string folder, string file, string jsonc) =>
new(packId, $"defs/{folder}/{file}.jsonc", jsonc);
public static ContentDocument Patch(string packId, string file, string jsonc) =>
new(packId, $"patches/{file}.jsonc", jsonc);
public static ContentDocument Locale(string packId, string language, string jsonc) =>
new(packId, $"localizations/{language}.jsonc", jsonc);
public static ContentDocument Map(string packId, string jsonc) =>
new(packId, "maps/default.jsonc", jsonc);
public static ContentDocument Manifest(string packId, string jsonc) =>
new(packId, "pack.jsonc", jsonc);
public static IReadOnlyList<ContentDocument> FromDirectory(string packId, string packRoot)
{
var documents = new List<ContentDocument>();
foreach (var path in Directory.EnumerateFiles(packRoot, "*.*", SearchOption.AllDirectories))
{
if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
&& !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
{
continue;
}
var relative = Path.GetRelativePath(packRoot, path).Replace('\\', '/');
documents.Add(new ContentDocument(packId, relative, File.ReadAllText(path)));
}
return documents;
}
}