let multiplayer name be set in browser storage rather than fully anonymous

allow-name-for-anon-multiplayer
Dave Conway-Jones 2024-10-11 09:08:17 +01:00
parent 83acc4836b
commit d457c81547
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643
2 changed files with 8 additions and 5 deletions

View File

@ -164,7 +164,7 @@ RED.multiplayer = (function () {
$(this).show()
}
})
if (users.length < maxShown + 1) {
if (users.length < maxShown + 1) {
userCountIcon.hide()
} else {
userCountSpan.text('+'+(users.length - maxShown))
@ -365,12 +365,12 @@ RED.multiplayer = (function () {
border.setAttribute("r",radius/2);
border.setAttribute("class", "red-ui-multiplayer-annotation-border")
group.appendChild(border)
return group
}
RED.view.annotations.register("red-ui-multiplayer",{
type: 'badge',
align: 'left',
@ -411,7 +411,7 @@ RED.multiplayer = (function () {
// } else {
log('Session ID', activeSessionId)
// }
headerWidget = $('<li><ul id="red-ui-multiplayer-user-list"></ul></li>').prependTo('.red-ui-header-toolbar')
RED.comms.on('connect', () => {
@ -422,6 +422,9 @@ RED.multiplayer = (function () {
if (location.workspace !== 0) {
connectInfo.location = location
}
if (localStorage.getItem("multiplayer-name") !== undefined && localStorage.getItem("multiplayer-name").length >0) {
connectInfo.name = localStorage.getItem("multiplayer-name");
}
RED.comms.send('multiplayer/connect', connectInfo)
})
RED.comms.subscribe('multiplayer/#', (topic, msg) => {

View File

@ -42,7 +42,7 @@ module.exports = {
let user = opts.user
if (!user || user.anonymous) {
user = user || { anonymous: true }
user.username = `Anon ${Math.floor(Math.random()*100)}`
user.username = opts?.data?.name || `Anon ${Math.floor(Math.random()*100)}`
}
session = {
session: opts.data.session,