mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-14 05:27:26 +08:00
[O] ResetTouchAfterTrack -> ResetTouch, add press key to reset (#93)
* [O] ResetTouchAfterTrack -> ResetTouch, add press key to reset * fix * update * fix: Remove not work --------- Co-authored-by: Menci <mencici@msn.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using AquaMai.Config.Attributes;
|
||||
using AquaMai.Config.Interfaces;
|
||||
using AquaMai.Config.Migration;
|
||||
using Tomlet.Models;
|
||||
|
||||
namespace AquaMai.Config;
|
||||
@@ -60,7 +61,7 @@ public class ConfigSerializer(IConfigSerializer.Options Options) : IConfigSerial
|
||||
}
|
||||
|
||||
// Version
|
||||
AppendEntry(sb, null, "Version", "2.0");
|
||||
AppendEntry(sb, null, "Version", ConfigMigrationManager.Instance.LatestVersion);
|
||||
|
||||
foreach (var section in ((Config)config).reflectionManager.SectionValues)
|
||||
{
|
||||
|
||||
@@ -59,6 +59,12 @@ public class ConfigView : IConfigView
|
||||
}
|
||||
current = (TomlTable)next;
|
||||
}
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
current.Keys.Remove(pathComponents.Last());
|
||||
return;
|
||||
}
|
||||
current.Put(pathComponents.Last(), value);
|
||||
}
|
||||
|
||||
@@ -85,6 +91,11 @@ public class ConfigView : IConfigView
|
||||
resultValue = default;
|
||||
return false;
|
||||
}
|
||||
if (typeof(T) == typeof(object))
|
||||
{
|
||||
resultValue = (T)(object)value;
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
resultValue = Utility.ParseTomlValue<T>(value);
|
||||
@@ -98,8 +109,34 @@ public class ConfigView : IConfigView
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove(string path)
|
||||
{
|
||||
var pathComponents = path.Split('.');
|
||||
var current = root;
|
||||
foreach (var component in pathComponents.Take(pathComponents.Length - 1))
|
||||
{
|
||||
if (!Utility.TomlTryGetValueCaseInsensitive(current, component, out var next) || next is not TomlTable nextTable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
current = (TomlTable)next;
|
||||
}
|
||||
var keyToRemove = pathComponents.Last();
|
||||
var keysCaseSensitive = current.Keys.Where(k => string.Equals(k, keyToRemove, StringComparison.OrdinalIgnoreCase));
|
||||
foreach (var key in keysCaseSensitive)
|
||||
{
|
||||
current.Entries.Remove(key);
|
||||
}
|
||||
return keysCaseSensitive.Any();
|
||||
}
|
||||
|
||||
public string ToToml()
|
||||
{
|
||||
return root.SerializedValue;
|
||||
}
|
||||
|
||||
public IConfigView Clone()
|
||||
{
|
||||
return new ConfigView(ToToml());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
|
||||
private readonly Dictionary<string, IConfigMigration> migrationMap =
|
||||
new List<IConfigMigration>
|
||||
{
|
||||
new ConfigMigration_V1_0_V2_0()
|
||||
new ConfigMigration_V1_0_V2_0(),
|
||||
new ConfigMigration_V2_0_V2_1()
|
||||
}.ToDictionary(m => m.FromVersion);
|
||||
|
||||
public string LatestVersion { get; }
|
||||
@@ -39,10 +40,12 @@ public class ConfigMigrationManager : IConfigMigrationManager
|
||||
config = migration.Migrate(config);
|
||||
currentVersion = migration.ToVersion;
|
||||
}
|
||||
|
||||
if (currentVersion != LatestVersion)
|
||||
{
|
||||
throw new ArgumentException($"Could not migrate the config from v{currentVersion} to v{LatestVersion}");
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -52,7 +55,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
// Assume v1.0 if not found
|
||||
return "1.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using AquaMai.Config.Interfaces;
|
||||
using Tomlet.Models;
|
||||
|
||||
namespace AquaMai.Config.Migration;
|
||||
|
||||
public class ConfigMigration_V2_0_V2_1 : IConfigMigration
|
||||
{
|
||||
public string FromVersion => "2.0";
|
||||
public string ToVersion => "2.1";
|
||||
|
||||
public IConfigView Migrate(IConfigView src)
|
||||
{
|
||||
var dst = src.Clone();
|
||||
dst.SetValue("Version", ToVersion);
|
||||
|
||||
if (IsSectionEnabled(src, "Tweaks.ResetTouchAfterTrack"))
|
||||
{
|
||||
dst.Remove("Tweaks.ResetTouchAfterTrack");
|
||||
dst.SetValue("Tweaks.ResetTouch.AfterTrack", true);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
public bool IsSectionEnabled(IConfigView src, string path)
|
||||
{
|
||||
if (src.TryGetValue(path, out object section))
|
||||
{
|
||||
if (section is bool enabled)
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
else if (section is TomlTable table)
|
||||
{
|
||||
if (Utility.TomlTryGetValueCaseInsensitive(table, "Disabled", out var disabled))
|
||||
{
|
||||
return !Utility.IsTrutyOrDefault(disabled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,16 @@ public static class Utility
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsTrutyOrDefault(TomlValue value, bool defaultValue = false)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
TomlBoolean boolean => boolean.Value,
|
||||
TomlLong @long => @long.Value != 0,
|
||||
_ => defaultValue
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsIntegerType(Type type)
|
||||
{
|
||||
return type == typeof(sbyte) || type == typeof(short) || type == typeof(int) || type == typeof(long)
|
||||
|
||||
Reference in New Issue
Block a user