Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add partyToggleInfo() to hide the info panel
- Loading branch information
Showing
13 changed files
with
224 additions
and
67 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# info_panel |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<head> | ||
<link rel="stylesheet" href="../sketch.css" /> | ||
</head> | ||
</head> | ||
<body> | ||
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.1/lib/p5.js"></script> | ||
|
||
<script src="/dist/p5.party.js"></script> | ||
|
||
<script src="index.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
let shared; | ||
|
||
function preload() { | ||
partyConnect("wss://deepstream-server-1.herokuapp.com", "info_panel", "main"); | ||
shared = partyLoadShared("shared"); | ||
} | ||
|
||
function setup() { | ||
createCanvas(400, 400); | ||
noStroke(); | ||
|
||
// set defaults on shared data | ||
if (partyIsHost()) { | ||
partySetShared(shared, { | ||
x: 0, | ||
y: 0, | ||
}); | ||
} | ||
|
||
partyToggleInfo(false); // pass false to hide | ||
|
||
createButton("Toggle Info").mousePressed(() => { | ||
partyToggleInfo(); // pass nothing to toggle | ||
}); | ||
|
||
createButton("Show Info").mousePressed(() => { | ||
partyToggleInfo(true); // pass true to show | ||
}); | ||
|
||
createButton("Hide Info").mousePressed(() => { | ||
partyToggleInfo(false); // pass true to show | ||
}); | ||
} | ||
|
||
function mousePressed() { | ||
// write shared data | ||
shared.x = mouseX; | ||
shared.y = mouseY; | ||
} | ||
|
||
function draw() { | ||
background("#ffcccc"); | ||
fill("#000066"); | ||
|
||
// read shared data | ||
ellipse(shared.x, shared.y, 100, 100); | ||
} |
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,40 +1,51 @@ | ||
#party-debug { | ||
#party-info { | ||
font-family: monospace; | ||
font-size: 12px; | ||
|
||
background-color: #ffcccc; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
|
||
display: none; | ||
} | ||
|
||
#party-info.show { | ||
display: block; | ||
} | ||
#party-debug div { | ||
|
||
#party-info div { | ||
padding: 10px; | ||
} | ||
#party-debug .app { | ||
#party-info .app { | ||
background-color: #ffffcc; | ||
} | ||
#party-debug .room { | ||
#party-info .room { | ||
background-color: #ffffcc; | ||
} | ||
#party-debug .participant { | ||
#party-info .id { | ||
background-color: #ffffcc; | ||
} | ||
|
||
#party-info .participant { | ||
background-color: #ccccff; | ||
} | ||
#party-debug .host::after { | ||
#party-info .host::after { | ||
content: " « host"; | ||
} | ||
#party-debug .me::after { | ||
#party-info .me::after { | ||
content: " « me"; | ||
} | ||
#party-debug .host.me::after { | ||
#party-info .host.me::after { | ||
content: " « host+me"; | ||
} | ||
#party-debug .missing { | ||
#party-info .missing { | ||
color: rgba(0, 0, 0, 0.3); | ||
} | ||
|
||
#party-debug .label { | ||
#party-info .label { | ||
background-color: #ccffcc; | ||
} | ||
#party-debug .record { | ||
#party-info .record { | ||
background-color: #ccffff; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// eslint-disable-next-line | ||
import css from "./InfoPanel.css"; | ||
|
||
const UPDATE_MS = 100; | ||
|
||
export class InfoPanel { | ||
#client; | ||
#room; | ||
#el; | ||
|
||
constructor(client, room) { | ||
this.#client = client; | ||
this.#room = room; | ||
this.#el = createInfoPanelElement(); | ||
|
||
this.#room.whenReady(this.#startUpdates.bind(this)); | ||
} | ||
|
||
toggle(show) { | ||
this.#el.classList.toggle("show", show); | ||
} | ||
|
||
#startUpdates() { | ||
setInterval(this.#update.bind(this), UPDATE_MS); | ||
} | ||
|
||
#update() { | ||
// collect info | ||
const onlineClients = this.#client.getAllClients(); | ||
const data = this.#room._panelData(); | ||
const isHost = this.#room.getHostName() === this.#client.getUid(); | ||
|
||
// generate output | ||
// const output = ""; | ||
this.#el.innerHTML = ""; | ||
|
||
const appendDiv = (content, ...classes) => { | ||
const el = document.createElement("div"); | ||
const cleaned_classes = classes.filter((n) => n); // remove empty strings | ||
el.classList.add(...cleaned_classes); | ||
el.innerHTML = content; | ||
this.#el.appendChild(el); | ||
return el; | ||
}; | ||
|
||
// header info | ||
appendDiv("p5.party info", "label"); | ||
appendDiv(data.appName, "app"); | ||
appendDiv(data.roomName, "room"); | ||
const shortName = this.#client.getUid().substr(-4); | ||
const host = isHost ? "host" : ""; | ||
appendDiv(shortName, "id", host); | ||
|
||
// participant info | ||
appendDiv("Participants", "label"); | ||
for (const name of data.participantUids) { | ||
const shortName = name.substr(-4); | ||
const host = this.#room.getHostName() === name ? "host" : ""; | ||
const missing = onlineClients.includes(name) ? "" : "missing"; | ||
const me = this.#client.getUid() === name ? "me" : ""; | ||
appendDiv(shortName, "participant", host, missing, me); | ||
} | ||
|
||
// shared objects | ||
appendDiv("Shared Objects", "label"); | ||
for (const entry of data.recordDsList.getEntries()) { | ||
const name = entry.split("/")[1]; | ||
appendDiv(`"${name}"`, "record"); | ||
} | ||
|
||
// output += `<div class="label">#participantRecords</div>`; | ||
// // get keys from #participantRecords | ||
// const keys = Object.keys(data.participantRecords); | ||
// for (const key of keys) { | ||
// output += `<div class="record">${key}</div>`; | ||
// } | ||
|
||
// this.#el.innerHTML = output; | ||
} | ||
} | ||
|
||
// add a child div to parent with provided classes and content | ||
|
||
function createInfoPanelElement() { | ||
let el = document.getElementById("party-info"); | ||
if (!el) { | ||
el = document.createElement("div"); | ||
el.id = "party-info"; | ||
document.body.appendChild(el); | ||
} | ||
return el; | ||
} |
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
Oops, something went wrong.