using System.Collections.Generic; using Vellum; namespace Clave.Vellum { /// /// Saves a ChordSet as a list of its chords, each with its priority and whether it is enabled. /// /// /// Loading adds the chords again, which ranks them against each other as if they had been added in code. /// public sealed class ChordSetConverter : SaveConverter { public const string ChordsKey = "chords"; public const string ChordKey = "chord"; public const string PriorityKey = "priority"; public const string EnabledKey = "enabled"; public override SaveNode Write(ChordSet value, SaveSession session) { var chords = new List(); foreach (Chord chord in value) { chords.Add(new SavedChord(chord, value.PriorityOf(chord), value.IsEnabled(chord))); } return SavedChords.Write(chords, session); } public override ChordSet Read(SaveNode node, SaveSession session) { var builder = new ChordSetBuilder(); foreach (SavedChord saved in SavedChords.Read(node, session)) { builder.Add(saved.Chord, saved.Priority); if (!saved.Enabled) { builder.SetEnabled(saved.Chord, false); } } return builder.Build(); } public override bool TryListChildren(SaveNode node, ChildList children) { return SavedChords.TryListChildren(node, children); } } }