Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dynCall to makeDynCall #93

Merged
merged 10 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ node_modules
metaList
package-lock.json
package-lock.json.meta
Assets/Plugins
Assets/Plugins
Assets/PlayroomKit/node_modules.meta
/.idea
Assets/chromedriver*
8 changes: 0 additions & 8 deletions .idea/.idea.playroom-unity/.idea/indexLayout.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/.idea.playroom-unity/.idea/projectSettingsUpdater.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/.idea.playroom-unity/.idea/vcs.xml

This file was deleted.

146 changes: 0 additions & 146 deletions .idea/.idea.playroom-unity/.idea/workspace.xml

This file was deleted.

8 changes: 8 additions & 0 deletions Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1488774288987972495, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: webDriverDirectory
value: Assets/
objectReference: {fileID: 0}
- target: {fileID: 1488774288987972495, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: includeJavaScriptFiles.Array.data[0]
value: Playroomkit/modules/PlayroomMockBridge.js
objectReference: {fileID: 0}
- target: {fileID: 1957495583081457048, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: m_Name
value: PlayroomMockManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void Initialize()
PlayroomKit.InsertCoin(new PlayroomKit.InitOptions()
{
maxPlayersPerRoom = 2,

defaultPlayerStates = new() {
{"score", 0},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1429187865}
m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1}
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.5748165, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -287,6 +287,14 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1488774288987972495, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: webDriverDirectory
value: Assets/
objectReference: {fileID: 0}
- target: {fileID: 1488774288987972495, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: includeJavaScriptFiles.Array.data[0]
value: Playroomkit/modules/PlayroomMockBridge.js
objectReference: {fileID: 0}
- target: {fileID: 1957495583081457048, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: m_Name
value: PlayroomMockManager
Expand Down
19 changes: 19 additions & 0 deletions Assets/PlayroomKit/modules/MockModeBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ private static void MockOnPlayerJoinBrowser(Action<Player> onPlayerJoinCallback)
UnityBrowserBridge.Instance.ExecuteJS($"OnPlayerJoin('{gameObjectName}')");
#endif
}

private static void MockOnPlayerQuitBrowser(Action<Player> onPlayerJoinCallback)
{
if (!OnPlayerJoinCallbacks.Contains(onPlayerJoinCallback)) OnPlayerJoinCallbacks.Add(onPlayerJoinCallback);

var gameObjectName = GetGameObject("devManager").name;

#if UNITY_EDITOR
UnityBrowserBridge.Instance.ExecuteJS($"OnPlayerQuit('{gameObjectName}')");
#endif
}

private static void MockOnPlayerQuitLocal(Action<string> onPlayerQuitCallback)
{
Debug.Log("On Player Quit");
var testPlayer = GetPlayer(PlayerId);
testPlayer.OnQuitCallbacks.Add(onPlayerQuitCallback);
__OnQuitInternalHandler(PlayerId);
}

/// <summary>
/// This function is used by GetPlayerID in PlayroomKitDevManager, GetPlayer is only invoked
Expand Down
33 changes: 17 additions & 16 deletions Assets/PlayroomKit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ mergeInto(LibraryManager.library, {
onLaunchCallBackKey = UTF8ToString(onLaunchCallBackKey);
onQuitInternalCallbackKey = UTF8ToString(onQuitInternalCallbackKey);


function OnLaunchCallBack() {
var key = _ConvertString(onLaunchCallBackKey);
dynCall("vi", onLaunchCallBack, [key]);
{{{ makeDynCall('vi', 'onLaunchCallBack') }}}(key)
}

function OnDisconnectCallback() {
var key = _ConvertString(onQuitInternalCallbackKey);
dynCall("vi", onDisconnectCallback, [key]);
{{{ makeDynCall('vi', 'onDisconnectCallback') }}}(key)
}
this.onPlayerJoinCallBacks = {};
var options = optionsJson ? JSON.parse(UTF8ToString(optionsJson)) : {};
Expand All @@ -44,7 +45,7 @@ mergeInto(LibraryManager.library, {
stringToUTF8(id, buffer, bufferSize);

player.onQuit(() => {
dynCall("vi", onQuitInternalCallback, [buffer]);
{{{ makeDynCall('vi', 'onQuitInternalCallback') }}}(buffer)
});
});
})
Expand All @@ -53,7 +54,7 @@ mergeInto(LibraryManager.library, {
var bufferSize = lengthBytesUTF8(jsonString) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(jsonString, buffer, bufferSize);
dynCall("vi", onError, [buffer]);
{{{ makeDynCall('vi','onError') }}}(buffer)
});
},

Expand Down Expand Up @@ -139,8 +140,8 @@ mergeInto(LibraryManager.library, {
var bufferSize = lengthBytesUTF8(id) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(id, buffer, bufferSize);

dynCall("vi", functionPtr, [buffer]);
{{{ makeDynCall('vi', 'functionPtr') }}}(buffer)
});
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -701,7 +702,7 @@ mergeInto(LibraryManager.library, {

Playroom.onDisconnect((e) => {
console.log(`Disconnected!`, e.code, e.reason);
dynCall("v", callback, []);
{{{ makeDynCall('v', 'callback') }}}()
});
},

Expand All @@ -720,8 +721,8 @@ mergeInto(LibraryManager.library, {
stateVal = JSON.stringify(stateVal);

var key = _ConvertString(stateKey);

dynCall("vii", onStateSetCallback, [key, stringToNewUTF8(stateVal)]);
{{{ makeDynCall('vii', 'onStateSetCallback') }}}(key, stringToNewUTF8(stateVal))
})
.catch((error) => {
console.error("Error Waiting for state:", error);
Expand Down Expand Up @@ -757,7 +758,7 @@ mergeInto(LibraryManager.library, {
stateKey = UTF8ToString(stateKey);
Playroom.waitForPlayerState(playerState, stateKey)
.then(() => {
dynCall("v", onStateSetCallback, []);
{{{ makeDynCall('v', 'onStateSetCallback') }}}()
})
.catch((error) => {
console.error("Error waiting for state:", error);
Expand Down Expand Up @@ -789,7 +790,7 @@ mergeInto(LibraryManager.library, {
playerState
.kick()
.then(() => {
dynCall("v", onKickCallBack, []);
{{{ makeDynCall('v', 'onKickCallback') }}}()
})
.catch((error) => {
console.error("Error kicking player:", error);
Expand All @@ -807,7 +808,7 @@ mergeInto(LibraryManager.library, {
var keys = keysToExclude ? JSON.parse(UTF8ToString(keysToExclude)) : [];
Playroom.resetStates(keys)
.then(() => {
dynCall("v", onStatesReset, []);
{{{ makeDynCall('v', 'onStatesReset') }}}()
})
.catch((error) => {
console.error("Error resetting states:", error);
Expand All @@ -826,7 +827,7 @@ mergeInto(LibraryManager.library, {
var keys = keysToExclude ? JSON.parse(UTF8ToString(keysToExclude)) : [];
Playroom.resetPlayersStates(keys)
.then(() => {
dynCall("v", onStatesReset, []);
{{{ makeDynCall('v', 'onStatesReset') }}}()
})
.catch((error) => {
console.error("Error resetting players states:", error);
Expand All @@ -852,7 +853,7 @@ mergeInto(LibraryManager.library, {
var buffer = _malloc(bufferSize);
stringToUTF8(id, buffer, bufferSize);

dynCall("vii", callback, [stringToNewUTF8(dataJson), buffer]);
{{{ makeDynCall('vii', 'callback') }}}(stringToNewUTF8(dataJson), buffer)

return onResponseReturn;
}
Expand Down Expand Up @@ -885,7 +886,7 @@ mergeInto(LibraryManager.library, {

function onResponseCallback(responseData) {
console.log("Response received: ", responseData);
dynCall("v", callbackOnResponse, []);
{{{ makeDynCall('v', 'callbackOnResponse') }}}()
}

Playroom.RPC.call(UTF8ToString(name), data, mode, onResponseCallback);
Expand All @@ -905,7 +906,7 @@ mergeInto(LibraryManager.library, {
Playroom.startMatchmaking()
.then(() => {
console.log(`Player has joined a public room`);
dynCall("v", callback, []);
{{{ makeDynCall('v', 'callback') }}}()
})
.catch((error) => {
console.error(`JS: Error starting match making ${error}`);
Expand Down
Binary file removed Assets/chromedriver.exe
Binary file not shown.
7 changes: 0 additions & 7 deletions Assets/chromedriver.exe.meta

This file was deleted.

Loading