124 lines
3.5 KiB
JavaScript
124 lines
3.5 KiB
JavaScript
const navBar = document.querySelector("nav")
|
|
const uiButtons = document.querySelector("footer>section.left")
|
|
const footer = document.querySelector("footer")
|
|
const leftSection = document.querySelector("section.left")
|
|
const audioPourcentageLabel = document.querySelector("label[for='audioVolume']")
|
|
const audio = new Audio()
|
|
|
|
function startAudio() {
|
|
audio.src = "./assets/audio/Golden Hill (Radio Edit).mp3"
|
|
audio.loop = true
|
|
audio.play()
|
|
audio.onended = () => {
|
|
if (!audio.paused) {
|
|
audio.play()
|
|
}
|
|
}
|
|
updateVolume(audio.volume)
|
|
}
|
|
|
|
function muteAudio() {
|
|
audio.muted = true
|
|
}
|
|
|
|
function unmuteAudio() {
|
|
audio.muted = false
|
|
}
|
|
|
|
function showNavBar() {
|
|
footer.style.zIndex = "-1"
|
|
leftSection.style.zIndex = "-1"
|
|
navBar.removeAttribute("hidden")
|
|
for (const button of uiButtons.children) {
|
|
button.setAttribute("hidden", "")
|
|
}
|
|
}
|
|
|
|
function hideNavBar() {
|
|
footer.style.zIndex = "9"
|
|
leftSection.style.zIndex = "9"
|
|
navBar.setAttribute("hidden", "")
|
|
for (const button of uiButtons.children) {
|
|
button.removeAttribute("hidden")
|
|
}
|
|
}
|
|
|
|
function toggleAudio(element) {
|
|
if (element.getAttribute("state") == 0) {
|
|
system.call("audio::mute")
|
|
element.setAttribute("state", 1)
|
|
element.children[0].classList.replace("fa-music", "fa-music-slash")
|
|
} else {
|
|
system.call("audio::unmute")
|
|
element.setAttribute("state", 0)
|
|
element.children[0].classList.replace("fa-music-slash", "fa-music")
|
|
}
|
|
}
|
|
|
|
function toggleMusic(element) {
|
|
if (element.getAttribute("state") == 0) {
|
|
system.call("audio::mute")
|
|
element.setAttribute("state", 1)
|
|
element.children[0].classList.replace("fa-pause", "fa-play")
|
|
element.children[1].innerText = "Reprendre"
|
|
} else {
|
|
system.call("audio::unmute")
|
|
element.setAttribute("state", 0)
|
|
element.children[0].classList.replace("fa-play", "fa-pause")
|
|
element.children[1].innerText = "Pause"
|
|
}
|
|
}
|
|
|
|
function updateVolume(value) {
|
|
audio.volume = value / 100
|
|
audioPourcentageLabel.innerText = `${value}%`
|
|
}
|
|
|
|
function logout() {
|
|
localStorage.removeItem("user")
|
|
document.location.href = './login.html'
|
|
}
|
|
|
|
system.result("server::ping", (pong) => {
|
|
playersStatus.innerText = `${pong.players.online}/${pong.players.max}`
|
|
})
|
|
|
|
system.result("player::profile", (playerProfile) => {
|
|
if (!localStorage.getItem("user")) {
|
|
localStorage.setItem("user", JSON.stringify(playerProfile))
|
|
}
|
|
})
|
|
|
|
function handleOptionsChanges(key, value) {
|
|
system.call("game::optionSet", { key, value })
|
|
}
|
|
|
|
function handleSettingsChanges(key, value) {
|
|
system.call("settings::set", { key, value })
|
|
}
|
|
|
|
system.result("game::parseOptions", (options) => {
|
|
gamma.checked = options.gamma == 1 ? true : false
|
|
renderClouds.checked = options.renderrenderClouds == false ? false : true
|
|
guiScale.value = options.guiScale
|
|
graphicsMode.checked = options.graphicsMode == 0 ? true : false
|
|
renderDistance.value = options.renderDistance
|
|
})
|
|
|
|
system.result("settings::read", (settings) => {
|
|
ram.value = settings.ram.max
|
|
})
|
|
|
|
system.result("hardware::ramInformation", ($ram) => {
|
|
ram.setAttribute("max", $ram.avaibleRam)
|
|
maxRam.innerText = `${Math.floor($ram.avaibleRam / 1024)} G`
|
|
})
|
|
|
|
window.onload = () => {
|
|
system.call("hardware::ramInformation")
|
|
system.call("game::parseOptions")
|
|
system.call("server::ping")
|
|
system.call("player::profile")
|
|
system.call("settings::read")
|
|
startAudio()
|
|
} |