Skip to content

Commit

Permalink
[O] ResetTouchAfterTrack -> ResetTouch, add press key to reset
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Nov 28, 2024
1 parent 8a728ad commit bca22d2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 23 deletions.
8 changes: 6 additions & 2 deletions AquaMai/AquaMai.Config/Migration/ConfigMigrationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class ConfigMigrationManager : IConfigMigrationManager
private readonly Dictionary<string, IConfigMigration> migrationMap =
new List<IConfigMigration>
{
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; }
Expand All @@ -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;
}

Expand All @@ -52,7 +55,8 @@ public string GetVersion(IConfigView config)
{
return version;
}

// Assume v1.0 if not found
return "1.0";
}
}
}
28 changes: 28 additions & 0 deletions AquaMai/AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs
Original file line number Diff line number Diff line change
@@ -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<bool>("Tweaks.ResetTouchAfterTrack"))
{
dst.SetValue("Tweaks.ResetTouch.AfterTrack", true);
dst.SetValue("Tweaks.ResetTouchAfterTrack", null);
}

return dst;
}
}
1 change: 1 addition & 0 deletions AquaMai/AquaMai.Config/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 9 additions & 0 deletions AquaMai/AquaMai.Core/Resources/Locale.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AquaMai/AquaMai.Core/Resources/Locale.resx
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@
<data name="PlaylogSaveError" xml:space="preserve">
<value>Playlog save error</value>
</data>
<data name="TouchPanelReset" xml:space="preserve">
<value>Touch panel reset</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AquaMai/AquaMai.Core/Resources/Locale.zh.resx
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,7 @@
<data name="PlaylogSaveError" xml:space="preserve">
<value>保存 Playlog 失败</value>
</data>
<data name="TouchPanelReset" xml:space="preserve">
<value>触摸面板已重置</value>
</data>
</root>
2 changes: 2 additions & 0 deletions AquaMai/AquaMai.Mods/GameSystem/TestProof.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =>
Expand Down
43 changes: 43 additions & 0 deletions AquaMai/AquaMai.Mods/Tweaks/ResetTouch.cs
Original file line number Diff line number Diff line change
@@ -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<AmManager, AmManager.EState>.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<AmManager, AmManager.EState>.Instance.StartTouchPanel();
MessageHelper.ShowMessage(Locale.TouchPanelReset);
}
}
21 changes: 0 additions & 21 deletions AquaMai/AquaMai.Mods/Tweaks/ResetTouchAfterTrack.cs

This file was deleted.

0 comments on commit bca22d2

Please sign in to comment.