diff --git a/IPA.Loader/Config/Data/List.cs b/IPA.Loader/Config/Data/List.cs index 2db84080..843c9556 100644 --- a/IPA.Loader/Config/Data/List.cs +++ b/IPA.Loader/Config/Data/List.cs @@ -1,16 +1,20 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; namespace IPA.Config.Data { /// /// A list of s for serialization by an . + /// Use or to create. /// public sealed class List : Value, IList { private readonly List values = new List(); + internal List() { } + /// /// Gets the value at the given index in this . /// @@ -34,6 +38,15 @@ namespace IPA.Config.Data /// public void Add(Value item) => values.Add(item); + /// + /// Adds a range of s to the end of this . + /// + /// the range of s to add + public void AddRange(IEnumerable vals) + { + foreach (var val in vals) Add(val); + } + /// /// Clears the . /// @@ -94,6 +107,13 @@ namespace IPA.Config.Data /// public void RemoveAt(int index) => values.RemoveAt(index); + /// + /// Converts this into a human-readable format. + /// + /// a comma-seperated list of the result of wrapped in square brackets + public override string ToString() + => $"[{string.Join(",",this.Select(v => v.ToString()))}]"; + IEnumerator IEnumerable.GetEnumerator() => ((IList)values).GetEnumerator(); } diff --git a/IPA.Loader/Config/Data/Map.cs b/IPA.Loader/Config/Data/Map.cs index 7ad0054e..fec993b4 100644 --- a/IPA.Loader/Config/Data/Map.cs +++ b/IPA.Loader/Config/Data/Map.cs @@ -1,16 +1,20 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; namespace IPA.Config.Data { /// /// A map of to for serialization by an . + /// Use or to create. /// public sealed class Map : Value, IDictionary { private readonly Dictionary values = new Dictionary(); + internal Map() { } + /// /// Accesses the at in the map. /// @@ -98,6 +102,13 @@ namespace IPA.Config.Data public bool TryGetValue(string key, out Value value) => values.TryGetValue(key, out value); IEnumerator IEnumerable.GetEnumerator() => ((IDictionary)values).GetEnumerator(); + + /// + /// Converts this into a human-readable format. + /// + /// a JSON-like set of key-value pairs + public override string ToString() + => $"{{{string.Join(",", this.Select(p => $"\"{p.Key}\":{p.Value.ToString()}"))}}}"; } diff --git a/IPA.Loader/Config/Data/Primitives.cs b/IPA.Loader/Config/Data/Primitives.cs new file mode 100644 index 00000000..23d4adcb --- /dev/null +++ b/IPA.Loader/Config/Data/Primitives.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IPA.Config.Data +{ + /// + /// A representing a piece of text. The only reason this is not named + /// String is so that it doesn't conflict with . + /// + public sealed class Text : Value + { + /// + /// The actual value of this object. + /// + public string Value { get; set; } + + /// + /// Converts this into a human-readable format. + /// + /// a quoted, unescaped string form of + public override string ToString() => $"\"{Value}\""; + } + + /// + /// A representing an integer. This may hold a 's + /// worth of data. + /// + public sealed class Integer : Value + { + /// + /// The actual value of the object. + /// + public long Value { get; set; } + + /// + /// Converts this into a human-readable format. + /// + /// the result of Value.ToString() + public override string ToString() => Value.ToString(); + } + + /// + /// A representing a floating point value. This may hold a + /// 's worth of data. + /// + public sealed class FloatingPoint : Value + { + /// + /// The actual value fo this object. + /// + public double Value { get; set; } + + /// + /// Converts this into a human-readable format. + /// + /// the result of Value.ToString() + public override string ToString() => Value.ToString(); + } + + /// + /// A representing a boolean value. + /// + public sealed class Boolean : Value + { + /// + /// The actual value fo this object. + /// + public bool Value { get; set; } + + /// + /// Converts this into a human-readable format. + /// + /// the result of Value.ToString().ToLower() + public override string ToString() => Value.ToString().ToLower(); + } +} diff --git a/IPA.Loader/Config/Data/Value.cs b/IPA.Loader/Config/Data/Value.cs index 5b8b6d03..a2abb681 100644 --- a/IPA.Loader/Config/Data/Value.cs +++ b/IPA.Loader/Config/Data/Value.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,48 +9,125 @@ namespace IPA.Config.Data { /// /// A base value type for config data abstract representations, to be serialized with an - /// . + /// . If a is , then + /// that represents just that: a null in whatever serialization is being used. + /// Also contains factory functions for all derived types. /// public abstract class Value { + /// + /// Converts this into a human-readable format. + /// + /// a human-readable string containing the value provided + public abstract override string ToString(); - } + /// + /// Creates a Null . + /// + /// + public static Value Null() => null; - // not String to prevent overlap with System.String - /// - /// A representing a piece of text. The only reason this is not named - /// String is so that it doesn't conflict with . - /// - public sealed class Text : Value - { + /// + /// Creates an empty . + /// + /// an empty + /// + public static List List() => new List(); + /// + /// Creates an empty . + /// + /// an empty + /// + public static Map Map() => new Map(); - } + /// + /// Creates a new representing a . + /// + /// the value to wrap + /// a wrapping + /// + public static Text From(string val) => Text(val); + /// + /// Creates a new object wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static Text Text(string val) => val == null ? new Text { Value = val } : null; - /// - /// A representing an integer. This may hold a 's - /// worth of data. - /// - public sealed class Integer : Value - { + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static Integer From(long val) => Integer(val); + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static Integer Integer(long val) => new Integer { Value = val }; - } + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static FloatingPoint From(double val) => Float(val); + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static FloatingPoint Float(double val) => new FloatingPoint { Value = val }; - /// - /// A representing a floating point value. This may hold a - /// 's worth of data. - /// - public sealed class FloatingPoint : Value - { + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static Boolean From(bool val) => Bool(val); + /// + /// Creates a new wrapping a . + /// + /// the value to wrap + /// a wrapping + /// + public static Boolean Bool(bool val) => new Boolean { Value = val }; - } - - /// - /// A representing a boolean value. - /// - public sealed class Boolean : Value - { + /// + /// Creates a new holding the content of an + /// of . + /// + /// the s to initialize the with + /// a containing the content of + /// + public static List From(IEnumerable vals) + { + if (vals == null) return null; + var l = List(); + l.AddRange(vals); + return l; + } + /// + /// Creates a new holding the content of an + /// of to . + /// + /// the dictionary of s to initialize the wtih + /// a containing the content of + /// + public static Map From(IDictionary vals) + { + if (vals == null) return null; + var m = Map(); + foreach (var v in vals) m.Add(v.Key, v.Value); + return m; + } } - - } diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index 6f927018..2bca05e3 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -88,6 +88,7 @@ + diff --git a/Refs/BeatSaberCustomUI.dll b/Refs/BeatSaberCustomUI.dll deleted file mode 100644 index 0453b5d6..00000000 Binary files a/Refs/BeatSaberCustomUI.dll and /dev/null differ diff --git a/Refs/UnityEngine.CoreModule.Net4.dll b/Refs/UnityEngine.CoreModule.Net4.dll index 6362cdf1..f6df15fd 100644 Binary files a/Refs/UnityEngine.CoreModule.Net4.dll and b/Refs/UnityEngine.CoreModule.Net4.dll differ