2021-03-14 20:55:23 -04:00
|
|
|
const { LitElement, html, css } = require('lit-element')
|
|
|
|
|
|
|
|
class PlayerList extends LitElement {
|
|
|
|
static get styles () {
|
|
|
|
return css`
|
|
|
|
.playerlist-container {
|
|
|
|
position: absolute;
|
|
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
|
|
left: 50%;
|
|
|
|
top: 10%;
|
|
|
|
transform: translateX(-50%);
|
|
|
|
border: 2px solid rgba(0, 0, 0, 0.8);
|
|
|
|
padding: 10px;
|
|
|
|
min-width: 8%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.playerlist-entry {
|
|
|
|
overflow: hidden;
|
|
|
|
color: white;
|
|
|
|
font-size: 20px;
|
|
|
|
margin: 0px;
|
|
|
|
line-height: 100%;
|
|
|
|
text-shadow: 2px 2px 0px #3f3f3f;
|
|
|
|
font-family: mojangles, minecraft, monospace;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.plist-active-player {
|
|
|
|
color: rgb(42, 204, 237);
|
|
|
|
}
|
|
|
|
|
|
|
|
.plist-ping-container {
|
|
|
|
text-align: right;
|
|
|
|
float: right;
|
|
|
|
padding-left: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.plist-ping-value {
|
|
|
|
color: rgb(114, 255, 114);
|
|
|
|
float: left;
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.plist-ping-label {
|
|
|
|
color: white;
|
|
|
|
float: right;
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2021-03-16 04:45:39 -04:00
|
|
|
static get properties () {
|
|
|
|
return {
|
|
|
|
clientId: { type: String },
|
|
|
|
players: { type: Object }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
super()
|
|
|
|
this.clientId = ''
|
|
|
|
this.players = {}
|
|
|
|
}
|
|
|
|
|
2021-03-14 20:55:23 -04:00
|
|
|
render () {
|
|
|
|
return html`
|
|
|
|
<div id="playerlist-container" class="playerlist-container" style="display: none;">
|
2021-03-16 04:45:39 -04:00
|
|
|
${Object.values(this.players).map(player => html`
|
|
|
|
<div class="playerlist-entry${this.clientId === player.uuid ? ' plist-active-player' : ''}" id="plist-player-${player.uuid}">
|
|
|
|
${player.username}
|
|
|
|
<div class="plist-ping-container">
|
|
|
|
<p class="plist-ping-value">${player.ping}</p>
|
|
|
|
<p class="plist-ping-label">ms</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`)}
|
2021-03-14 20:55:23 -04:00
|
|
|
</div>
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
init (bot) {
|
|
|
|
const playerList = this.shadowRoot.querySelector('#playerlist-container')
|
|
|
|
|
|
|
|
this.isOpen = false
|
2021-03-16 04:45:39 -04:00
|
|
|
this.players = bot.players
|
|
|
|
this.clientId = bot.player.uuid
|
|
|
|
|
|
|
|
this.requestUpdate()
|
2021-03-14 20:55:23 -04:00
|
|
|
|
2021-03-15 13:28:40 -04:00
|
|
|
const showList = (shouldShow = true) => {
|
|
|
|
playerList.style.display = shouldShow ? 'block' : 'none'
|
|
|
|
this.isOpen = shouldShow
|
|
|
|
}
|
2021-03-14 20:55:23 -04:00
|
|
|
|
2021-03-15 22:16:37 -04:00
|
|
|
document.addEventListener('keydown', e => {
|
2021-03-15 13:28:40 -04:00
|
|
|
e ??= window.event
|
2021-03-14 20:55:23 -04:00
|
|
|
if (e.key === 'Tab') {
|
|
|
|
showList(true)
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
2021-03-15 22:16:37 -04:00
|
|
|
})
|
2021-03-14 20:55:23 -04:00
|
|
|
|
2021-03-15 22:16:37 -04:00
|
|
|
document.addEventListener('keyup', e => {
|
2021-03-15 13:28:40 -04:00
|
|
|
if (!this.isOpen) return
|
|
|
|
e ??= window.event
|
2021-03-14 20:55:23 -04:00
|
|
|
if (e.key === 'Tab') {
|
|
|
|
showList(false)
|
|
|
|
e.preventDefault()
|
|
|
|
}
|
2021-03-15 22:16:37 -04:00
|
|
|
})
|
2021-03-14 20:55:23 -04:00
|
|
|
|
2021-03-16 04:45:39 -04:00
|
|
|
bot.on('playerUpdated', () => this.requestUpdate()) // LitElement seems to be batching requests, so it should be fine?
|
|
|
|
bot.on('playerJoined', () => this.requestUpdate())
|
|
|
|
bot.on('playerLeft', () => this.requestUpdate())
|
2021-03-14 20:55:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.customElements.define('player-list', PlayerList)
|