[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:
凌莞~(=^▽^=)
2024-11-30 05:29:30 +08:00
committed by GitHub
parent bed1b85319
commit d5a9c98ff9
12 changed files with 161 additions and 24 deletions

View File

@@ -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());
}
}