feat: phase 5 groundwork (playback format 3, videos contracts, migration 0010, strings)
Lays down every contract the later parcels of owner review 1 phase 5 build on, so they compile against shared types without touching each other's files. - Settings format 3: export.playback (direction, loops, fades, hold), omitted at its default and member by member; RequiredFormat is 3 only while used. - OutputProgram public API with a forward-only body; still-frame job parameters (StillFrame, StillPhoto) routed to format-3 nodes only. - Render.Sha256/Kind, RenderCopy, RenderKind; JobKind.VideoCopy = 24. - Migration 0010 (sqlite, postgres): renders.sha256/kind, ix_renders_created, render_copies without a foreign key. - Videos protocol DTOs, client calls, ServerCapabilities.Videos (declared, not announced yet), ServerSettingsDto.VideosPath. - IVideoLibrary with a NotImplemented stub registered on the server; TrashKind.Videos, VideoTrashNames, VideoErrors. - en and it strings for the whole phase, five icons, decisions 1-22 and the open-question defaults; tests that used format 3 as "newer" now use 4. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86aa07c1d7
commit
d472dfdec1
67 files changed
+2233
-244
No files matched your search
@@ -570,23 +570,130 @@ public sealed class ProjectSettingsTests
|
||||
[Test]
|
||||
public void ANewerFormatStaysReadOnlyAndKeepsItsNumber()
|
||||
{
|
||||
const string newer = """{ "version": 3, "camera": { "rotate": 90 }, "look": { "filter": "film", "grain": 0.2 } }""";
|
||||
const string newer = """{ "version": 4, "camera": { "rotate": 90 }, "look": { "filter": "film", "grain": 0.2 } }""";
|
||||
Assert.Throws<InvalidDataException>(() => ProjectSettings.FromJson(newer));
|
||||
var read = ProjectSettings.FromJson(newer, allowNewer: true);
|
||||
Assert.True(read.IsNewerFormat);
|
||||
Assert.Equal(3, read.WrittenFormat);
|
||||
Assert.Equal(4, read.WrittenFormat);
|
||||
var canonical = ProjectContent.Canonical(newer);
|
||||
Assert.Equal(3, ProjectContent.FormatOf(canonical));
|
||||
Assert.Equal(4, ProjectContent.FormatOf(canonical));
|
||||
Assert.Contains("\"grain\": 0.2", canonical);
|
||||
Assert.Equal(canonical, ProjectContent.Canonical(canonical));
|
||||
|
||||
// A format-2 project is this Chronos's own (written as the format it needs); text without a version is format 1.
|
||||
// Format-2 and format-3 projects are this Chronos's own (written as the format they need); text without a version
|
||||
// is format 1.
|
||||
Assert.False(ProjectSettings.FromJson("""{ "version": 2 }""").IsNewerFormat);
|
||||
Assert.Equal(1, ProjectSettings.FromJson("""{ "version": 2 }""").WrittenFormat);
|
||||
Assert.False(ProjectSettings.FromJson("""{ "version": 3 }""").IsNewerFormat);
|
||||
Assert.Equal(1, ProjectSettings.FromJson("""{ "version": 3 }""").WrittenFormat);
|
||||
Assert.Equal(1, ProjectContent.FormatOf("""{ "camera": {} }"""));
|
||||
Assert.Equal(1, ProjectContent.FormatOf(null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APlaybackAtItsDefaultIsWrittenAsNone()
|
||||
{
|
||||
var plain = new ProjectSettings().ToJson();
|
||||
foreach (var playback in new[]
|
||||
{
|
||||
new PlaybackSettings(),
|
||||
new PlaybackSettings { Direction = "Forward", Loops = 1, FadeIn = 0, FadeOut = 0, HoldEnd = 0 },
|
||||
new PlaybackSettings { Loops = 0, FadeIn = double.NaN, HoldEnd = -2 },
|
||||
})
|
||||
{
|
||||
Assert.True(playback.IsDefault);
|
||||
var settings = new ProjectSettings { Export = new ExportSettings { Playback = playback } };
|
||||
Assert.Equal(ProjectSettings.BaseVersion, settings.RequiredFormat);
|
||||
Assert.Equal(plain, settings.ToJson());
|
||||
}
|
||||
Assert.False(plain.Contains("playback", StringComparison.Ordinal));
|
||||
Assert.Null(ProjectSettings.FromJson(plain).Export.Playback);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThePlaybackRaisesTheFormatToThreeAndLeavesOutItsDefaults()
|
||||
{
|
||||
var plain = new ProjectSettings();
|
||||
var turned = plain with { Camera = new CameraSettings { Rotate = 90 } };
|
||||
var reversed = new PlaybackSettings { Direction = PlaybackDirection.Reverse, Loops = 1, FadeIn = 0 };
|
||||
Assert.Equal((1, 2), (plain.RequiredFormat, turned.RequiredFormat));
|
||||
foreach (var settings in new[]
|
||||
{
|
||||
plain with { Export = plain.Export with { Playback = reversed } },
|
||||
turned with { Export = plain.Export with { Playback = new PlaybackSettings { FadeOut = 2.5 } } },
|
||||
plain with { Export = plain.Export with { Playback = new PlaybackSettings { Loops = 3, HoldEnd = 1 } } },
|
||||
})
|
||||
{
|
||||
Assert.Equal(ProjectSettings.PlaybackVersion, settings.RequiredFormat);
|
||||
Assert.Equal(3, ProjectSettings.CurrentVersion);
|
||||
var json = settings.ToJson();
|
||||
Assert.Contains("\"version\": 3", json);
|
||||
var back = ProjectSettings.FromJson(json);
|
||||
Assert.Equal(3, back.Version);
|
||||
Assert.False(back.IsNewerFormat);
|
||||
Assert.Equal(json, back.ToJson());
|
||||
Assert.Equal(json, ProjectContent.Canonical(json));
|
||||
}
|
||||
|
||||
// Each member at its default is left out of the text.
|
||||
var text = (plain with { Export = plain.Export with { Playback = reversed } }).ToJson();
|
||||
var written = System.Text.Json.Nodes.JsonNode.Parse(text)!["export"]!["playback"]!.AsObject().Select(p => p.Key).ToList();
|
||||
Assert.SequenceEqual(["direction"], written);
|
||||
|
||||
// Every member reads back; the effective values clamp what is out of range.
|
||||
var full = ProjectSettings.FromJson("""{ "export": { "playback": { "direction": "boomerang", "loops": 40, "fadeIn": 1.5, "fadeOut": 99, "holdEnd": 3 } } }""");
|
||||
var playback = Assert.NotNull(full.Export.Playback);
|
||||
Assert.Equal(("boomerang", (int?)40, (double?)1.5, (double?)99.0, (double?)3.0), (playback.Direction, playback.Loops, playback.FadeIn, playback.FadeOut, playback.HoldEnd));
|
||||
Assert.Equal((PlaybackSettings.MaxLoops, PlaybackSettings.MaxFadeSeconds), (playback.EffectiveLoops, playback.EffectiveFadeOut));
|
||||
Assert.Equal(3, full.RequiredFormat);
|
||||
|
||||
// A direction this Chronos does not know renders forward but is kept, and keeps the format.
|
||||
var unknown = ProjectSettings.FromJson("""{ "export": { "playback": { "direction": "pingpong", "speed": 2 } } }""");
|
||||
var kept = Assert.NotNull(unknown.Export.Playback);
|
||||
Assert.Equal(PlaybackDirection.Forward, kept.EffectiveDirection);
|
||||
Assert.False(kept.IsDefault);
|
||||
Assert.Equal(3, unknown.RequiredFormat);
|
||||
Assert.Contains("\"speed\": 2", unknown.ToJson());
|
||||
|
||||
// Taken away again, the project is format 1 with the text it had before.
|
||||
var undone = ProjectSettings.FromJson(text) with { Export = plain.Export };
|
||||
Assert.Equal(plain.ToJson(), undone.ToJson());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFormatThreeFileReadByAFormatTwoBuildKeepsItsPlayback()
|
||||
{
|
||||
var path = Path.Combine(TestContext.FixturesDirectory, "settings", "format3-playback.json");
|
||||
var fixture = File.ReadAllText(path);
|
||||
var settings = ProjectSettings.FromJson(fixture);
|
||||
Assert.Equal(3, settings.Version);
|
||||
var playback = Assert.NotNull(settings.Export.Playback);
|
||||
Assert.Equal((PlaybackDirection.Boomerang, 2, 1.5, 2.0, 3.0), (playback.EffectiveDirection, playback.EffectiveLoops, playback.EffectiveFadeIn, playback.EffectiveFadeOut, playback.EffectiveHoldEnd));
|
||||
Assert.Equal((3, 90), (settings.RequiredFormat, settings.Camera.Rotate));
|
||||
var canonical = ProjectContent.Canonical(settings.ToJson());
|
||||
Assert.Equal(3, ProjectContent.FormatOf(canonical));
|
||||
|
||||
// A format-2 build knows no playback: it lands in the export's Extra and is written back where it was.
|
||||
var old = Format2Build.Read(canonical);
|
||||
Assert.True(old.Export.Extra!.ContainsKey("playback"));
|
||||
Assert.Equal(3, old.Version);
|
||||
Assert.Equal(canonical, Format2Build.Write(old).ReplaceLineEndings("\n"));
|
||||
Assert.True(ProjectContent.MatchesHash(Format2Build.Write(old), ProjectContent.Hash(canonical)));
|
||||
var export = System.Text.Json.Nodes.JsonNode.Parse(canonical)!["export"]!.AsObject().Select(p => p.Key).ToList();
|
||||
Assert.Equal("playback", export[^1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The settings as a format-2 build reads and writes them: its export without the playback (owner review 1, phase 5),
|
||||
/// with the same serialiser options. What it does not know lands in <c>Extra</c>.
|
||||
/// </summary>
|
||||
private static class Format2Build
|
||||
{
|
||||
public static Format2Project Read(string json) => System.Text.Json.JsonSerializer.Deserialize(json, OldJson.Default.Format2Project)!;
|
||||
|
||||
public static string Write(Format2Project project) => System.Text.Json.JsonSerializer.Serialize(project, OldJson.Default.Format2Project);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The settings as a format-1 build reads and writes them: its camera without phase 4's members and its project without
|
||||
/// the look, with the same serialiser options. What it does not know lands in <c>Extra</c>.
|
||||
@@ -630,6 +737,39 @@ internal sealed record OldProject
|
||||
public Dictionary<string, System.Text.Json.JsonElement>? Extra { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>A format-2 build's export (before owner review 1, phase 5): no playback.</summary>
|
||||
internal sealed record Format2Export
|
||||
{
|
||||
public Auto<string> Preset { get; init; } = new();
|
||||
public ExportOverrides Overrides { get; init; } = new();
|
||||
public string NameTemplate { get; init; } = "{date} {title} - {preset}";
|
||||
public string? Folder { get; init; }
|
||||
public IReadOnlyList<string> Batch { get; init; } = [];
|
||||
public bool SyncToServer { get; init; }
|
||||
|
||||
[System.Text.Json.Serialization.JsonExtensionData]
|
||||
public Dictionary<string, System.Text.Json.JsonElement>? Extra { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>A format-2 build's project (owner review 1, phase 4): phase 4's camera and look, the export without playback.</summary>
|
||||
internal sealed record Format2Project
|
||||
{
|
||||
public int Version { get; init; } = 1;
|
||||
public TimingSettings Timing { get; init; } = new();
|
||||
public ExposureSettings Exposure { get; init; } = new();
|
||||
public MotionSettings Motion { get; init; } = new();
|
||||
public CameraSettings Camera { get; init; } = new();
|
||||
public StackSettings Stack { get; init; } = new();
|
||||
public Format2Export Export { get; init; } = new();
|
||||
public IReadOnlyList<int> ExcludedFrames { get; init; } = [];
|
||||
public int? HeroFrame { get; init; }
|
||||
public IReadOnlyList<PendingFrame>? PendingFrames { get; init; }
|
||||
public LookSettings? Look { get; init; }
|
||||
|
||||
[System.Text.Json.Serialization.JsonExtensionData]
|
||||
public Dictionary<string, System.Text.Json.JsonElement>? Extra { get; set; }
|
||||
}
|
||||
|
||||
[System.Text.Json.Serialization.JsonSourceGenerationOptions(
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = System.Text.Json.Serialization.JsonKnownNamingPolicy.CamelCase,
|
||||
@@ -637,4 +777,5 @@ internal sealed record OldProject
|
||||
UseStringEnumConverter = true,
|
||||
PropertyNameCaseInsensitive = true)]
|
||||
[System.Text.Json.Serialization.JsonSerializable(typeof(OldProject))]
|
||||
[System.Text.Json.Serialization.JsonSerializable(typeof(Format2Project))]
|
||||
internal sealed partial class OldJson : System.Text.Json.Serialization.JsonSerializerContext;
|
||||
Reference in new issue
Block a user