Browse Source

Finished up Config.Data

pull/46/head
Anairkoen Schno 4 years ago
parent
commit
3627f48ea2
7 changed files with 221 additions and 32 deletions
  1. +20
    -0
      IPA.Loader/Config/Data/List.cs
  2. +11
    -0
      IPA.Loader/Config/Data/Map.cs
  3. +79
    -0
      IPA.Loader/Config/Data/Primitives.cs
  4. +110
    -32
      IPA.Loader/Config/Data/Value.cs
  5. +1
    -0
      IPA.Loader/IPA.Loader.csproj
  6. BIN
      Refs/BeatSaberCustomUI.dll
  7. BIN
      Refs/UnityEngine.CoreModule.Net4.dll

+ 20
- 0
IPA.Loader/Config/Data/List.cs View File

@ -1,16 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace IPA.Config.Data
{
/// <summary>
/// A list of <see cref="Value"/>s for serialization by an <see cref="IConfigProvider"/>.
/// Use <see cref="Value.List"/> or <see cref="Value.From(IEnumerable{Value})"/> to create.
/// </summary>
public sealed class List : Value, IList<Value>
{
private readonly List<Value> values = new List<Value>();
internal List() { }
/// <summary>
/// Gets the value at the given index in this <see cref="List"/>.
/// </summary>
@ -34,6 +38,15 @@ namespace IPA.Config.Data
/// <seealso cref="ICollection{T}.Add(T)"/>
public void Add(Value item) => values.Add(item);
/// <summary>
/// Adds a range of <see cref="Value"/>s to the end of this <see cref="List"/>.
/// </summary>
/// <param name="vals">the range of <see cref="Value"/>s to add</param>
public void AddRange(IEnumerable<Value> vals)
{
foreach (var val in vals) Add(val);
}
/// <summary>
/// Clears the <see cref="List"/>.
/// </summary>
@ -94,6 +107,13 @@ namespace IPA.Config.Data
/// <seealso cref="IList{T}.RemoveAt(int)"/>
public void RemoveAt(int index) => values.RemoveAt(index);
/// <summary>
/// Converts this <see cref="Value"/> into a human-readable format.
/// </summary>
/// <returns>a comma-seperated list of the result of <see cref="Value.ToString"/> wrapped in square brackets</returns>
public override string ToString()
=> $"[{string.Join(",",this.Select(v => v.ToString()))}]";
IEnumerator IEnumerable.GetEnumerator() => ((IList<Value>)values).GetEnumerator();
}


+ 11
- 0
IPA.Loader/Config/Data/Map.cs View File

@ -1,16 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace IPA.Config.Data
{
/// <summary>
/// A map of <see cref="string"/> to <see cref="Value"/> for serialization by an <see cref="IConfigProvider"/>.
/// Use <see cref="Value.Map"/> or <see cref="Value.From(IDictionary{string, Value})"/> to create.
/// </summary>
public sealed class Map : Value, IDictionary<string, Value>
{
private readonly Dictionary<string, Value> values = new Dictionary<string, Value>();
internal Map() { }
/// <summary>
/// Accesses the <see cref="Value"/> at <paramref name="key"/> in the map.
/// </summary>
@ -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<string, Value>)values).GetEnumerator();
/// <summary>
/// Converts this <see cref="Value"/> into a human-readable format.
/// </summary>
/// <returns>a JSON-like set of key-value pairs</returns>
public override string ToString()
=> $"{{{string.Join(",", this.Select(p => $"\"{p.Key}\":{p.Value.ToString()}"))}}}";
}


+ 79
- 0
IPA.Loader/Config/Data/Primitives.cs View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Config.Data
{
/// <summary>
/// A <see cref="Value"/> representing a piece of text. The only reason this is not named
/// String is so that it doesn't conflict with <see cref="string"/>.
/// </summary>
public sealed class Text : Value
{
/// <summary>
/// The actual value of this <see cref="Text"/> object.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Converts this <see cref="Data.Value"/> into a human-readable format.
/// </summary>
/// <returns>a quoted, unescaped string form of <see cref="Value"/></returns>
public override string ToString() => $"\"{Value}\"";
}
/// <summary>
/// A <see cref="Value"/> representing an integer. This may hold a <see cref="long"/>'s
/// worth of data.
/// </summary>
public sealed class Integer : Value
{
/// <summary>
/// The actual value of the <see cref="Integer"/> object.
/// </summary>
public long Value { get; set; }
/// <summary>
/// Converts this <see cref="Data.Value"/> into a human-readable format.
/// </summary>
/// <returns>the result of <c>Value.ToString()</c></returns>
public override string ToString() => Value.ToString();
}
/// <summary>
/// A <see cref="Value"/> representing a floating point value. This may hold a
/// <see cref="double"/>'s worth of data.
/// </summary>
public sealed class FloatingPoint : Value
{
/// <summary>
/// The actual value fo this <see cref="FloatingPoint"/> object.
/// </summary>
public double Value { get; set; }
/// <summary>
/// Converts this <see cref="Data.Value"/> into a human-readable format.
/// </summary>
/// <returns>the result of <c>Value.ToString()</c></returns>
public override string ToString() => Value.ToString();
}
/// <summary>
/// A <see cref="Value"/> representing a boolean value.
/// </summary>
public sealed class Boolean : Value
{
/// <summary>
/// The actual value fo this <see cref="Boolean"/> object.
/// </summary>
public bool Value { get; set; }
/// <summary>
/// Converts this <see cref="Data.Value"/> into a human-readable format.
/// </summary>
/// <returns>the result of <c>Value.ToString().ToLower()</c></returns>
public override string ToString() => Value.ToString().ToLower();
}
}

