diff --git a/AquaMai/AquaMai.Config/Migration/ConfigMigrationManager.cs b/AquaMai/AquaMai.Config/Migration/ConfigMigrationManager.cs index 98958830..fe4ce8f0 100644 --- a/AquaMai/AquaMai.Config/Migration/ConfigMigrationManager.cs +++ b/AquaMai/AquaMai.Config/Migration/ConfigMigrationManager.cs @@ -12,7 +12,8 @@ public class ConfigMigrationManager : IConfigMigrationManager private readonly Dictionary migrationMap = new List { - 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 IConfigView Migrate(IConfigView config) 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 string GetVersion(IConfigView config) { return version; } + // Assume v1.0 if not found return "1.0"; } -} +} \ No newline at end of file diff --git a/AquaMai/AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs b/AquaMai/AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs new file mode 100644 index 00000000..f21c93b8 --- /dev/null +++ b/AquaMai/AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using AquaMai.Config.Interfaces; +using AquaMai.Config.Types; +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; + + dst.SetValue("Version", ToVersion); + + if (src.GetValueOrDefault("Tweaks.ResetTouchAfterTrack")) + { + dst.SetValue("Tweaks.ResetTouch.AfterTrack", true); + dst.SetValue("Tweaks.ResetTouchAfterTrack", null); + } + + return dst; + } +} \ No newline at end of file diff --git a/AquaMai/AquaMai.Config/Utility.cs b/AquaMai/AquaMai.Config/Utility.cs index f6dbc605..024c5318 100644 --- a/AquaMai/AquaMai.Config/Utility.cs +++ b/AquaMai/AquaMai.Config/Utility.cs @@ -14,6 +14,7 @@ public static bool IsTruty(TomlValue value, string path = null) { TomlBoolean boolean => boolean.Value, TomlLong @long => @long.Value != 0, + TomlTable => true, _ => throw new ArgumentException( path == null ? $"Non-boolish TOML type {value.GetType().Name} value: {value}" diff --git a/AquaMai/AquaMai.Core/Resources/Locale.Designer.cs b/AquaMai/AquaMai.Core/Resources/Locale.Designer.cs index 5a3fba47..e46e620e 100644 --- a/AquaMai/AquaMai.Core/Resources/Locale.Designer.cs +++ b/AquaMai/AquaMai.Core/Resources/Locale.Designer.cs @@ -340,6 +340,15 @@ public static string SpeedUp { } } + /// + /// Looks up a localized string similar to Touch panel reset. + /// + public static string TouchPanelReset { + get { + return ResourceManager.GetString("TouchPanelReset", resourceCulture); + } + } + /// /// Looks up a localized string similar to UserAll Upsert Error. /// diff --git a/AquaMai/AquaMai.Core/Resources/Locale.resx b/AquaMai/AquaMai.Core/Resources/Locale.resx index 8eb37db8..8ee645de 100644 --- a/AquaMai/AquaMai.Core/Resources/Locale.resx +++ b/AquaMai/AquaMai.Core/Resources/Locale.resx @@ -116,4 +116,7 @@ Playlog save error + + Touch panel reset + diff --git a/AquaMai/AquaMai.Core/Resources/Locale.zh.resx b/AquaMai/AquaMai.Core/Resources/Locale.zh.resx index e6a8916d..fac48af0 100644 --- a/AquaMai/AquaMai.Core/Resources/Locale.zh.resx +++ b/AquaMai/AquaMai.Core/Resources/Locale.zh.resx @@ -109,4 +109,7 @@ 保存 Playlog 失败 + + 触摸面板已重置 + diff --git a/AquaMai/AquaMai.Mods/GameSystem/TestProof.cs b/AquaMai/AquaMai.Mods/GameSystem/TestProof.cs index 0db5db06..387955c4 100644 --- a/AquaMai/AquaMai.Mods/GameSystem/TestProof.cs +++ b/AquaMai/AquaMai.Mods/GameSystem/TestProof.cs @@ -5,6 +5,7 @@ using AquaMai.Core; using AquaMai.Core.Attributes; using AquaMai.Core.Helpers; +using AquaMai.Mods.Tweaks; using AquaMai.Mods.UX; using AquaMai.Mods.UX.PracticeMode; using HarmonyLib; @@ -35,6 +36,7 @@ public static bool ShouldEnableImplicitly (typeof(OneKeyRetrySkip), OneKeyRetrySkip.skipKey), (typeof(HideSelfMadeCharts), HideSelfMadeCharts.key), (typeof(PracticeMode), PracticeMode.key), + (typeof(ResetTouch), ResetTouch.key), ]; var keyMapEnabled = ConfigLoader.Config.GetSectionState(typeof(KeyMap)).Enabled; return featureKeys.Any(it => diff --git a/AquaMai/AquaMai.Mods/Tweaks/ResetTouch.cs b/AquaMai/AquaMai.Mods/Tweaks/ResetTouch.cs new file mode 100644 index 00000000..64c79d32 --- /dev/null +++ b/AquaMai/AquaMai.Mods/Tweaks/ResetTouch.cs @@ -0,0 +1,43 @@ +using AquaMai.Config.Attributes; +using AquaMai.Config.Types; +using AquaMai.Core.Helpers; +using AquaMai.Core.Resources; +using HarmonyLib; +using MAI2.Util; +using Main; +using Manager; +using Process; + +namespace AquaMai.Mods.Tweaks; + +[ConfigSection( + en: "Reset touch panel manually or after playing track.", + zh: "重置触摸面板")] +public class ResetTouch +{ + [ConfigEntry(en: "Reset touch panel after playing track.", zh: "玩完一首歌自动重置")] + private static bool afterTrack = false; + + [ConfigEntry(en: "Reset manually.", zh: "按键重置")] + public static readonly KeyCodeOrName key = KeyCodeOrName.None; + + [ConfigEntry] private static readonly bool longPress = false; + + [HarmonyPostfix] + [HarmonyPatch(typeof(ResultProcess), "OnStart")] + public static void ResultProcessOnStart() + { + if (!afterTrack) return; + SingletonStateMachine.Instance.StartTouchPanel(); + MelonLoader.MelonLogger.Msg("[TouchResetAfterTrack] Touch panel reset"); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameMainObject), "Update")] + public static void OnGameMainObjectUpdate() + { + if (!KeyListener.GetKeyDownOrLongPress(key, longPress)) return; + SingletonStateMachine.Instance.StartTouchPanel(); + MessageHelper.ShowMessage(Locale.TouchPanelReset); + } +} \ No newline at end of file diff --git a/AquaMai/AquaMai.Mods/Tweaks/ResetTouchAfterTrack.cs b/AquaMai/AquaMai.Mods/Tweaks/ResetTouchAfterTrack.cs deleted file mode 100644 index e598f59c..00000000 --- a/AquaMai/AquaMai.Mods/Tweaks/ResetTouchAfterTrack.cs +++ /dev/null @@ -1,21 +0,0 @@ -using AquaMai.Config.Attributes; -using HarmonyLib; -using MAI2.Util; -using Manager; -using Process; - -namespace AquaMai.Mods.Tweaks; - -[ConfigSection( - en: "Reset touch panel after playing track.", - zh: "在游玩一首曲目后重置触摸面板")] -public class ResetTouchAfterTrack -{ - [HarmonyPostfix] - [HarmonyPatch(typeof(ResultProcess), "OnStart")] - public static void ResultProcessOnStart() - { - SingletonStateMachine.Instance.StartTouchPanel(); - MelonLoader.MelonLogger.Msg("[TouchResetAfterTrack] Touch panel reset"); - } -}