From d317ec9fd21ab0d2ade2076302e0d47330e72c7d Mon Sep 17 00:00:00 2001 From: HaeinLEE Date: Thu, 13 Mar 2025 14:04:29 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B8=B0=EB=B3=B4=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=20=ED=8C=8C=EC=9D=BC=EB=AA=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20LoadReplayDatas=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Script/Replay/ReplayManager.cs | 39 ++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Assets/Script/Replay/ReplayManager.cs b/Assets/Script/Replay/ReplayManager.cs index e508abc..d024256 100644 --- a/Assets/Script/Replay/ReplayManager.cs +++ b/Assets/Script/Replay/ReplayManager.cs @@ -59,28 +59,49 @@ public class ReplayManager : Singleton recordingReplayData.moves.Add(new Move(stoneColor, row, col)); } + /// /// 게임 종료 후 호출하여 리플레이 데이터를 저장합니다. - ///게임에서 승리한 플레이어를 플레이어 타입으로 알려주세요 /// - public void SaveReplayData(PlayerType winnerPlayerType) + public void SaveReplayData(string winnerPlayerType) { - string winnerPlayer = winnerPlayerType==PlayerType.PlayerA ? "PlayerA" : "PlayerB"; - - string time = DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")); + string time = DateTime.Now.ToString(("yyyy-MM-dd HH_mm_ss")); recordingReplayData.gameDate = time; - recordingReplayData.winnerPlayerType = winnerPlayer; + recordingReplayData.winnerPlayerType = winnerPlayerType; string json = JsonUtility.ToJson(recordingReplayData, true); - //TODO: 최신 10개로 유지하도록 수정 - string path = Path.Combine(Application.persistentDataPath, "game_record.json"); + string path = Path.Combine(Application.persistentDataPath, $"{time}.json"); File.WriteAllText(path, json); - + + //최신 데이터 10개만 유지되도록 저장 + RecordCountChecker(); Debug.Log("기보 저장 완료: " + path); } + + private List LoadReplayDatas() + { + List records = new List(); + string path = Application.persistentDataPath; + var files = Directory.GetFiles(path, "*.json"); + foreach (var file in files) + { + records.Add(JsonUtility.FromJson(File.ReadAllText(file))); + } + return records; + } + + private void RecordCountChecker() + { + string path = Application.persistentDataPath; + var files = Directory.GetFiles(path, "*.json"); + if (files.Length <= 10) + return; + File.Delete(files[0]); + RecordCountChecker(); + } protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode)