185 lines
6.2 KiB
C#
185 lines
6.2 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class JudgeManager : MonoBehaviour
|
||
{
|
||
public static JudgeManager Instance { get; private set; }
|
||
|
||
// ===== ԭ������ =====
|
||
private Dictionary<KeyCode, Queue<Note>> judgeQueues = new Dictionary<KeyCode, Queue<Note>>();
|
||
private Dictionary<string, bool> startJudgedNotes = new Dictionary<string, bool>();
|
||
private Dictionary<string, bool> releasedNotes = new Dictionary<string, bool>();
|
||
private Dictionary<string, float> noteEndTimes = new Dictionary<string, float>();
|
||
private Dictionary<string, int> middlePassedCounts = new Dictionary<string, int>();
|
||
|
||
// ===== ������������ȫ�ֻ���״̬ =====
|
||
private class HoldJudgeState
|
||
{
|
||
public bool startResolved; // Start �Ƿ��Ѿ��ж������ɹ� or ʧ�ܣ�
|
||
public bool endResolved; // End �Ƿ��Ѿ��ж���
|
||
public bool skillTriggered; // �����Ƿ��Ѵ���
|
||
}
|
||
|
||
private Dictionary<string, HoldJudgeState> holdStates = new Dictionary<string, HoldJudgeState>();
|
||
|
||
private HoldJudgeState GetHoldState(string noteID)
|
||
{
|
||
if (!holdStates.ContainsKey(noteID))
|
||
holdStates[noteID] = new HoldJudgeState();
|
||
return holdStates[noteID];
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
if (Instance == null) Instance = this;
|
||
else Destroy(gameObject);
|
||
}
|
||
|
||
// ===== �������ж�����բ�� =====
|
||
public bool TryResolveStart(string noteID)
|
||
{
|
||
var s = GetHoldState(noteID);
|
||
if (s.startResolved)
|
||
{
|
||
Debug.LogWarning($"[JudgeManager] TryResolveStart: already resolved start for {noteID}");
|
||
return false;
|
||
}
|
||
s.startResolved = true;
|
||
Debug.Log($"[JudgeManager] TryResolveStart: start resolved for {noteID} at time={Time.time:F3}");
|
||
return true;
|
||
}
|
||
|
||
public bool TryResolveEnd(string noteID)
|
||
{
|
||
var s = GetHoldState(noteID);
|
||
if (s.endResolved)
|
||
{
|
||
Debug.LogWarning($"[JudgeManager] TryResolveEnd: already resolved end for {noteID}");
|
||
return false;
|
||
}
|
||
s.endResolved = true;
|
||
Debug.Log($"[JudgeManager] TryResolveEnd: end resolved for {noteID} at time={Time.time:F3}");
|
||
return true;
|
||
}
|
||
|
||
public bool TryTriggerSkill(string noteID)
|
||
{
|
||
var s = GetHoldState(noteID);
|
||
if (s.skillTriggered)
|
||
{
|
||
Debug.LogWarning($"[JudgeManager] TryTriggerSkill: already triggered for {noteID}");
|
||
return false;
|
||
}
|
||
s.skillTriggered = true;
|
||
Debug.Log($"[JudgeManager] TryTriggerSkill: skill triggered for {noteID} at time={Time.time:F3}");
|
||
return true;
|
||
}
|
||
|
||
public void ClearHoldState(string noteID)
|
||
{
|
||
if (holdStates.ContainsKey(noteID))
|
||
{
|
||
holdStates.Remove(noteID);
|
||
Debug.Log($"[JudgeManager] ClearHoldState: cleared state for {noteID}");
|
||
}
|
||
}
|
||
|
||
// ===== ԭ�нӿڣ����ֲ��䣩 =====
|
||
|
||
public void RegisterScheduledEndTime(string noteID, float endTime)
|
||
{
|
||
noteEndTimes[noteID] = endTime;
|
||
Debug.Log($"[JudgeManager] RegisterScheduledEndTime: {noteID} -> {endTime:F3}");
|
||
}
|
||
|
||
public float GetScheduledEndTime(string noteID)
|
||
{
|
||
return noteEndTimes.ContainsKey(noteID) ? noteEndTimes[noteID] : 0f;
|
||
}
|
||
|
||
public void RegisterStartJudged(string noteID, bool state)
|
||
{
|
||
startJudgedNotes[noteID] = state;
|
||
Debug.Log($"[JudgeManager] RegisterStartJudged: {noteID} = {state} at time={Time.time:F3}");
|
||
}
|
||
|
||
public bool IsStartJudged(string noteID)
|
||
{
|
||
return startJudgedNotes.ContainsKey(noteID) && startJudgedNotes[noteID];
|
||
}
|
||
|
||
public void RegisterNoteReleased(string noteID, bool state)
|
||
{
|
||
releasedNotes[noteID] = state;
|
||
Debug.Log($"[JudgeManager] RegisterNoteReleased: {noteID} = {state}");
|
||
}
|
||
|
||
public bool HasNoteReleased(string noteID)
|
||
{
|
||
return releasedNotes.ContainsKey(noteID) && releasedNotes[noteID];
|
||
}
|
||
|
||
public void RegisterNote(KeyCode key, Note note)
|
||
{
|
||
if (!judgeQueues.ContainsKey(key))
|
||
judgeQueues[key] = new Queue<Note>();
|
||
|
||
if (!judgeQueues[key].Contains(note))
|
||
judgeQueues[key].Enqueue(note);
|
||
Debug.Log($"[JudgeManager] RegisterNote: key={key} note={note.name} time={Time.time:F3} queueSize={judgeQueues[key].Count}");
|
||
}
|
||
|
||
public void UnregisterNote(KeyCode key, Note note)
|
||
{
|
||
if (!judgeQueues.ContainsKey(key)) return;
|
||
|
||
Queue<Note> newQueue = new Queue<Note>();
|
||
while (judgeQueues[key].Count > 0)
|
||
{
|
||
Note n = judgeQueues[key].Dequeue();
|
||
if (n != note)
|
||
newQueue.Enqueue(n);
|
||
else if (!n.IsJudged())
|
||
n.JudgeMiss();
|
||
}
|
||
judgeQueues[key] = newQueue;
|
||
Debug.Log($"[JudgeManager] UnregisterNote: key={key} removed {note.name}, newQueueSize={judgeQueues[key].Count}");
|
||
}
|
||
|
||
public void JudgeEarliestNote(KeyCode key)
|
||
{
|
||
if (judgeQueues.ContainsKey(key) && judgeQueues[key].Count > 0)
|
||
{
|
||
Note note = judgeQueues[key].Dequeue();
|
||
if (note != null && !note.IsJudged())
|
||
{
|
||
Debug.Log($"[JudgeManager] JudgeEarliestNote: judging {note.name} for key={key} at time={Time.time:F3}");
|
||
note.Judge();
|
||
}
|
||
}
|
||
}
|
||
|
||
public void RegisterMiddlePassed(string noteID)
|
||
{
|
||
if (!middlePassedCounts.ContainsKey(noteID))
|
||
middlePassedCounts[noteID] = 0;
|
||
middlePassedCounts[noteID]++;
|
||
Debug.Log($"[JudgeManager] Middle passed for {noteID}, total={middlePassedCounts[noteID]}");
|
||
}
|
||
|
||
public int GetMiddlePassedCount(string noteID)
|
||
{
|
||
return middlePassedCounts.ContainsKey(noteID) ? middlePassedCounts[noteID] : 0;
|
||
}
|
||
|
||
public void ClearNoteRecord(string noteID)
|
||
{
|
||
startJudgedNotes.Remove(noteID);
|
||
releasedNotes.Remove(noteID);
|
||
noteEndTimes.Remove(noteID);
|
||
middlePassedCounts.Remove(noteID);
|
||
ClearHoldState(noteID);
|
||
Debug.Log($"[JudgeManager] ClearNoteRecord: cleared records for {noteID}");
|
||
}
|
||
}
|