2022-08-13 12:40:42 +02:00
|
|
|
|
import * as Enum from "./Enums.js";
|
|
|
|
|
|
|
|
|
|
export class HUD {
|
|
|
|
|
#game
|
2022-10-11 16:55:14 +02:00
|
|
|
|
#cursor
|
2022-08-13 12:40:42 +02:00
|
|
|
|
#setting = {
|
2022-10-07 15:44:35 +02:00
|
|
|
|
showScore: false,
|
|
|
|
|
showBuyMenu: false
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
#elements = {
|
|
|
|
|
score: null,
|
2022-10-05 20:08:33 +02:00
|
|
|
|
scoreDetail: null,
|
2022-10-07 15:44:35 +02:00
|
|
|
|
buyMenu: null,
|
2022-10-09 17:40:06 +02:00
|
|
|
|
canBuyIcon: null,
|
2022-08-13 12:40:42 +02:00
|
|
|
|
equippedItem: null,
|
|
|
|
|
slotModel: null,
|
2022-10-12 13:48:22 +02:00
|
|
|
|
shotModel: null,
|
2022-08-13 12:40:42 +02:00
|
|
|
|
inventory: null,
|
|
|
|
|
money: null,
|
|
|
|
|
health: null,
|
|
|
|
|
armor: null,
|
2022-10-04 19:45:10 +02:00
|
|
|
|
ammo: null,
|
2022-08-13 12:40:42 +02:00
|
|
|
|
messageTop: null,
|
|
|
|
|
messageBottom: null,
|
|
|
|
|
scoreMyTeam: null,
|
|
|
|
|
scoreOpponentTeam: null,
|
|
|
|
|
aliveMyTeam: null,
|
|
|
|
|
aliveOpponentTeam: null,
|
|
|
|
|
time: null,
|
|
|
|
|
killFeed: null,
|
|
|
|
|
}
|
2022-10-12 13:48:22 +02:00
|
|
|
|
#shotAnimationInterval = null;
|
2022-08-13 12:40:42 +02:00
|
|
|
|
#countDownIntervalId = null;
|
2022-10-07 15:44:35 +02:00
|
|
|
|
#scoreObject = null;
|
2022-10-09 13:28:35 +02:00
|
|
|
|
#lastBuyMenuPlayerMoney = null;
|
2022-08-13 12:40:42 +02:00
|
|
|
|
|
2022-10-11 16:55:14 +02:00
|
|
|
|
injectDependency(game, cursor) {
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#game = game
|
2022-10-11 16:55:14 +02:00
|
|
|
|
this.#cursor = cursor
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pause(msg, timeMs) {
|
|
|
|
|
this.#startCountDown(timeMs)
|
|
|
|
|
this.displayTopMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showScore() {
|
|
|
|
|
this.#setting.showScore = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideScore() {
|
|
|
|
|
this.#setting.showScore = false
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 16:55:14 +02:00
|
|
|
|
toggleBuyMenu() {
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#setting.showBuyMenu = !this.#setting.showBuyMenu
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hideBuyMenu() {
|
|
|
|
|
this.#setting.showBuyMenu = false
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 12:40:42 +02:00
|
|
|
|
toggleScore() {
|
|
|
|
|
this.#setting.showScore = !this.#setting.showScore
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:35:28 +02:00
|
|
|
|
#renderRoundsHistory(history, halfTimeRoundNumber, meIsAttacker) {
|
|
|
|
|
let template = ''
|
|
|
|
|
if (halfTimeRoundNumber === null) {
|
|
|
|
|
halfTimeRoundNumber = -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let [roundNumber, data] of Object.entries(history)) {
|
|
|
|
|
roundNumber = parseInt(roundNumber)
|
|
|
|
|
let iWasAttacker = meIsAttacker
|
|
|
|
|
if (roundNumber < halfTimeRoundNumber) {
|
|
|
|
|
iWasAttacker = !meIsAttacker
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (roundNumber === halfTimeRoundNumber) {
|
|
|
|
|
template += '<div class="round-number">|</div>'
|
|
|
|
|
}
|
|
|
|
|
const myTeamWonThatRound = (iWasAttacker === data.attackersWins)
|
|
|
|
|
const direction = (myTeamWonThatRound ? 'round-win-my-team' : 'round-win-other-team')
|
|
|
|
|
template += `<div class="round-number">
|
|
|
|
|
<span class="${direction} round-win-${data.attackersWins ? '1' : '0'}">
|
|
|
|
|
${Enum.RoundEndReasonIcon[data.reason]}
|
|
|
|
|
</span>
|
|
|
|
|
<div>${roundNumber % 5 === 0 ? roundNumber : ''}</div>
|
|
|
|
|
</div>`
|
|
|
|
|
}
|
|
|
|
|
return template
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#renderPlayerStats(scoreBoardData, players, statsForOtherTeam) {
|
|
|
|
|
const hud = this
|
|
|
|
|
let playerTable = '';
|
|
|
|
|
scoreBoardData.forEach(function (row) {
|
2022-10-07 15:44:35 +02:00
|
|
|
|
const playerId = row.id
|
|
|
|
|
const player = players[playerId].data
|
2022-10-06 20:35:28 +02:00
|
|
|
|
playerTable += `
|
2022-10-07 15:44:35 +02:00
|
|
|
|
<tr ${player.health > 0 ? '' : 'class="player-dead"'} data-player-id="${playerId}">
|
2022-10-06 20:35:28 +02:00
|
|
|
|
<td>${hud.#getPlayerName(player, hud.#game.playerMe.data)}</td>
|
2022-10-07 15:44:35 +02:00
|
|
|
|
<td data-money>${statsForOtherTeam ? '' : `${player.money}`}</td>
|
|
|
|
|
<td data-kills>${row.kills}</td>
|
|
|
|
|
<td data-deaths>${row.deaths}</td>
|
2022-10-06 20:35:28 +02:00
|
|
|
|
</tr>
|
|
|
|
|
`;
|
|
|
|
|
})
|
|
|
|
|
return `
|
|
|
|
|
<table class="player-stats ${statsForOtherTeam ? 'team-other' : 'team-my'}">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th style="width:60%">Player name</th>
|
|
|
|
|
<th style="width:20%">Money</th>
|
|
|
|
|
<th style="width:10%">Kills</th>
|
|
|
|
|
<th style="width:10%">Deaths</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
2022-10-07 15:44:35 +02:00
|
|
|
|
<tbody data-player-stats>
|
2022-10-06 20:35:28 +02:00
|
|
|
|
${playerTable}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 15:44:35 +02:00
|
|
|
|
requestFullScoreBoardUpdate(scoreObject) {
|
|
|
|
|
this.#scoreObject = scoreObject
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#updateScoreBoard() {
|
|
|
|
|
if (this.#scoreObject === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:35:28 +02:00
|
|
|
|
const game = this.#game
|
2022-10-07 15:44:35 +02:00
|
|
|
|
const scoreObject = this.#scoreObject;
|
2022-10-06 20:35:28 +02:00
|
|
|
|
const meIsAttacker = game.playerMe.isAttacker()
|
|
|
|
|
const myTeamIndex = game.playerMe.getTeamIndex()
|
|
|
|
|
const otherTeamIndex = game.playerMe.getOtherTeamIndex()
|
|
|
|
|
|
|
|
|
|
this.#elements.scoreDetail.innerHTML = `
|
|
|
|
|
<div>
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<td class="score-my color-me">${scoreObject.score[myTeamIndex]}<p>Score ${game.playerMe.getTeamName()}</p></td>
|
2022-10-06 20:35:28 +02:00
|
|
|
|
<td class="score-players players-my">
|
|
|
|
|
${this.#renderPlayerStats(scoreObject.scoreboard[myTeamIndex], game.players, false)}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="width:76px;text-align:center">
|
|
|
|
|
<small>Half Score</small>
|
|
|
|
|
<table class="half-score">
|
|
|
|
|
<td>
|
|
|
|
|
<span class="color-me">${scoreObject.firstHalfScore[scoreObject.halfTimeRoundNumber === null ? myTeamIndex : otherTeamIndex]}</span><br>
|
|
|
|
|
<small>1st</small><br>
|
|
|
|
|
<span class="color-opponent">${scoreObject.firstHalfScore[scoreObject.halfTimeRoundNumber === null ? otherTeamIndex : myTeamIndex]}</span>
|
|
|
|
|
</td>
|
|
|
|
|
${scoreObject.halfTimeRoundNumber === null ? '' : `
|
|
|
|
|
<td>
|
|
|
|
|
<span class="color-me">${scoreObject.secondHalfScore[myTeamIndex]}</span><br>
|
|
|
|
|
<small>2nd</small><br>
|
|
|
|
|
<span class="color-opponent">${scoreObject.secondHalfScore[otherTeamIndex]}</span>
|
|
|
|
|
</td>`}
|
|
|
|
|
</table>
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<div class="rounds-history">${this.#renderRoundsHistory(scoreObject.history, scoreObject.halfTimeRoundNumber, meIsAttacker)}</div>
|
|
|
|
|
</td>
|
|
|
|
|
<td style="width:135px">
|
|
|
|
|
<span class="color-me">$ ${scoreObject.lossBonus[myTeamIndex]}</span><br>
|
|
|
|
|
<small>Round loss Bonus</small><br>
|
|
|
|
|
<span class="color-opponent">$ ${scoreObject.lossBonus[otherTeamIndex]}</span>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<table>
|
|
|
|
|
<tr>
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<td class="score-opponent color-opponent">${scoreObject.score[otherTeamIndex]}<p>Score ${game.playerMe.getOtherTeamName()}</p></td>
|
2022-10-06 20:35:28 +02:00
|
|
|
|
<td class="score-players players-opponent">
|
|
|
|
|
${this.#renderPlayerStats(scoreObject.scoreboard[otherTeamIndex], game.players, true)}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
2022-10-07 15:44:35 +02:00
|
|
|
|
`;
|
|
|
|
|
this.#scoreObject = null
|
2022-10-05 20:08:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 12:40:42 +02:00
|
|
|
|
bombPlanted() {
|
2022-10-16 17:53:47 +02:00
|
|
|
|
this.displayBottomMessage('<span class="text-danger">⚠️ Alert</span><br>The bomb has been planted.<br>40 seconds to detonation.')
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:35:28 +02:00
|
|
|
|
#getPlayerName(player, playerMe) {
|
|
|
|
|
if (player.id === playerMe.id) {
|
|
|
|
|
return `Me (${Enum.ColorNames[player.color]})`
|
|
|
|
|
}
|
|
|
|
|
return (player.isAttacker === playerMe.isAttacker ? '' : 'Enemy ') + Enum.ColorNames[player.color]
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 15:44:35 +02:00
|
|
|
|
#getPlayerStatRowElement(playerData) {
|
|
|
|
|
return this.#elements.scoreDetail.querySelector(`[data-player-stats] [data-player-id="${playerData.id}"]`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#updatePlayerKills(playerData, amount) {
|
|
|
|
|
const killsElement = this.#getPlayerStatRowElement(playerData).querySelector('[data-kills]')
|
|
|
|
|
let kills = parseInt(killsElement.innerText)
|
|
|
|
|
killsElement.innerText = `${kills + amount}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#updatePlayerAlive(playerData) {
|
|
|
|
|
const statRowElement = this.#getPlayerStatRowElement(playerData)
|
|
|
|
|
statRowElement.classList.add('player-dead')
|
|
|
|
|
const deathsElement = statRowElement.querySelector('[data-deaths]')
|
|
|
|
|
let deaths = parseInt(deathsElement.innerText)
|
|
|
|
|
deathsElement.innerText = `${deaths - 1}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateMyTeamPlayerMoney(playerData, money) {
|
|
|
|
|
const moneyElement = this.#getPlayerStatRowElement(playerData).querySelector('[data-money]')
|
|
|
|
|
moneyElement.innerText = `${money}`
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:35:28 +02:00
|
|
|
|
showKill(playerCulprit, playerDead, wasHeadshot, playerMe, killedItemId) {
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#updatePlayerAlive(playerDead)
|
|
|
|
|
if (playerCulprit.id === playerDead.id) { // suicide
|
|
|
|
|
this.#updatePlayerKills(playerDead, -1)
|
|
|
|
|
} else if (playerCulprit.isAttacker === playerDead.isAttacker) { // team kill
|
|
|
|
|
this.#updatePlayerKills(playerCulprit, -1)
|
|
|
|
|
} else {
|
|
|
|
|
this.#updatePlayerKills(playerCulprit, 1)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 12:40:42 +02:00
|
|
|
|
const culprit = document.createElement('span')
|
2022-10-06 20:35:28 +02:00
|
|
|
|
const culpritOnMyTeam = (playerCulprit.isAttacker === playerMe.isAttacker)
|
2022-08-13 12:40:42 +02:00
|
|
|
|
culprit.classList.add(culpritOnMyTeam ? 'team-me' : 'team-opponent')
|
2022-10-06 20:35:28 +02:00
|
|
|
|
culprit.innerText = this.#getPlayerName(playerCulprit, playerMe)
|
2022-08-13 12:40:42 +02:00
|
|
|
|
|
|
|
|
|
const dead = document.createElement('span')
|
2022-10-06 20:35:28 +02:00
|
|
|
|
const deadOnyMyTeam = (playerDead.isAttacker === playerMe.isAttacker)
|
2022-08-13 12:40:42 +02:00
|
|
|
|
dead.classList.add(deadOnyMyTeam ? 'team-me' : 'team-opponent')
|
2022-10-06 20:35:28 +02:00
|
|
|
|
dead.innerText = this.#getPlayerName(playerDead, playerMe)
|
2022-08-13 12:40:42 +02:00
|
|
|
|
|
|
|
|
|
const parentElement = this.#elements.killFeed
|
|
|
|
|
if (parentElement.children.length > 4) {
|
|
|
|
|
parentElement.children[0].remove()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const row = document.createElement('p')
|
2022-10-06 20:35:28 +02:00
|
|
|
|
let shouldHighlight = (playerCulprit.id === playerMe.id || playerDead.id === playerMe.id)
|
2022-08-13 12:40:42 +02:00
|
|
|
|
if (shouldHighlight) {
|
|
|
|
|
row.classList.add('highlight')
|
|
|
|
|
}
|
|
|
|
|
let headshot = (wasHeadshot ? ' ⌖' : '')
|
|
|
|
|
row.append(culprit)
|
|
|
|
|
row.append(` killed${headshot} `)
|
|
|
|
|
row.append(dead)
|
|
|
|
|
parentElement.append(row)
|
|
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
row.remove()
|
|
|
|
|
}, 3000)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
roundStart(roundTimeMs) {
|
|
|
|
|
this.#startCountDown(roundTimeMs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#startCountDown(timeMs) {
|
|
|
|
|
clearInterval(this.#countDownIntervalId)
|
|
|
|
|
let roundTimeSec = Math.floor(timeMs / 1000)
|
|
|
|
|
|
|
|
|
|
const timeElement = this.#elements.time
|
|
|
|
|
let roundTimeInterval = setInterval(function () {
|
|
|
|
|
roundTimeSec--
|
|
|
|
|
|
|
|
|
|
let roundTimeMinute = Math.floor(roundTimeSec / 60)
|
|
|
|
|
timeElement.innerText = `${roundTimeMinute.toString().padStart(2, '0')}:${(roundTimeSec % 60).toString().padStart(2, '0')}`
|
|
|
|
|
if (roundTimeSec === 0) {
|
|
|
|
|
clearInterval(roundTimeInterval)
|
|
|
|
|
}
|
|
|
|
|
}, 1000)
|
|
|
|
|
this.#countDownIntervalId = roundTimeInterval
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startWarmup(timeMs) {
|
2022-10-16 17:53:47 +02:00
|
|
|
|
this.displayTopMessage('Waiting for all players to connect')
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#startCountDown(timeMs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayTopMessage(msg) {
|
2022-10-16 17:53:47 +02:00
|
|
|
|
this.#elements.messageTop.innerText = msg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayBottomMessage(msg) {
|
|
|
|
|
this.#elements.messageBottom.innerHTML = msg
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearAlerts() {
|
|
|
|
|
this.clearTopMessage()
|
|
|
|
|
this.clearBottomMessage()
|
|
|
|
|
this.#elements.killFeed.innerHTML = ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearTopMessage() {
|
2022-10-16 17:53:47 +02:00
|
|
|
|
this.#elements.messageTop.innerText = ''
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearBottomMessage() {
|
2022-10-16 17:53:47 +02:00
|
|
|
|
this.#elements.messageBottom.innerHTML = ''
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 20:08:33 +02:00
|
|
|
|
equip(slotId, availableSlots) {
|
2022-10-17 11:56:29 +02:00
|
|
|
|
this.#elements.slotModel.src = `./resources/slot_${slotId}.png`
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#elements.inventory.querySelectorAll('[data-slot]').forEach(function (node) {
|
2022-10-05 20:08:33 +02:00
|
|
|
|
node.classList.remove('highlight', 'hidden')
|
|
|
|
|
if (!availableSlots[node.dataset.slot]) {
|
|
|
|
|
node.classList.add('hidden')
|
|
|
|
|
}
|
2022-08-13 12:40:42 +02:00
|
|
|
|
})
|
|
|
|
|
this.#elements.inventory.querySelector(`[data-slot="${slotId}"]`).classList.add('highlight')
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 13:28:35 +02:00
|
|
|
|
#refreshBuyMenu(playerData) {
|
|
|
|
|
if (this.#lastBuyMenuPlayerMoney === playerData.money && this.#elements.buyMenu.innerHTML !== '') {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const money = playerData.money
|
|
|
|
|
const isAttacker = playerData.isAttacker
|
|
|
|
|
const buyMenuElement = this.#elements.buyMenu
|
|
|
|
|
this.#lastBuyMenuPlayerMoney = money
|
|
|
|
|
|
|
|
|
|
buyMenuElement.innerHTML = `
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<p class="title">${this.#game.playerMe.getTeamName()} Buy Store. Your money balance $ <strong>${money}</strong></p>
|
|
|
|
|
<h3>Equipment</h3>
|
2022-10-09 13:28:35 +02:00
|
|
|
|
<p${money < 1000 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="10" class="hud-action action-buy">Buy Kevlar + Helmet for $ 1,000</a></p>
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<h3>Pistols</h3>
|
2022-10-09 13:28:35 +02:00
|
|
|
|
${isAttacker
|
|
|
|
|
? `<p${money < 200 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="11" class="hud-action action-buy">Buy Glock for $ 200</a></p>`
|
|
|
|
|
: `<p${money < 200 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="8" class="hud-action action-buy">Buy USP for $ 200</a></p>`
|
|
|
|
|
}
|
|
|
|
|
<p${money < 250 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="9" class="hud-action action-buy">Buy P-250 for $ 250</a></p>
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<h3>Rifles</h3>
|
2022-10-09 13:28:35 +02:00
|
|
|
|
${isAttacker
|
|
|
|
|
? `<p${money < 2700 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="1" class="hud-action action-buy">Buy AK-47 for $ 2,700</a></p>`
|
|
|
|
|
: `<p${money < 3100 ? ' class="disabled"' : ''}><a data-buy-menu-item-id="7" class="hud-action action-buy">Buy M4-A1 for $ 3,100</a></p>`
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 13:48:22 +02:00
|
|
|
|
showShot() {
|
|
|
|
|
clearTimeout(this.#shotAnimationInterval)
|
|
|
|
|
this.#elements.shotModel.classList.remove('hidden');
|
|
|
|
|
this.#shotAnimationInterval = setTimeout(() => this.#elements.shotModel.classList.add('hidden'), 30)
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 12:40:42 +02:00
|
|
|
|
updateHud(player) {
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#updateScoreBoard()
|
2022-08-13 12:40:42 +02:00
|
|
|
|
const hs = this.#setting
|
|
|
|
|
if (hs.showScore) {
|
|
|
|
|
this.#elements.score.classList.remove('hidden');
|
|
|
|
|
} else {
|
|
|
|
|
this.#elements.score.classList.add('hidden');
|
|
|
|
|
}
|
2022-10-09 17:40:06 +02:00
|
|
|
|
this.#elements.canBuyIcon.classList.toggle('hidden', !player.canBuy);
|
2022-10-07 15:44:35 +02:00
|
|
|
|
if (player.canBuy && hs.showBuyMenu) {
|
2022-10-11 16:55:14 +02:00
|
|
|
|
this.#cursor.requestUnLock()
|
2022-10-09 13:28:35 +02:00
|
|
|
|
this.#refreshBuyMenu(player)
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#elements.buyMenu.classList.remove('hidden');
|
2022-10-11 16:55:14 +02:00
|
|
|
|
} else if (!this.#elements.buyMenu.classList.contains('hidden')) {
|
|
|
|
|
this.#cursor.requestLock()
|
2022-10-09 13:28:35 +02:00
|
|
|
|
this.#elements.buyMenu.innerHTML = ''
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#elements.buyMenu.classList.add('hidden');
|
|
|
|
|
}
|
2022-08-13 12:40:42 +02:00
|
|
|
|
|
|
|
|
|
this.#elements.money.innerText = player.money
|
|
|
|
|
this.#elements.health.innerText = player.health
|
|
|
|
|
this.#elements.armor.innerText = player.armor
|
2022-10-04 19:45:10 +02:00
|
|
|
|
if (player.ammo === null) {
|
|
|
|
|
this.#elements.ammo.innerText = `${player.item.name}`
|
|
|
|
|
} else {
|
|
|
|
|
this.#elements.ammo.innerText = `${player.item.name} - ${player.ammo} / ${player.ammoReserve}`
|
|
|
|
|
}
|
2022-08-13 12:40:42 +02:00
|
|
|
|
|
2022-10-06 20:35:28 +02:00
|
|
|
|
let myTeamIndex = +player.isAttacker
|
|
|
|
|
let otherTeamIndex = +!player.isAttacker
|
|
|
|
|
this.#elements.scoreMyTeam.innerHTML = this.#game.score.score[myTeamIndex]
|
|
|
|
|
this.#elements.scoreOpponentTeam.innerHTML = this.#game.score.score[otherTeamIndex]
|
|
|
|
|
this.#elements.aliveMyTeam.innerHTML = this.#game.alivePlayers[myTeamIndex]
|
|
|
|
|
this.#elements.aliveOpponentTeam.innerHTML = this.#game.alivePlayers[otherTeamIndex]
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createHud(elementHud) {
|
|
|
|
|
if (this.#elements.score) {
|
|
|
|
|
throw new Error("HUD already created")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elementHud.innerHTML = `
|
|
|
|
|
<div id="cross">✛</div>
|
2022-10-12 13:48:22 +02:00
|
|
|
|
<div id="equipped-item">
|
|
|
|
|
<div style="position:relative">
|
2022-10-17 11:56:29 +02:00
|
|
|
|
<img data-shot class="hidden" src="./resources/shot.gif">
|
|
|
|
|
<img data-slot src="./resources/slot_2.png">
|
2022-10-12 13:48:22 +02:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-08-13 12:40:42 +02:00
|
|
|
|
<div id="scoreboard" class="hidden">
|
2022-10-05 20:08:33 +02:00
|
|
|
|
<div id="scoreboard-detail"></div>
|
2022-08-13 12:40:42 +02:00
|
|
|
|
</div>
|
2022-10-09 13:28:35 +02:00
|
|
|
|
<div id="buy-menu" class="hidden"></div>
|
2022-08-13 12:40:42 +02:00
|
|
|
|
<section>
|
|
|
|
|
<div class="left">
|
|
|
|
|
<div class="top">
|
|
|
|
|
<div class="radar">
|
|
|
|
|
<br><br><br>
|
|
|
|
|
<br><br><br>
|
|
|
|
|
<br><br><br>
|
|
|
|
|
</div>
|
2022-10-09 17:40:06 +02:00
|
|
|
|
<div class="money bg"><span data-money>0</span> $ <span data-can-buy>🛒</span></div>
|
2022-08-13 12:40:42 +02:00
|
|
|
|
</div>
|
|
|
|
|
<div class="bottom">
|
|
|
|
|
<div class="health row bg">
|
|
|
|
|
<div class="hp">
|
|
|
|
|
➕ <span data-health>100</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="hp">
|
|
|
|
|
🛡️ <span data-armor>0</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="middle">
|
|
|
|
|
<div class="timer">
|
|
|
|
|
<div class="team-me-alive"></div>
|
|
|
|
|
<div class="timer-center bg">
|
|
|
|
|
<div id="time">---</div>
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="team-me-score">0</div>
|
|
|
|
|
<div class="team-opponent-score">0</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="team-opponent-alive"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="message-top"></div>
|
|
|
|
|
<div id="message-bottom"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="right">
|
|
|
|
|
<div class="kill-feed">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="inventory">
|
|
|
|
|
<p data-slot="0">Knife [q]</p>
|
2022-10-05 20:08:33 +02:00
|
|
|
|
<p class="hidden" data-slot="1">Primary [1]</p>
|
2022-10-04 19:45:10 +02:00
|
|
|
|
<p class="highlight" data-slot="2">Secondary [2]</p>
|
2022-10-05 20:08:33 +02:00
|
|
|
|
<p class="hidden" data-slot="3">Bomb [5]</p>
|
2022-08-13 12:40:42 +02:00
|
|
|
|
</div>
|
|
|
|
|
<div>
|
2022-10-04 19:45:10 +02:00
|
|
|
|
<span data-ammo class="ammo bg">
|
2022-08-13 12:40:42 +02:00
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
this.#elements.score = elementHud.querySelector('#scoreboard')
|
2022-10-07 15:44:35 +02:00
|
|
|
|
this.#elements.buyMenu = elementHud.querySelector('#buy-menu')
|
2022-10-09 17:40:06 +02:00
|
|
|
|
this.#elements.canBuyIcon = elementHud.querySelector('[data-can-buy]')
|
2022-10-05 20:08:33 +02:00
|
|
|
|
this.#elements.scoreDetail = elementHud.querySelector('#scoreboard-detail')
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#elements.equippedItem = elementHud.querySelector('#equipped-item')
|
2022-10-12 13:48:22 +02:00
|
|
|
|
this.#elements.slotModel = elementHud.querySelector('#equipped-item img[data-slot]')
|
|
|
|
|
this.#elements.shotModel = elementHud.querySelector('#equipped-item img[data-shot]')
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#elements.inventory = elementHud.querySelector('.inventory')
|
|
|
|
|
this.#elements.money = elementHud.querySelector('[data-money]')
|
|
|
|
|
this.#elements.health = elementHud.querySelector('[data-health]')
|
|
|
|
|
this.#elements.armor = elementHud.querySelector('[data-armor]')
|
2022-10-04 19:45:10 +02:00
|
|
|
|
this.#elements.ammo = elementHud.querySelector('[data-ammo]')
|
2022-08-13 12:40:42 +02:00
|
|
|
|
this.#elements.messageTop = elementHud.querySelector('#message-top')
|
|
|
|
|
this.#elements.messageBottom = elementHud.querySelector('#message-bottom')
|
|
|
|
|
this.#elements.scoreMyTeam = elementHud.querySelector('.team-me-score')
|
|
|
|
|
this.#elements.scoreOpponentTeam = elementHud.querySelector('.team-opponent-score')
|
|
|
|
|
this.#elements.aliveMyTeam = elementHud.querySelector('.team-me-alive')
|
|
|
|
|
this.#elements.aliveOpponentTeam = elementHud.querySelector('.team-opponent-alive')
|
|
|
|
|
this.#elements.time = elementHud.querySelector('#time')
|
|
|
|
|
this.#elements.killFeed = elementHud.querySelector('.kill-feed')
|
2022-10-09 13:28:35 +02:00
|
|
|
|
|
|
|
|
|
const game = this.#game
|
|
|
|
|
this.#elements.buyMenu.addEventListener('click', function (e) {
|
|
|
|
|
if (!e.target.classList.contains('action-buy')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
game.buyList.push(e.target.dataset.buyMenuItemId)
|
|
|
|
|
}, {capture: true})
|
2022-08-13 12:40:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|