Skip to content

Commit

Permalink
Merge pull request #45 from asadm/MatchMaking
Browse files Browse the repository at this point in the history
Update: Matchmaking
  • Loading branch information
SaadBazaz authored Feb 26, 2024
2 parents 7c2c059 + 07e7a95 commit b0befb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public class InitOptions
public Dictionary<string, object> defaultStates = null;
public Dictionary<string, object> defaultPlayerStates = null;

public bool matchmaking = false;

}

public class MatchMakingOptions
{
public int waitBeforeCreatingNewRoom = 5000;
}

private static Action InsertCoinCallback = null;
Expand Down Expand Up @@ -123,6 +130,8 @@ private static string SerializeInitOptions(InitOptions options)
node["skipLobby"] = options.skipLobby;
node["reconnectGracePeriod"] = options.reconnectGracePeriod;

node["matchmaking"] = options.matchmaking;

if (options.maxPlayersPerRoom.HasValue)
{
node["maxPlayersPerRoom"] = options.maxPlayersPerRoom.Value;
Expand Down Expand Up @@ -1136,6 +1145,8 @@ private static string ConvertComplexToJson(object data)
}
}

[DllImport("__Internal")]
public static extern void StartMatchMaking();

// Player class
public class Player
Expand Down
13 changes: 12 additions & 1 deletion Assets/Plugins/PlayroomPlugin.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,18 @@ mergeInto(LibraryManager.library, {
},


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


Playroom.startMatchmaking().then(() => {
console.log(`Player has joined a public room`);
}).catch(error => {
console.error(
`JS: Error starting match making ${error}`)
});
},

});
2 changes: 2 additions & 0 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private void Awake()
PlayroomKit.InsertCoin(new PlayroomKit.InitOptions()
{
maxPlayersPerRoom = 2,
matchmaking = true,
defaultPlayerStates = new() {
{"score", -500},
},
Expand All @@ -41,6 +42,7 @@ private void Awake()
PlayroomKit.OnPlayerJoin(AddPlayer);
});


}

void Start()
Expand Down

0 comments on commit b0befb4

Please sign in to comment.