$(function() {
let displayOn = true
// Hide/show ui function
function display(bool) {
if (bool) {
displayOn = true;
$("body").show();
Money(false)
} else {
displayOn = false;
$("body").hide();
}
}
function characterCreatorMenu(bool) {
if (bool) {
$("#characterCreator").fadeIn("slow");
$("#characterEditor, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
return;
}
$("#characterCreator").fadeOut("slow");
}
function characterEditorMenu(bool) {
if (bool) {
$("#characterEditor").fadeIn("slow");
$("#characterCreator, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
return;
}
$("#characterEditor").fadeOut("slow");
}
function exitGameMenu(bool) {
if (bool) {
$("#exitGameMenu").fadeIn("slow");
$("#characterCreator, #characterEditor, #deleteCharacterMenu, #spawnLocation").hide();
return;
}
$("#exitGameMenu").fadeOut("slow");
}
function confirmDeleteMenu(bool) {
if (bool) {
$("#deleteCharacterMenu").fadeIn("slow");
$("#characterCreator, #characterEditor, #exitGameMenu, #spawnLocation").hide();
return;
}
$("#deleteCharacterMenu").fadeOut("slow");
}
function spawnMenu(bool) {
if (bool) {
$("#spawnLocation").fadeIn("slow");
$("#characterCreator, #characterEditor, #exitGameMenu, #deleteCharacterMenu").hide();
return;
}
$("#spawnLocation").fadeOut("slow");
}
function Money(bool) {
if (bool) {
$("#money").show();
$("body").css("background-image", "none");
$("body").show();
if (displayOn === false) {
$("#overlay").hide();
}
} else {
$("#money").hide();
$("#overlay").show();
}
}
display(false);
characterCreatorMenu(false);
characterEditorMenu(false);
exitGameMenu(false);
confirmDeleteMenu(false);
spawnMenu(false);
Money(false);
window.addEventListener('message', function(event) {
const item = event.data;
if (item.type === "ui") {
if (item.status) {
$('#serverName').text(item.serverName);
$("body").css("background-image", "url(" + item.background + ")");
display(true);
} else {
display(false);
}
}
$('#playerAmount').text(item.characterAmount);
if (item.type === "character") {
characterCreatorMenu(false);
createCharacter(item.firstName, item.lastName, item.dateOfBirth, item.gender, item.twtName, item.department, item.startingCash, item.startingBank, item.id);
}
if (item.type === "setSpawns") {
$("#spawnMenuContainer").empty();
setTimeout(function(){
$("#spawnMenuContainer").append(``);
$(".spawnButtons").click(function() {
$.post(`https://${GetParentResourceName()}/tpToLocation`, JSON.stringify({
x: $(this).data("x"),
y: $(this).data("y"),
z: $(this).data("z")
}));
spawnMenu(false);
setTimeout(function(){
$("#spawnMenuContainer").empty();
}, 550);
return;
});
}, 10);
}
if (item.type === "givePerms") {
JSON.parse(item.deptRoles).forEach((dept) => {
$('.departments').append($('