Ready for the first beta release. #105
@ -4,7 +4,7 @@ public class Shell
|
|||||||
{
|
{
|
||||||
public const string Author = "That_One_Nerd";
|
public const string Author = "That_One_Nerd";
|
||||||
public const string Name = "SrcMod";
|
public const string Name = "SrcMod";
|
||||||
public const string Version = "Beta 0.4.0";
|
public const string Version = "Beta 0.5.0";
|
||||||
|
|
||||||
public readonly string? ShellDirectory;
|
public readonly string? ShellDirectory;
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,17 @@
|
|||||||
|
|
|||||||
namespace Valve.Miscellaneous;
|
namespace Valve.Miscellaneous;
|
||||||
|
|
||||||
internal static class TypeParsers
|
public static class TypeParsers
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
{
|
{
|
||||||
public static bool CanParse(object? obj) => obj is not null && obj is sbyte or byte or short or ushort or int
|
public static bool CanParse(object? obj) => obj is not null && obj is sbyte or byte or short or ushort or int
|
||||||
or uint or long or ulong or Int128 or UInt128 or nint or nuint or Half or float or double or decimal
|
or uint or long or ulong or Int128 or UInt128 or nint or nuint or Half or float or double or decimal
|
||||||
or char or DateOnly or DateTime or DateTimeOffset or Guid or TimeOnly or TimeSpan;
|
or char or DateOnly or DateTime or DateTimeOffset or Guid or TimeOnly or TimeSpan;
|
||||||
|
public static bool CanParse(Type type) => type == typeof(sbyte) || type == typeof(byte) || type == typeof(short)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(ushort) || type == typeof(int) || type == typeof(uint) || type == typeof(long)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(ulong) || type == typeof(Int128) || type == typeof(UInt128) || type == typeof(nint)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(nuint) || type == typeof(Half) || type == typeof(float) || type == typeof(double)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(decimal) || type == typeof(char) || type == typeof(DateOnly) || type == typeof(DateTime)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(DateTimeOffset) || type == typeof(Guid) || type == typeof(TimeOnly)
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
|
|| type == typeof(TimeSpan);
|
||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
|
|||||||
public static object ParseAll(string msg)
|
public static object ParseAll(string msg)
|
||||||
{
|
{
|
||||||
if (TryParse(msg, out sbyte int8)) return int8;
|
if (TryParse(msg, out sbyte int8)) return int8;
|
||||||
|
|||||||
|
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
Synchronize this file with the other TypeParsers class in the shell. Synchronize this file with the other TypeParsers class in the shell.
This has been completed now. This has been completed now.
This has been completed now. This has been completed now.
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
using Valve.Vkv.ObjectModels;
|
using Valve.Vkv.ObjectModels;
|
||||||
|
|
||||||
|
using ValveParsers = Valve.Miscellaneous.TypeParsers;
|
||||||
|
|
||||||
namespace Valve.Vkv;
|
namespace Valve.Vkv;
|
||||||
|
|
||||||
public static class VkvConvert
|
public static class VkvConvert
|
||||||
@ -68,7 +70,7 @@ public static class VkvConvert
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static object DeserializeObject(string content) =>
|
private static object DeserializeObject(string content) =>
|
||||||
TypeParsers.ParseAll(content);
|
ValveParsers.ParseAll(content);
|
||||||
private static string DeserializeString(string content, VkvOptions options)
|
private static string DeserializeString(string content, VkvOptions options)
|
||||||
{
|
{
|
||||||
if (options.useQuotes)
|
if (options.useQuotes)
|
||||||
@ -118,6 +120,23 @@ public static class VkvConvert
|
|||||||
{
|
{
|
||||||
if (node is null) return null;
|
if (node is null) return null;
|
||||||
|
|
||||||
|
if (node is VkvSingleNode single)
|
||||||
|
{
|
||||||
|
object? value = single.value;
|
||||||
|
if (value is null) return null;
|
||||||
|
else if (value is string str)
|
||||||
|
{
|
||||||
|
value = ValveParsers.ParseAll(str);
|
||||||
|
if (value is string still && outputType.IsEnum)
|
||||||
|
{
|
||||||
|
if (Enum.TryParse(outputType, still, true, out object? res) && res is not null)
|
||||||
|
value = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Convert.ChangeType(value, outputType);
|
||||||
|
}
|
||||||
|
else if (node is VkvTreeNode tree)
|
||||||
|
{
|
||||||
object? instance = Activator.CreateInstance(outputType);
|
object? instance = Activator.CreateInstance(outputType);
|
||||||
if (instance is null) return null;
|
if (instance is null) return null;
|
||||||
|
|
||||||
@ -148,25 +167,21 @@ public static class VkvConvert
|
|||||||
{
|
{
|
||||||
// TODO: check if the node tree has that field.
|
// TODO: check if the node tree has that field.
|
||||||
|
|
||||||
Type castType = field.FieldType;
|
// TODO:
|
||||||
if (TypeParsers.CanParse(instance))
|
// parsables
|
||||||
{
|
// enums
|
||||||
|
// casting
|
||||||
}
|
// sub-conversion
|
||||||
}
|
}
|
||||||
foreach (PropertyInfo prop in validProperties)
|
foreach (PropertyInfo prop in validProperties)
|
||||||
{
|
{
|
||||||
// TODO: check if the node tree has that field.
|
// TODO: check if the node tree has that field.
|
||||||
|
|
||||||
Type castType = prop.PropertyType;
|
|
||||||
if (TypeParsers.CanParse(instance))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else throw new VkvSerializationException("Unknown VKV node type.");
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SerializeNode
|
#region SerializeNode
|
||||||
@ -238,12 +253,12 @@ public static class VkvConvert
|
|||||||
if (obj is null) return null;
|
if (obj is null) return null;
|
||||||
Type type = obj.GetType();
|
Type type = obj.GetType();
|
||||||
|
|
||||||
if (type.IsPrimitive || TypeParsers.CanParse(obj)) return new VkvSingleNode(obj);
|
if (type.IsPrimitive || ValveParsers.CanParse(obj)) return new VkvSingleNode(obj);
|
||||||
else if (type.IsPointer) throw new("Cannot serialize a pointer.");
|
else if (type.IsPointer) throw new("Cannot serialize a pointer.");
|
||||||
|
|
||||||
VkvTreeNode tree = new();
|
VkvTreeNode tree = new();
|
||||||
|
|
||||||
if (obj is IVkvConvertible vdf) return vdf.ToNodeTree();
|
if (obj is IVkvConvertible vkv) return vkv.ToNodeTree();
|
||||||
else if (obj is IDictionary dictionary)
|
else if (obj is IDictionary dictionary)
|
||||||
{
|
{
|
||||||
object[] keys = new object[dictionary.Count],
|
object[] keys = new object[dictionary.Count],
|
||||||
|
|||||||
Synchronize this file with the other TypeParsers class in the shell.
Synchronize this file with the other TypeParsers class in the shell.
This has been completed now.
This has been completed now.