Skip to content

Commit

Permalink
feat: new signatures for persistence api
Browse files Browse the repository at this point in the history
  • Loading branch information
momintlh committed Jan 23, 2025
1 parent 0406580 commit d5d6d3c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class GameManagerDemo : MonoBehaviour

private PlayroomKit _playroomKit = new();


[Serializable]
private class TempData
{
Expand Down
17 changes: 13 additions & 4 deletions Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul
public Player Me();

public bool IsHost();

public void TransferHost(string playerId);

public string GetRoomCode();
Expand All @@ -32,10 +32,14 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul
public void SetState<T>(string key, T value, bool reliable = false);

public T GetState<T>(string key);

public void SetPersistentData<T>(string key, T value);
public T GetPersistentData<T>(string key);

public void OnDisconnect(Action callback);

public bool IsStreamScreen();


public void WaitForState(string stateKey, Action<string> onStateSetCallback = null);

Expand All @@ -51,6 +55,9 @@ public void InsertCoin(InitOptions options = null, Action onLaunchCallBack = nul

public void UnsubscribeOnQuit();


#region Callbacks Wrappers

[MonoPInvokeCallback(typeof(Action<string>))]
protected static void __OnPlayerJoinCallbackHandler(string id)
{
Expand All @@ -65,14 +72,14 @@ protected static void OnPlayerJoinWrapperCallback(string id)
callback?.Invoke(player);
}
}


[MonoPInvokeCallback(typeof(Action<string, string>))]
protected static void InvokeCallback(string stateKey, string stateVal)
{
CallbackManager.InvokeCallback(stateKey, stateVal);
}

[MonoPInvokeCallback(typeof(Action<string>))]
internal static void __OnQuitInternalHandler(string playerId)
{
Expand All @@ -85,6 +92,8 @@ internal static void __OnQuitInternalHandler(string playerId)
Debug.LogError("[__OnQuitInternalHandler] Couldn't find player with id " + playerId);
}
}

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void StartMatchmaking(Action callback = null)
_ubb.CallJs("StartMatchmaking", null, null, true);
callback?.Invoke();
}

public void OnDisconnect(Action callback)
{
string key = Guid.NewGuid().ToString();
Expand Down Expand Up @@ -127,6 +127,16 @@ public T GetState<T>(string key)
return _ubb.CallJs<T>("GetState", null, null, false, key);
}

public void SetPersistentData<T>(string key, T value)
{
_ubb.CallJs<T>("GetState", null, null, false, key);
}

public T GetPersistentData<T>(string key)
{
throw new NotImplementedException();
}

public void WaitForState(string stateKey, Action<string> onStateSetCallback = null)
{
string callbackKey = $"WaitForState_{stateKey}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OnPlayerJoin = function (gameObjectName) {
unityInstance.SendMessage(gameObjectName, "GetPlayerID", player.id);
player.onQuit((state) => {
unityInstance.SendMessage(gameObjectName, "OnQuitPlayer", player.id);
})
});
});
};

Expand Down Expand Up @@ -229,8 +229,8 @@ ResetStates = async function (keysToExclude) {
await Playroom.resetStates(keysToExclude);
};

//#region RPC
RpcRegister = function (name, callbackKey) {

Playroom.RPC.register(name, (data, caller) => {
const jsonData = {
key: callbackKey,
Expand Down Expand Up @@ -261,4 +261,15 @@ RpcCall = function (name, data, rpcMode) {
}

Playroom.RPC.call(name, data, mode);
};
};
//#endregion

//#region Persistence
SetPersistentData = async function(key, value) {
await Playroom.setPersistentData(key, value)
}

GetPersistentData = async function(key, value) {
return await Playroom.getPersistentData(key, value)
}
//#endregion
10 changes: 10 additions & 0 deletions Assets/PlayroomKit/modules/MockMode/LocalPlayroomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public T GetState<T>(string key)
}
}

public void SetPersistentData<T>(string key, T value)
{
throw new NotImplementedException();
}

public T GetPersistentData<T>(string key)
{
throw new NotImplementedException();
}

public void OnDisconnect(Action callback)
{
callback?.Invoke();
Expand Down
2 changes: 2 additions & 0 deletions Assets/PlayroomKit/modules/Options/InitOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class InitOptions
[CanBeNull]
public string gameId;
public bool discord = false;

public bool persistentMode = false;

public Dictionary<string, object> defaultStates = null;
public Dictionary<string, object> defaultPlayerStates = null;
Expand Down
9 changes: 9 additions & 0 deletions Assets/PlayroomKit/modules/PlayroomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ public T GetState<T>(string key)
}
}

public void SetPersistentData<T>(string key, T value)
{
throw new NotImplementedException();
}

public T GetPersistentData<T>(string key)
{
throw new NotImplementedException();
}

[MonoPInvokeCallback(typeof(Action))]
private static void InvokeStartMatchmakingCallback()
Expand Down

0 comments on commit d5d6d3c

Please sign in to comment.