From 53fd8594b605e22406f007c94145c75fbaf09489 Mon Sep 17 00:00:00 2001 From: momintlh <77355191+momintlh@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:02:33 +0500 Subject: [PATCH] fix: persistent mode to true if turnbased is true --- Assets/PlayroomKit/PlayroomKit.cs | 6 ++-- Assets/PlayroomKit/modules/Helpers/Helpers.cs | 1 - .../modules/Interfaces/IPlayroomBase.cs | 12 ++++---- .../BrowserMode/BrowserMockService.cs | 18 ++++++++++-- .../BrowserMode/PlayroomMockBrowserBridge.js | 9 ++++++ .../modules/MockMode/LocalPlayroomService.cs | 3 +- .../modules/PlayroomBuildService.cs | 29 +++++++++++++------ Assets/Scripts/GameManager.cs | 12 ++++---- 8 files changed, 60 insertions(+), 30 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index b03812c..524bb02 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -72,14 +72,12 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul _playroomService.InsertCoin(options, onLaunchCallBack, onDisconnectCallback); } - public void OnPlayerJoin(Action onPlayerJoinCallback) { CheckPlayRoomInitialized(); _playroomService.OnPlayerJoin(onPlayerJoinCallback); } - public bool IsHost() { CheckPlayRoomInitialized(); @@ -322,10 +320,10 @@ public void SaveMyTurnData(object data) _playroomService.SaveMyTurnData(data); } - public string GetMyTurnData() + public void GetMyTurnData(Action callback) { CheckPlayRoomInitialized(); - return _playroomService.GetMyTurnData(); + _playroomService.GetMyTurnData(callback); } public void GetAllTurns(Action callback) diff --git a/Assets/PlayroomKit/modules/Helpers/Helpers.cs b/Assets/PlayroomKit/modules/Helpers/Helpers.cs index 3166fd4..b27487a 100644 --- a/Assets/PlayroomKit/modules/Helpers/Helpers.cs +++ b/Assets/PlayroomKit/modules/Helpers/Helpers.cs @@ -35,7 +35,6 @@ public static string SerializeInitOptions(InitOptions options) node["avatars"] = avatarsArray; } - if (options.matchmaking is bool booleanMatchmaking) { diff --git a/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs b/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs index a10166e..03d0a15 100644 --- a/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs +++ b/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs @@ -56,15 +56,17 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul public void UnsubscribeOnQuit(); #region TurnBased + public string GetChallengeId(); - + public void SaveMyTurnData(object data); - - public string GetMyTurnData(); - + + public void GetMyTurnData(Action callback); + public void GetAllTurns(Action callback); - + public void ClearTurns(Action callback); + #endregion diff --git a/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockService.cs b/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockService.cs index 1bd8dff..236ed91 100644 --- a/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockService.cs +++ b/Assets/PlayroomKit/modules/MockMode/BrowserMode/BrowserMockService.cs @@ -207,12 +207,24 @@ public string GetChallengeId() public void SaveMyTurnData(object data) { - _ubb.CallJs("SaveMyTurnData", null, null, true, JsonUtility.ToJson(data)); + string jsonData; + + if (data is int || data is string || data is float) + { + jsonData = JSONNode.Parse(data.ToString()).ToString(); + } + else + { + jsonData = JsonUtility.ToJson(data); + } + + _ubb.CallJs("SaveMyTurnData", null, null, true, jsonData); } - public string GetMyTurnData() + public void GetMyTurnData(Action callback) { - return _ubb.CallJs("GetMyTurnData", null, null, true); + string data = _ubb.CallJs("GetMyTurnData", null, null, true); + callback.Invoke(data); } public void GetAllTurns(Action callback) diff --git a/Assets/PlayroomKit/modules/MockMode/BrowserMode/PlayroomMockBrowserBridge.js b/Assets/PlayroomKit/modules/MockMode/BrowserMode/PlayroomMockBrowserBridge.js index 1a4148c..768260f 100644 --- a/Assets/PlayroomKit/modules/MockMode/BrowserMode/PlayroomMockBrowserBridge.js +++ b/Assets/PlayroomKit/modules/MockMode/BrowserMode/PlayroomMockBrowserBridge.js @@ -285,16 +285,25 @@ GetChallengeId = function () { }; SaveMyTurnData = async function (data) { + + console.warn(`saving data ${data}`) + await Playroom.saveMyTurnData(data); }; GetAllTurns = async function () { const data = await Playroom.getAllTurns(); + + console.warn(`Getting All Turns ${data}`) + return JSON.stringify(data); }; GetMyTurnData = async function () { const data = await Playroom.getMyTurnData(); + + console.warn(`Getting My Turn Data ${data}`) + return JSON.stringify(data); }; diff --git a/Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs b/Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs index ec2975f..3d2af50 100644 --- a/Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs +++ b/Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs @@ -194,10 +194,9 @@ public void SaveMyTurnData(object data) DebugLogger.LogWarning("[MockMode] Turn based API is currently not supported in local mode!"); } - public string GetMyTurnData() + public void GetMyTurnData(Action callback) { DebugLogger.LogWarning("[MockMode] Turn based API is currently not supported in local mode!"); - return default; } public void GetAllTurns(Action callback) diff --git a/Assets/PlayroomKit/modules/PlayroomBuildService.cs b/Assets/PlayroomKit/modules/PlayroomBuildService.cs index 3cf2d41..ef3e29e 100644 --- a/Assets/PlayroomKit/modules/PlayroomBuildService.cs +++ b/Assets/PlayroomKit/modules/PlayroomBuildService.cs @@ -4,6 +4,7 @@ using SimpleJSON; using System; using System.Collections.Generic; +using OpenQA.Selenium.DevTools.V96.Browser; namespace Playroom { @@ -20,6 +21,7 @@ public PlayroomBuildService() { _interop = new PlayroomKitInterop(); } + public PlayroomBuildService(IInterop interop) { _interop = interop; @@ -46,6 +48,19 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul #endif } + // UNTESTED: + if (options.turnBased is true) + { + options.persistentMode = true; + } + else if (options.turnBased is TurnBasedOptions turnBasedOptions) + { + if (string.IsNullOrEmpty(turnBasedOptions.challengeId)) + { + options.persistentMode = true; + } + } + _interop.InsertCoinWrapper( optionsJson, InvokeInsertCoin, IPlayroomBase.__OnQuitInternalHandler, OnDisconnectCallbackHandler, InvokeOnErrorInsertCoin, onLaunchCallBackKey, onDisconnectCallBackKey); @@ -83,14 +98,14 @@ public void OnDisconnect(Action callback) } #endregion - + #region Unsubscribers public void UnsubscribeOnQuit() { _interop.UnsubscribeOnQuitWrapper(); } - + private void UnsubscribeOnPlayerJoin(string callbackID) { _interop.UnsubscribeOnPlayerJoinWrapper(callbackID); @@ -269,14 +284,14 @@ public void WaitForPlayerState(string playerID, string stateKey, Action WaitForPlayerCallback = onStateSetCallback; _interop.WaitForPlayerStateWrapper(playerID, stateKey, OnStateSetCallback); } - + public void ResetStates(string[] keysToExclude = null, Action onStatesReset = null) { _onStatesResetCallback = onStatesReset; string keysJson = keysToExclude != null ? Helpers.CreateJsonArray(keysToExclude).ToString() : null; _interop.ResetStatesWrapper(keysJson, InvokeResetCallBack); } - + public void ResetPlayersStates(string[] keysToExclude = null, Action onStatesReset = null) { _onStatesResetCallback = onStatesReset; @@ -284,8 +299,6 @@ public void ResetPlayersStates(string[] keysToExclude = null, Action onStatesRes _interop.ResetPlayersStatesWrapper(keysJson, InvokePlayersResetCallBack); } - - #endregion #region Joystick @@ -339,7 +352,7 @@ public void SaveMyTurnData(object data) throw new NotImplementedException(); } - public string GetMyTurnData() + public void GetMyTurnData(Action callback) { throw new NotImplementedException(); } @@ -404,10 +417,8 @@ private static void InvokeOnErrorInsertCoin(string error) _onError?.Invoke(error); Debug.LogException(new Exception(error)); } - #endregion - } } } \ No newline at end of file diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 4fb6748..1c6abc7 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -14,10 +14,8 @@ private void Start() { _kit.InsertCoin(new InitOptions() { - turnBased = new TurnBasedOptions() - { - challengeId = "123" - }, + turnBased = true, + persistentMode = true, maxPlayersPerRoom = 2, }, OnLaunchCallBack); } @@ -47,8 +45,10 @@ private void Update() if (Input.GetKeyDown(KeyCode.M)) { - string data = _kit.GetMyTurnData(); - Debug.Log($"Getting my turn data: {data}"); + _kit.GetMyTurnData((data) => + { + Debug.Log($"Getting my turn data: {data}"); + }); } if (Input.GetKeyDown(KeyCode.A))