-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
mergeInto(LibraryManager.library, { | ||
/** | ||
* @description Inserts a coin into the game by loading the required scripts and initializing the Playroom. | ||
* @param {function} callback - A callback function to execute after the Playroom is loaded. | ||
* @param {function} onLaunchCallBack - A callback function to execute after the Playroom is loaded. | ||
* @param {function} onQuitInternalCallback - (internal) This C# callback function calls an OnQuit wrapper on C# side, with the player's ID. | ||
*/ | ||
InsertCoinInternal: function ( | ||
callback, | ||
onLaunchCallBack, | ||
optionsJson, | ||
onJoinCallback, | ||
onQuitInternalCallback | ||
onQuitInternalCallback, | ||
// onLaunchCallback | ||
) { | ||
function embedScript(src) { | ||
return new Promise((resolve, reject) => { | ||
|
@@ -21,6 +22,9 @@ mergeInto(LibraryManager.library, { | |
}); | ||
} | ||
|
||
var options = optionsJson ? JSON.parse(UTF8ToString(optionsJson)) : {}; | ||
// console.log(options) | ||
|
||
Promise.all([ | ||
embedScript("https://unpkg.com/[email protected]/umd/react.development.js"), | ||
embedScript( | ||
|
@@ -36,13 +40,9 @@ mergeInto(LibraryManager.library, { | |
return; | ||
} | ||
|
||
console.info("Playroom has loaded."); | ||
|
||
var options = optionsJson ? JSON.parse(optionsJson) : {}; | ||
|
||
Playroom.insertCoin(options) | ||
.then(() => { | ||
dynCall("v", callback, []); | ||
dynCall("v", onLaunchCallBack, []); | ||
|
||
Playroom.onPlayerJoin((player) => { | ||
var id = player.id; | ||
|
@@ -65,6 +65,8 @@ mergeInto(LibraryManager.library, { | |
}); | ||
}, | ||
|
||
|
||
|
||
/** | ||
* @description Checks whether the player is the host of the game. | ||
* @returns {boolean} True if the local player is the host, otherwise false. | ||
|
@@ -639,5 +641,22 @@ mergeInto(LibraryManager.library, { | |
var buffer = _malloc(bufferSize); | ||
stringToUTF8(roomCode, buffer, bufferSize); | ||
return buffer; | ||
} | ||
}, | ||
|
||
OnDisconnect: function (callback) { | ||
if (!window.Playroom) { | ||
console.error( | ||
"Playroom library is not loaded. Please make sure to call InsertCoin first." | ||
); | ||
return; | ||
} | ||
|
||
Playroom.onDisconnect((e) => { | ||
console.log(`Disconnected!`, e.code, e.reason); | ||
dynCall("v", callback, []) | ||
}); | ||
|
||
}, | ||
|
||
|
||
}); |