Skip to content

Commit

Permalink
ResetStates and ResetPlayersStates
Browse files Browse the repository at this point in the history
  • Loading branch information
momintlh committed Jan 17, 2024
1 parent 2cb4ba7 commit 2a57fb7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public void WaitForPlayerState(string playerID, string StateKey, Action onStateS

[MonoPInvokeCallback(typeof(Action))]
void OnStateSetCallback()
{
{
Callback?.Invoke();
}

Expand Down Expand Up @@ -701,6 +701,12 @@ private static Dictionary<string, T> ParseJsonToDictionary<T>(string jsonString)
return dictionary;
}

[DllImport("__Internal")]
public static extern void ResetStates(string[] keysToExclude = null, Action OnStatesReset = null);

[DllImport("__Internal")]
public static extern void ResetPlayersStates(string[] keysToExclude, Action OnPlayersStatesReset = null);


// it checks if the game is running in the browser or in the editor
public static bool IsRunningInBrowser()
Expand Down
29 changes: 27 additions & 2 deletions Assets/Plugins/PlayroomPlugin.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mergeInto(LibraryManager.library, {
optionsJson,
onJoinCallback,
onQuitInternalCallback,
// onLaunchCallback
) {
function embedScript(src) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -736,8 +735,34 @@ mergeInto(LibraryManager.library, {
console.error("Error kicking player:", error);
});

}
},

ResetStates: function (keysToExclude, onStatesReset) {
if (!window.Playroom) {
console.error("Playroom library is not loaded. Please make sure to call InsertCoin first.");
reject("Playroom library not loaded");
return;
}

Playroom.resetStates(keysToExclude).then(() => {
dynCall('v', onStatesReset, [])
}).catch((error) => {
console.error("Error reseting states:", error);
});
},

ResetPlayersStates: function (keysToExclude, onPlayersStatesReset) {
if (!window.Playroom) {
console.error("Playroom library is not loaded. Please make sure to call InsertCoin first.");
reject("Playroom library not loaded");
return;
}

Playroom.resetPlayersStates(keysToExclude).then(() => {
dynCall('v', onPlayersStatesReset, [])
}).catch((error) => {
console.error("Error reseting players states:", error);
});
},

});

0 comments on commit 2a57fb7

Please sign in to comment.