From da36ef4002ba080492dd951b83fbd2ca9cd993e2 Mon Sep 17 00:00:00 2001 From: Clansty Date: Tue, 26 Nov 2024 05:14:58 +0800 Subject: [PATCH] [O] enforce type for SetEntryValue and some comment and type chore --- AquaMai/AquaMai.Config.Interfaces/IConfig.cs | 2 +- AquaMai/AquaMai.Config/Config.cs | 9 ++++++++- AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs | 4 ++-- AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/AquaMai/AquaMai.Config.Interfaces/IConfig.cs b/AquaMai/AquaMai.Config.Interfaces/IConfig.cs index 4b3859d7..5f3f4a02 100644 --- a/AquaMai/AquaMai.Config.Interfaces/IConfig.cs +++ b/AquaMai/AquaMai.Config.Interfaces/IConfig.cs @@ -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; } } diff --git a/AquaMai/AquaMai.Config/Config.cs b/AquaMai/AquaMai.Config/Config.cs index fdbf67eb..9e445c2d 100644 --- a/AquaMai/AquaMai.Config/Config.cs +++ b/AquaMai/AquaMai.Config/Config.cs @@ -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; } -} +} \ No newline at end of file diff --git a/AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs b/AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs index c54adb78..82092816 100644 --- a/AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs +++ b/AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs @@ -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); } } diff --git a/AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs b/AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs index 14eee957..d3a21038 100644 --- a/AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs +++ b/AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs @@ -14,7 +14,7 @@ namespace AquaMai.Mods.GameSystem; Not recommand to enable when SinglePlayer is off. """, zh: """ - 去除游戏中的倒计时(隐藏并设为 65535 秒) + 去除并隐藏游戏中的倒计时 没有开启单人模式时,不建议启用 """)] public class DisableTimeout