+ 110
- 32
IPA.Loader/Config/Data/Value.cs View File

@ -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
{
/// <summary>
/// A base value type for config data abstract representations, to be serialized with an
/// <see cref="IConfigProvider"/>.
/// <see cref="IConfigProvider"/>. If a <see cref="Value"/> is <see langword="null"/>, then
/// that represents just that: a <c>null</c> in whatever serialization is being used.
/// Also contains factory functions for all derived types.
/// </summary>
public abstract class Value
{
/// <summary>
/// Converts this <see cref="Value"/> into a human-readable format.
/// </summary>
/// <returns>a human-readable string containing the value provided</returns>
public abstract override string ToString();
}
/// <summary>
/// Creates a Null <see cref="Value"/>.
/// </summary>
/// <returns><see langword="null"/></returns>
public static Value Null() => null;
// not String to prevent overlap with System.String
/// <summary>
/// A <see cref="Value"/> representing a piece of text. The only reason this is not named
/// String is so that it doesn't conflict with <see cref="string"/>.
/// </summary>
public sealed class Text : Value
{
/// <summary>
/// Creates an empty <see cref="List"/>.
/// </summary>
/// <returns>an empty <see cref="List"/></returns>
/// <seealso cref="From(IEnumerable{Value})"/>
public static List List() => new List();
/// <summary>
/// Creates an empty <see cref="Map"/>.
/// </summary>
/// <returns>an empty <see cref="Map"/></returns>
/// <seealso cref="From(IDictionary{string, Value})"/>
public static Map Map() => new Map();
}
/// <summary>
/// Creates a new <see cref="Value"/> representing a <see cref="string"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Data.Text"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="Text(string)"/>
public static Text From(string val) => Text(val);
/// <summary>
/// Creates a new <see cref="Data.Text"/> object wrapping a <see cref="string"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Data.Text"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="From(string)"/>
public static Text Text(string val) => val == null ? new Text { Value = val } : null;
/// <summary>
/// A <see cref="Value"/> representing an integer. This may hold a <see cref="long"/>'s
/// worth of data.
/// </summary>
public sealed class Integer : Value
{
/// <summary>
/// Creates a new <see cref="Value"/> wrapping a <see cref="long"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Data.Integer"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="Integer(long)"/>
public static Integer From(long val) => Integer(val);
/// <summary>
/// Creates a new <see cref="Data.Integer"/> wrapping a <see cref="long"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Data.Integer"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="From(long)"/>
public static Integer Integer(long val) => new Integer { Value = val };
}
/// <summary>
/// Creates a new <see cref="Value"/> wrapping a <see cref="double"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="FloatingPoint"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="Float(double)"/>
public static FloatingPoint From(double val) => Float(val);
/// <summary>
/// Creates a new <see cref="FloatingPoint"/> wrapping a <see cref="double"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="FloatingPoint"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="From(double)"/>
public static FloatingPoint Float(double val) => new FloatingPoint { Value = val };
/// <summary>
/// A <see cref="Value"/> representing a floating point value. This may hold a
/// <see cref="double"/>'s worth of data.
/// </summary>
public sealed class FloatingPoint : Value
{
/// <summary>
/// Creates a new <see cref="Value"/> wrapping a <see cref="bool"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Boolean"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="Bool(bool)"/>
public static Boolean From(bool val) => Bool(val);
/// <summary>
/// Creates a new <see cref="Boolean"/> wrapping a <see cref="bool"/>.
/// </summary>
/// <param name="val">the value to wrap</param>
/// <returns>a <see cref="Boolean"/> wrapping <paramref name="val"/></returns>
/// <seealso cref="From(bool)"/>
public static Boolean Bool(bool val) => new Boolean { Value = val };
}
/// <summary>
/// A <see cref="Value"/> representing a boolean value.
/// </summary>
public sealed class Boolean : Value
{
/// <summary>
/// Creates a new <see cref="Data.List"/> holding the content of an <see cref="IEnumerable{T}"/>
/// of <see cref="Value"/>.
/// </summary>
/// <param name="vals">the <see cref="Value"/>s to initialize the <see cref="Data.List"/> with</param>
/// <returns>a <see cref="Data.List"/> containing the content of <paramref name="vals"/></returns>
/// <seealso cref="List"/>
public static List From(IEnumerable<Value> vals)
{
if (vals == null) return null;
var l = List();
l.AddRange(vals);
return l;
}
/// <summary>
/// Creates a new <see cref="Data.Map"/> holding the content of an <see cref="IDictionary{TKey, TValue}"/>
/// of <see cref="string"/> to <see cref="Value"/>.
/// </summary>
/// <param name="vals">the dictionary of <see cref="Value"/>s to initialize the <see cref="Data.Map"/> wtih</param>
/// <returns>a <see cref="Data.Map"/> containing the content of <paramref name="vals"/></returns>
/// <seealso cref="Map"/>
public static Map From(IDictionary<string, Value> vals)
{
if (vals == null) return null;
var m = Map();
foreach (var v in vals) m.Add(v.Key, v.Value);
return m;
}
}
}

+ 1
- 0
IPA.Loader/IPA.Loader.csproj View File

@ -88,6 +88,7 @@
<Compile Include="Config\ConfigProviders\JsonConfigProvider.cs" />
<Compile Include="Config\Data\List.cs" />
<Compile Include="Config\Data\Map.cs" />
<Compile Include="Config\Data\Primitives.cs" />
<Compile Include="Config\Data\Value.cs" />
<Compile Include="Config\IConfigProvider.cs" />
<Compile Include="Config\IConfigStore.cs" />


BIN
Refs/BeatSaberCustomUI.dll View File


BIN
Refs/UnityEngine.CoreModule.Net4.dll View File


Loading…
Cancel
Save