UNPKG

@icytrigun/avatarpackage

Version:
386 lines (350 loc) 13.1 kB
const staticAvatarUrl = "http://localhost:8080/" async function getAllAvatars() { axios.get(staticAvatarUrl+"avatar/getAll") .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call Avatar Function") }); } async function getAvatarById(id) { axios.get(staticAvatarUrl+"avatar/get/"+id) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarById Function"); }); } async function createAvatar(imagePath,avatarName,currentPoints=0,pointsToNextLevel=100,avatarLevel=1) { axios.post(staticAvatarUrl+"avatar/set/",{ imagePath: imagePath, avatarLevel: avatarLevel, avatarName: avatarName, currentPoints: currentPoints, pointsToNextLevel: pointsToNextLevel, }) .then(response => { console.log(response.data.toString()) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call setAvatarFunction Function"); }); } async function deleteAvatar(id){ axios.delete(staticAvatarUrl+"avatar/delete"+id) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call deleteAvatar Function"); }); } async function updateAvatar(id,avatar){ axios.put(staticAvatarUrl+"avatar/update"+id,{ id: avatar.id, name: avatar.name, description: avatar.description, valueToFinish: avatar.valueToFinish }) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatar Function"); }); } async function updateAvatarLevel(userId, points, pointsToNextLevel=0){ axios.put(staticAvatarUrl+"avatar/updateAvatarLevel/"+userId+"/"+points+"/"+pointsToNextLevel) .then(response => { if(response.data.gotNewLevel==true){ toastr.info("Glückwunsch Level " +response.data.level + " wurde erreicht","Neues Level") } console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatar Function"); }); } async function getAvatarOfUserHTML(entryId,userId){ axios.get(staticAvatarUrl+"avatar/getAvatarHTML/"+userId) .then(response => { document.getElementById(entryId).innerHTML =response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarOfUserHTML Function"); }); } let selectedAvatarImage = ""; function selectedNewAvatarPicture(pictureName) { document.getElementById(pictureName).style.backgroundColor = "var(--snd-color)"; if (selectedAvatarImage != "" && pictureName != selectedAvatarImage) { document.getElementById(selectedAvatarImage).style.backgroundColor = "var(--snd-bg-color)"; } selectedAvatarImage = pictureName; document.getElementById("avatarProfileImageSaveBtn").style.display = "block"; } let selectedBorderImage = ""; function selectedNewBorderPicture(pictureName) { document.getElementById(pictureName).style.backgroundColor = "var(--snd-color)"; if (selectedBorderImage != "" && pictureName != selectedBorderImage) { document.getElementById(selectedBorderImage).style.backgroundColor = "var(--snd-bg-color)"; } selectedBorderImage = pictureName; document.getElementById("avatarBorderImageSaveBtn").style.display = "block"; } let selectedStickerImage = ""; async function selectedNewSticker1(pictureName) { document.getElementById(pictureName).style.backgroundColor = "var(--snd-color)"; if (selectedStickerImage != "" && pictureName != selectedStickerImage) { document.getElementById(selectedStickerImage).style.backgroundColor = "var(--snd-bg-color)"; } selectedStickerImage = pictureName; document.getElementById("avatarSticker1ImageSaveBtn").style.display = "block"; } let selectedSticker2Image = ""; async function selectedNewSticker2(pictureName) { document.getElementById(pictureName).style.backgroundColor = "var(--snd-color)"; if (selectedSticker2Image != "" && pictureName != selectedSticker2Image) { document.getElementById(selectedSticker2Image).style.backgroundColor = "var(--snd-bg-color)"; } selectedSticker2Image = pictureName; document.getElementById("avatarSticker2ImageSaveBtn").style.display = "block"; } async function saveNewAvatarProfilePicture(userId){ axios.put(staticAvatarUrl+"avatar/updateAvatarImage/",{ imagePath: selectedAvatarImage, userId: userId, }) .then(response => { toastr.info("Profilbild erfolgreich angepasst"); return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatarProfilePicture Function"); }); } async function saveNewAvatarSticker1Picture(userId){ axios.put(staticAvatarUrl+"avatar/updateAvatarSticker/1",{ imagePath: selectedStickerImage, userId: userId, }) .then(response => { toastr.info("Sticker erfolgreich angepasst"); return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatarSticker1Picture Function"); }); } async function saveNewAvatarSticker2Picture(userId){ axios.put(staticAvatarUrl+"avatar/updateAvatarSticker/2",{ imagePath: selectedSticker2Image, userId: userId, }) .then(response => { toastr.info("Sticker erfolgreich angepasst"); return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatarSticker2Picture Function"); }); } async function saveNewBorderImagePicture(userId){ axios.put(staticAvatarUrl+"avatar/updateAvatarBorderImage/",{ imagePath: selectedBorderImage, userId: userId, }) .then(response => { toastr.info("Sticker erfolgreich angepasst"); return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatarSticker2Picture Function"); }); } //AvatarItem Code async function getAllAvatarItems() { axios.get(staticAvatarUrl+"avatarItem/getAll") .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call AvatarItem Function") }); } async function getAvatarItemdById(id) { axios.get(staticAvatarUrl+"avatarItem/get/"+id) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarItemById Function"); }); } async function createAvatarItem(avatarItem) { axios.post(staticAvatarUrl+"avatarItem/set/",{ userId: avatarItem.userId, rewardImage: avatarItem.rewardImage, itemType: avatarItem.itemType, name: avatarItem.name, }) .then(response => { toastr.success("Neuer"+avatarItem.itemType +" " + avatarItem.name +" erhalten", "Neues Item") console.log(response.data.toString()) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call setAvatarItemFunction Function"); }); } async function deleteAvatarItem(id){ axios.delete(staticAvatarUrl+"avatarItem/delete"+id) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call deleteAvatarItem Function"); }); } async function updateAvatarItem(id,avatarItem){ axios.put(staticAvatarUrl+"avatarItem/update"+id,{ id: avatarItem.id, name: avatarItem.name, description: avatarItem.description, valueToFinish: avatarItem.valueToFinish }) .then(response => { console.log(response.data) return response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call updateAvatarItem Function"); }); } async function getCompleteAvatarUpdateHTML(userId,entryHTMLId){ let documentSetAllChangeAvatarHTMLId =document.getElementById(entryHTMLId) if(documentSetAllChangeAvatarHTMLId!=null){ axios.get(staticAvatarUrl+"avatarItem/createAvatarImagesAndStickerChangeHTML/"+userId) .then(response => { documentSetAllChangeAvatarHTMLId.innerHTML =response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getCompleteAvatarUpdateHTML Function"); }); }else{ console.error("no entryHTML Element at id"+entryHTMLId); } } async function getAvatarProfileUpdateHTML(userId,entryHTMLId){ let documentSetAvatarChangeAvatarHTMLId =document.getElementById(entryHTMLId) if(documentSetAvatarChangeAvatarHTMLId!=null){ axios.get(staticAvatarUrl+"avatarItem/createAvatarImageChangeHTML/"+userId) .then(response => { documentSetAvatarChangeAvatarHTMLId.innerHTML =response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarProfileUpdateHTML Function"); }); }else{ console.error("no entryHTML Element at id"+entryHTMLId); } } async function getAvatarSticker1UpdateHTML(userId,entryHTMLId){ let documentSetSticker1ChangeAvatarHTMLId =document.getElementById(entryHTMLId) if(documentSetSticker1ChangeAvatarHTMLId!=null){ axios.get(staticAvatarUrl+"avatarItem/createAvatarSticker1ChangeHTML/"+userId) .then(response => { documentSetSticker1ChangeAvatarHTMLId.innerHTML =response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarSticker1UpdateHTML Function"); }); }else{ console.error("no entryHTML Element at id"+entryHTMLId); } } async function getAvatarSticker2UpdateHTML(userId,entryHTMLId){ let documentSetSticker2ChangeAvatarHTMLId =document.getElementById(entryHTMLId) if(documentSetSticker2ChangeAvatarHTMLId!=null){ axios.get(staticAvatarUrl+"avatarItem/createAvatarSticker2ChangeHTML/"+userId) .then(response => { documentSetSticker2ChangeAvatarHTMLId.innerHTML =response.data; }) .catch(function (error) { console.log(error); }) .finally(() => { console.log("i did try to call getAvatarSticker2UpdateHTML Function"); }); }else{ console.error("no entryHTML Element at id"+entryHTMLId); } }