Skip to content

Commit

Permalink
[O] enforce type for SetEntryValue and some comment and type chore
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Nov 25, 2024
1 parent e3b06b1 commit da36ef4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion AquaMai/AquaMai.Config.Interfaces/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
9 changes: 8 additions & 1 deletion AquaMai/AquaMai.Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private void InitializeSection(ReflectionManager.Section section)
{
throw new InvalidOperationException($"Null default value for entry {entry.Path} is not allowed.");
}

entries.Add(entry.Path, new EntryState()
{
IsDefault = true,
Expand All @@ -75,6 +76,7 @@ public IConfig.ISectionState GetSectionState(Type type)
{
throw new ArgumentException($"Type {type.FullName} is not a config section.");
}

return sections[section.Path];
}

Expand All @@ -91,8 +93,13 @@ public IConfig.IEntryState GetEntryState(IReflectionManager.IEntry entry)

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;
}
}
}
4 changes: 2 additions & 2 deletions AquaMai/AquaMai.Mods/GameSettings/JudgeAdjust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -45,6 +45,6 @@ public static void GetJudgeTimingFrame(ref float __result)
public static void NewTouchPanelRecv()
{
if (touchDelay <= 0) return;
Thread.Sleep(touchDelay);
Thread.Sleep((int)touchDelay);
}
}
2 changes: 1 addition & 1 deletion AquaMai/AquaMai.Mods/GameSystem/DisableTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Disable timers (hidden and set to 65535 seconds).
Not recommand to enable when SinglePlayer is off.
""",
zh: """
去除游戏中的倒计时(隐藏并设为 65535 秒)
去除并隐藏游戏中的倒计时
没有开启单人模式时,不建议启用
""")]
public class DisableTimeout
Expand Down

0 comments on commit da36ef4

Please sign in to comment.