let Chars = {} let CreatingMenu = false let tebexLink = "" $(function(){ $.post(`https://${GetParentResourceName()}/loaded`) const element = document.querySelector(".characters-box"); element.addEventListener('wheel', (event) => { event.preventDefault(); element.scrollBy({ left: event.deltaY < 0 ? -60 : 60, }); }); $(document).on("click", ".characters-box .box-wrapper .box.haschar .click-box", function(){ if ($(this).parent().hasClass("active")) return let license = $(this).parent().data("license") $(".box.haschar").removeClass("active") $(this).parent().addClass("active") $.post(`https://${GetParentResourceName()}/playerSelected`, JSON.stringify(license)) for (let i = 0; i < Chars.length; i++) { if (Chars[i].citizenid == license || Chars[i].identifier == license){ let firstname = JSON.parse(Chars[i].charinfo).firstname || Chars[i].firstname let lastname = JSON.parse(Chars[i].charinfo).lastname || Chars[i].lastname let gender = Chars[i].charinfo.gender == 0 ? "MAND" : "KVINDE" || Chars[i].chardata[i].sex == "m" ? "MAND" : "KVINDE" $(".char-selected-box .name").html(`${firstname} ${lastname}`) $(".char-selected-box .gender").html(gender) } } }) $(document).on("click", ".characters-box .create-btn", function(){ $(".box.haschar").removeClass("active") $.post(`https://${GetParentResourceName()}/playCreateAnimation`) $(".characters-box").fadeOut(100); $(".char-selected-box").fadeOut(100); setTimeout(() => { $(".create-box").fadeIn(100); $(".create-box").css("display", "flex"); CreatingMenu = true }, 1000); }) $(document).on("click", ".create-box .cancel.btn", function(){ $.post(`https://${GetParentResourceName()}/stopCreateAnim`) $(".create-box").fadeOut(100); setTimeout(() => { $(".characters-box").fadeIn(100); $(".char-selected-box").fadeIn(100); CreatingMenu = false }, 1000); }) $(document).on("input", "#firstname-input", function(){ let data = $("#firstname-input").val() if (data.length > 15){ $("#firstname-input").val(data.slice(0, 15)) } }) $(document).on("input", "#lastname-input", function(){ let data = $("#lastname-input").val() if (data.length > 15){ $("#lastname-input").val(data.slice(0, 15)) } }) $(document).on("input", "#nationality-input", function(){ let data = $("#nationality-input").val() if (data.length > 20){ $("#nationality-input").val(data.slice(0, 20)) } }) $(document).on("input", "#gender-input", function(){ let data = $("#gender-input").val() $.post(`https://${GetParentResourceName()}/genderUpdate`, JSON.stringify(data)) }) $(document).on("click", ".create-box .create.btn", function(){ let gender = $("#gender-input").val() let firstname = $("#firstname-input").val() let lastname = $("#lastname-input").val() let nationality = $("#nationality-input").val() let dob = $("#dob-input").val() if (firstname.length < 3 || firstname.length > 15) { $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Firstname must be between 3 and 15 characters")) return }else if (lastname.length < 3 || lastname.length > 15) { $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Lastname must be between 3 and 15 characters")) return }else if (nationality.length < 2 || nationality.length > 20) { $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Nationality must be between 2 and 20 characters")) return } if (gender && firstname && lastname && nationality && dob){ $.post(`https://${GetParentResourceName()}/createCharacter`, JSON.stringify({ gender: gender, firstname: firstname, lastname: lastname, nationality: nationality, dob: dob }), function(cb){ if (cb){ $("body").fadeOut(100); }else{ $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Something went wrong")) } }) }else{ $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Please fill all the fields")) } }) $(document).on("click", ".characters-box .box-wrapper .play-btn.btn", function(){ $.post(`https://${GetParentResourceName()}/selectCharacter`, JSON.stringify($(this).data("license"))) $("body").fadeOut(100); }) $(document).on("click", ".locked-btn", function(){ $(".toaster-wrapper input").val(""); $(".toaster-wrapper").fadeIn(200); $(".toaster-wrapper").css("display", "flex"); }) $(document).on("click", ".close-box", function(){ $(".toaster-wrapper").fadeOut(200); }) $(document).on("click", ".submit", function(){ if ($(".toaster-wrapper input").val() == "" || !$(".toaster-wrapper input").val()) return $.post(`https://${GetParentResourceName()}/submitCode`, JSON.stringify($(".toaster-wrapper input").val()), function(cb){ if (cb){ let payedSlots = cb.payedSlots - cb.purchasedSlots let lockedSlots = cb.slots - payedSlots createAll(lockedSlots, Chars, cb.slots) $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Slot purchased")) $(".toaster-wrapper").fadeOut(200); }else{ $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("This code is used or not valid")) } }) }) $(document).on("mouseover", ".characters-box .box-wrapper .box.haschar", function(){ $.post(`https://${GetParentResourceName()}/playHoverAnimation`, JSON.stringify($(this).data("license"))) }) $(document).on("mouseout", ".characters-box .box-wrapper .box.haschar", function(){ $.post(`https://${GetParentResourceName()}/hoverOut`) }) $(document).on("click", ".delete-btn", function(){ $(".characters-box").fadeOut(100); $(".char-selected-box").fadeOut(100); $.post(`https://${GetParentResourceName()}/deleteChar`, JSON.stringify($(this).data("license")), function(cb){ if (cb){ let payedSlots = cb.payedSlots - cb.purchasedSlots let lockedSlots = cb.slots - payedSlots Chars = Object.values(cb.charData) createAll(lockedSlots, Chars, cb.slots) }else{ $.post(`https://${GetParentResourceName()}/notify`, JSON.stringify("Something went wrong")) } }) }) window.addEventListener("message", function(event){ let data = event.data; if(data.action == "open"){ $(".loading").show(); $("body").fadeIn(); } if(data.action == "sendData"){ let payedSlots = data.payedSlots - data.purchasedSlots let lockedSlots = data.slots - payedSlots Chars = Object.values(data.charData) createAll(lockedSlots, Chars, data.slots) } }) document.onkeyup = function (data) { if (data.which == 27) { if (CreatingMenu){ $.post(`https://${GetParentResourceName()}/stopCreateAnim`) $(".create-box").fadeOut(100); } } }; }) function createAll(lockedSlots, chardata, slots){ if (!chardata) { $(".characters-box").hide() $(".create-box").show() $.post(`https://${GetParentResourceName()}/playCreateAnimation`, JSON.stringify({}), function(){ $(".loading").fadeOut(100); }) }else{ $(".characters-box .box-wrapper").html(""); $.post(`https://${GetParentResourceName()}/playIdleAnimation`, JSON.stringify(chardata), function(){ for (let i = 0; i < slots; i++) { if (i < lockedSlots){ $(".characters-box .box-wrapper").append(`
OPRET
KARAKTER
`) }else{ $(".characters-box .box-wrapper").append(`
KØB
PLADS
`) } } for (let i = 0; i < chardata.length; i++) { $(`.characters-box .box-wrapper .box:nth-child(${i + 1})`).removeClass("locked") $(`.characters-box .box-wrapper .box:nth-child(${i + 1})`).removeClass("empty") $(`.characters-box .box-wrapper .box:nth-child(${i + 1})`).addClass("haschar") $(`.characters-box .box-wrapper .box:nth-child(${i + 1})`).data("license", chardata[i].citizenid || chardata[i].identifier) let charinfo = JSON.parse(chardata[i].charinfo) || "" $(`.characters-box .box-wrapper .box:nth-child(${i + 1})`).html(`
${chardata[i].identifier || chardata[i].citizenid}
${charinfo.firstname || chardata[i].firstname}
${charinfo.lastname || chardata[i].lastname}
SLET
`) } }) } setTimeout(() => { $(".loading").fadeOut(100); $(".characters-box").fadeIn(100); $(".char-selected-box").fadeIn(100); CreatingMenu = false }, 1000); }