[O] enforce type for SetEntryValue and some comment and type chore

pull/91/head
Clansty 2024-11-26 05:14:58 +08:00
parent e3b06b110f
commit da36ef4002
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
4 changed files with 12 additions and 5 deletions

View File

@ -6,7 +6,7 @@ public interface IConfig
{
public interface IEntryState
{
public bool IsDefault { get; set; }
public bool IsDefault { get; }
public object DefaultValue { get; }
public object Value { get; set; }
}

View File

@ -55,6 +55,7 @@ public class Config : IConfig
{
throw new InvalidOperationException($"Null default value for entry {entry.Path} is not allowed.");
}
entries.Add(entry.Path, new EntryState()
{
IsDefault = true,
@ -75,6 +76,7 @@ public class Config : IConfig
{
throw new ArgumentException($"Type {type.FullName} is not a config section.");
}
return sections[section.Path];
}
@ -91,8 +93,13 @@ public class Config : IConfig
public void SetEntryValue(IReflectionManager.IEntry entry, object value)
{
if (value.GetType() != entry.Field.FieldType)
{
throw new ArgumentException($"Value type {value.GetType().FullName} does not match entry type {entry.Field.FieldType.FullName}.");
}
entry.Field.SetValue(null, value);
entries[entry.Path].IsDefault = false;
entries[entry.Path].Value = value;
}
}
}

View File

@ -24,7 +24,7 @@ public class JudgeAdjust
[ConfigEntry(
en: "Increase touch delay.",
zh: "增加触摸延迟")]
private static readonly int touchDelay = 0;
private static readonly uint touchDelay = 0;
[HarmonyPostfix]
[HarmonyPatch(typeof(UserOption), "GetAdjustMSec")]
@ -45,6 +45,6 @@ public class JudgeAdjust
public static void NewTouchPanelRecv()
{
if (touchDelay <= 0) return;
Thread.Sleep(touchDelay);
Thread.Sleep((int)touchDelay);
}
}

View File

@ -14,7 +14,7 @@ namespace AquaMai.Mods.GameSystem;
Not recommand to enable when SinglePlayer is off.
""",
zh: """
65535
""")]
public class DisableTimeout