Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion AquaMai.Mods/UX/OneKeyRetrySkip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@ public class OneKeyRetrySkip
[ConfigEntry("跳关长按")]
public static readonly bool skipLongPress = true;

[ConfigEntry(
name: "仅自由模式可重开",
en: "Only allow retry in Freedom Mode while time remains.",
zh: "仅在自由模式且时间未耗尽时允许一键重试,跳过不受影响")]
public static readonly bool allowRetryOnlyInFreedomMode = false;

private static bool dirty = false;

private static bool IsRetryAllowed()
{
if (!allowRetryOnlyInFreedomMode) return true;
return GameManager.IsFreedomMode && GameManager.GetFreedomModeMSec() > 0;
}

[HarmonyPostfix]
[HarmonyPatch(typeof(GameProcess), "OnStart")]
public static void PostGameProcessStart()
Expand Down Expand Up @@ -63,7 +75,8 @@ public static void PostGameProcessUpdate(GameProcess __instance, Message[] ____m
traverse.Method("SetRelease").GetValue();
}

else if (KeyListener.GetKeyDownOrLongPress(retryKey, retryLongPress) && GameInfo.GameVersion >= 23000)
else if (KeyListener.GetKeyDownOrLongPress(retryKey, retryLongPress) && GameInfo.GameVersion >= 23000 &&
IsRetryAllowed())
{
#if DEBUG
MelonLogger.Msg("[OneKeyRetrySkip] Retry key pressed.");
Expand Down
6 changes: 1 addition & 5 deletions AquaMai.Mods/UX/PracticeMode/Libs/PractiseModeUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ public void Update()
}
else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B8) || InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B1))
{
DebugFeature.Pause = !DebugFeature.Pause;
if (!DebugFeature.Pause)
{
PracticeMode.Seek(0);
}
PracticeMode.TogglePause();
}
else if (InputManager.GetTouchPanelAreaDown(InputManager.TouchPanelArea.B7) && PracticeMode.repeatStart == -1)
{
Expand Down
46 changes: 45 additions & 1 deletion AquaMai.Mods/UX/PracticeMode/PracticeMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,33 @@ public class PracticeMode
[ConfigEntry]
public static readonly bool longPress = false;

[ConfigEntry(
name: "仅自由模式可用",
en: "Only allow Practice Mode in Freedom Mode while time remains.",
zh: "仅在自由模式且时间未耗尽时允许使用练习模式")]
public static readonly bool onlyInFreedomMode = false;

public static double repeatStart = -1;
public static double repeatEnd = -1;
public static float speed = 1;
private static CriAtomExPlayer player;
private static List<MovieMaterialMai2> movie;
private static GameCtrl[] gameCtrl = new GameCtrl[2];
public static bool keepNoteSpeed = false;

private static void ClearPracticeEffects()
{
// 清除练习模式的所有效果。涉及的效果有五种:UI界面、循环、速度保持、速度、暂停。
if (ui != null)
{
UnityEngine.Object.Destroy(ui);
ui = null;
}
if (repeatStart >= 0 || repeatEnd >= 0) ClearRepeat();
keepNoteSpeed = false;
if (speed != 1f) SpeedReset();
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
if (DebugFeature.Pause) TogglePause();
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}
Comment on lines +53 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了简化更新循环中复杂的布尔逻辑,并保持与 OneKeyRetrySkip.cs 的代码结构一致,建议将练习模式的准入检查提取为辅助方法 IsPracticeAllowed()

    private static void ClearPracticeEffects()
    {
        // 清除练习模式的所有效果。涉及的效果有四种:UI界面、循环、速度、暂停。
        if (ui != null)
        {
            UnityEngine.Object.Destroy(ui);
            ui = null;
        }
        if (repeatStart >= 0 || repeatEnd >= 0) ClearRepeat();
        if (speed != 1f) SpeedReset();
        if (DebugFeature.Pause) TogglePause();
    }

    private static bool IsPracticeAllowed()
    {
        if (!onlyInFreedomMode) return true;
        return GameManager.IsFreedomMode && GameManager.GetFreedomModeMSec() > 0;
    }
References
  1. Avoid complex boolean logic in if statements if a simpler structure, such as multiple ifs or an if-else block, is more readable and easier to understand.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得必要性不强。没必要

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来只有一处用到这个逻辑,我觉得没事


public static void SetRepeatEnd(double time)
{
Expand All @@ -67,6 +87,15 @@ public static void ClearRepeat()
repeatEnd = -1;
}

public static void TogglePause()
{
DebugFeature.Pause = !DebugFeature.Pause;
if (!DebugFeature.Pause)
{
Seek(0);
}
}

public static void GameCtrlResetOptionSpeed()
{
foreach (var g in gameCtrl)
Expand Down Expand Up @@ -169,6 +198,8 @@ public static double CurrentPlayMsec

public static PracticeModeUI ui;

private static long prevFreedomModeMSec = -1; // 上一帧时,自由模式的剩余秒数

[HarmonyPatch]
public class PatchNoteSpeed
{
Expand All @@ -192,7 +223,9 @@ public static void GameProcessPostStart()
repeatStart = -1;
repeatEnd = -1;
speed = 1;
keepNoteSpeed = false;
ui = null;
prevFreedomModeMSec = GameManager.IsFreedomMode ? GameManager.GetFreedomModeMSec() : -1;
}

[HarmonyPatch(typeof(GameProcess), "OnRelease")]
Expand All @@ -202,7 +235,9 @@ public static void GameProcessPostRelease()
repeatStart = -1;
repeatEnd = -1;
speed = 1;
keepNoteSpeed = false;
ui = null;
Comment thread
Starrah marked this conversation as resolved.
prevFreedomModeMSec = -1;
}

[HarmonyPatch(typeof(GameCtrl), "Initialize")]
Expand All @@ -228,10 +263,19 @@ public static void OnGenericProcessUpdate(GenericMonitor[] ____monitors)
[HarmonyPostfix]
public static void GameProcessPostUpdate(GameProcess __instance, GameMonitor[] ____monitors)
{
if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null)
if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null &&
(!onlyInFreedomMode || (GameManager.IsFreedomMode && GameManager.GetFreedomModeMSec() > 0))) // onlyInFreedomMode=true情况,则额外检查是否在练习模式内、且时间有剩余,如果不满足则不开启UI。
{
ui = ____monitors[0].gameObject.AddComponent<PracticeModeUI>();
}
Comment on lines +266 to 270

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在此处使用新提取的 IsPracticeAllowed() 辅助方法,以简化 if 条件并提高代码可读性。

        if (KeyListener.GetKeyDownOrLongPress(key, longPress) && ui is null && IsPracticeAllowed())
        {
            ui = ____monitors[0].gameObject.AddComponent<PracticeModeUI>();
        }
References
  1. Avoid complex boolean logic in if statements if a simpler structure, such as multiple ifs or an if-else block, is more readable and easier to understand.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得必要性不强。没必要。现在代码可读性也不差


if (onlyInFreedomMode && GameManager.IsFreedomMode)
{
var currentFreedomModeMSec = GameManager.GetFreedomModeMSec();
if (prevFreedomModeMSec > 0 && currentFreedomModeMSec <= 0)
ClearPracticeEffects(); // 如果这一帧内、练习模式的时间刚好归零了:则清空练习模式的一切效果。
prevFreedomModeMSec = currentFreedomModeMSec;
}

if (repeatStart >= 0 && repeatEnd >= 0)
{
Expand Down
Loading