207 行
4.1 KiB
C#
207 行
4.1 KiB
C#
using System.Collections.Immutable;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using YukkuriMovieMaker.Plugin;
|
|
using YukkuriMovieMaker.UndoRedo;
|
|
|
|
namespace UndoTree.Tests;
|
|
|
|
public sealed class Part : UndoRedoable
|
|
{
|
|
int value;
|
|
|
|
public Part(string label) => Label = label;
|
|
|
|
public string Label { get; }
|
|
|
|
public int Value
|
|
{
|
|
get => value;
|
|
set => Set(ref this.value, value);
|
|
}
|
|
|
|
public override string ToString() => $"{Label}:{Value}";
|
|
}
|
|
|
|
public sealed class Document : UndoRedoable
|
|
{
|
|
int x;
|
|
int y;
|
|
|
|
public Document() => SubscribeObservableCollectionChangedAndChild(Parts);
|
|
|
|
public int X
|
|
{
|
|
get => x;
|
|
set => Set(ref x, value);
|
|
}
|
|
|
|
public int Y
|
|
{
|
|
get => y;
|
|
set => Set(ref y, value);
|
|
}
|
|
|
|
public ObservableCollection<Part> Parts { get; } = [];
|
|
|
|
public string Snapshot() => $"X={X} Y={Y} Parts=[{string.Join(",", Parts)}]";
|
|
}
|
|
|
|
public sealed class Sheet : UndoRedoable
|
|
{
|
|
ImmutableList<Part> parts = [];
|
|
int x;
|
|
|
|
public int X
|
|
{
|
|
get => x;
|
|
set => Set(ref x, value);
|
|
}
|
|
|
|
public ImmutableList<Part> Parts
|
|
{
|
|
get => parts;
|
|
set => Set(ref parts, value);
|
|
}
|
|
|
|
public void Seed(ImmutableList<Part> seeded) => parts = seeded;
|
|
|
|
public string Snapshot() => $"X={X} Parts=[{string.Join(",", Parts.Select(part => part.Label))}]";
|
|
}
|
|
|
|
public sealed class Slot : UndoRedoable
|
|
{
|
|
int level;
|
|
|
|
public int Level
|
|
{
|
|
get => level;
|
|
set => Set(ref level, value);
|
|
}
|
|
}
|
|
|
|
public sealed class Panel : UndoRedoable
|
|
{
|
|
public Panel()
|
|
{
|
|
SubscribeChildUndoRedoable(Gain);
|
|
SubscribeObservableCollectionChangedAndChild(Slots);
|
|
}
|
|
|
|
public string Label => "panel";
|
|
|
|
public Slot Gain { get; } = new();
|
|
|
|
public ObservableCollection<Slot> Slots { get; } = [];
|
|
}
|
|
|
|
public sealed class Rig : UndoRedoable
|
|
{
|
|
public Part Knob { get; } = new("knob");
|
|
|
|
public IEnumerable<Part> Generated => Enumerable.Range(0, 3).Select(index => new Part(index.ToString()));
|
|
}
|
|
|
|
public sealed class Link : UndoRedoable
|
|
{
|
|
Link? next;
|
|
|
|
public Link? Next
|
|
{
|
|
get => next;
|
|
set => Set(ref next, value);
|
|
}
|
|
}
|
|
|
|
public sealed class Group : UndoRedoable
|
|
{
|
|
Document? child;
|
|
|
|
public Document? Child
|
|
{
|
|
get => child;
|
|
set => Set(ref child, value);
|
|
}
|
|
}
|
|
|
|
public sealed class Labelled : UndoRedoable
|
|
{
|
|
int amount;
|
|
int broken;
|
|
|
|
[Display(Name = "Visible name")]
|
|
public int Amount
|
|
{
|
|
get => amount;
|
|
set => Set(ref amount, value);
|
|
}
|
|
|
|
[Display(Name = "Missing", ResourceType = typeof(Texts))]
|
|
public int Broken
|
|
{
|
|
get => broken;
|
|
set => Set(ref broken, value);
|
|
}
|
|
}
|
|
|
|
public enum Shade
|
|
{
|
|
[Display(Name = "Visible shade")]
|
|
Dark,
|
|
Light,
|
|
}
|
|
|
|
[Flags]
|
|
public enum Marks
|
|
{
|
|
[Display(Name = "First mark")]
|
|
First = 1,
|
|
Second = 2,
|
|
}
|
|
|
|
public sealed class VisiblePlugin : IPlugin
|
|
{
|
|
public string Name => "Visible plugin";
|
|
}
|
|
|
|
public sealed class BrokenPlugin : IPlugin
|
|
{
|
|
public BrokenPlugin() => throw new InvalidOperationException("broken");
|
|
|
|
public string Name => "Broken plugin";
|
|
}
|
|
|
|
public abstract class AbstractPlugin : IPlugin
|
|
{
|
|
public string Name => "Abstract plugin";
|
|
}
|
|
|
|
public static class Histories
|
|
{
|
|
public static (UndoRedoManager Manager, Document Document) NewDocument(params string[] partLabels)
|
|
{
|
|
var document = new Document();
|
|
foreach (var label in partLabels)
|
|
document.Parts.Add(new Part(label));
|
|
|
|
var manager = new UndoRedoManager();
|
|
manager.Subscribe(document);
|
|
return (manager, document);
|
|
}
|
|
|
|
public static (UndoRedoManager Manager, Sheet Sheet) NewSheet(params string[] partLabels)
|
|
{
|
|
var sheet = new Sheet();
|
|
sheet.Seed([.. partLabels.Select(label => new Part(label))]);
|
|
var manager = new UndoRedoManager();
|
|
manager.Subscribe(sheet);
|
|
return (manager, sheet);
|
|
}
|
|
|
|
public static void Edit(UndoRedoManager manager, Action change)
|
|
{
|
|
change();
|
|
manager.Record();
|
|
}
|
|
}
|