@@ -169,6 +177,7 @@
});
var isGame = true;
+ var isMultiplayer = false;
editCodeButton.addEventListener("click", function() {
window.pxtTickEvent('share.editcode', { target: "arcade" });
})
@@ -220,6 +229,13 @@
});
window.addEventListener('message', function (ev) {
+ if (ev.data && ev.data.type === "status" && ev.data.state === "running" && isMultiplayer) {
+ const iframe = document.getElementsByTagName("iframe").item(0);
+
+ if (iframe) {
+ setActivePlayer(1, iframe);
+ }
+ }
if (!shareLinkIsApproved)
return;
var d = ev.data;
@@ -240,6 +256,8 @@
}
});
+ initPresenceBar();
+
function prebuildSimulator(container) {
var sims = document.createElement("div");
sims.className = "sim-embed";
@@ -282,6 +300,8 @@
if (built.parts.indexOf("multiplayer") !== -1) {
window.pxtTickEvent('share.isMultiplayerGame', { target: "arcade" });
multiplayerShareButton.style.display = "block";
+ isMultiplayer = true;
+ document.getElementById("presence-bar").style.display = "block";
}
});
});
@@ -296,6 +316,35 @@
iframe.src = src;
return iframe;
}
+
+ function initPresenceBar() {
+ for (let i = 0; i < 4; i++) {
+ const button = document.getElementsByClassName("player-" + (i + 1)).item(0);
+ button.addEventListener("click", () => {
+ const iframe = document.getElementsByTagName("iframe").item(0);
+
+ if (iframe) {
+ setActivePlayer(i + 1, iframe);
+ iframe.focus();
+ }
+ });
+ }
+ }
+
+ function setActivePlayer(playerNumber, iframe) {
+ const setSlotMsg = {
+ type: "setactiveplayer",
+ playerNumber: playerNumber,
+ };
+ const connectionMsg = {
+ type: "multiplayer",
+ content: "Connection",
+ slot: playerNumber,
+ connected: true,
+ };
+ iframe.contentWindow.postMessage(setSlotMsg, "*");
+ iframe.contentWindow.postMessage(connectionMsg, "*");
+ }
})();