Compare commits

..

1 Commits

Author SHA1 Message Date
Vftdan dfc0870fc1 Fixed some inconsistent whitespaces 2024-04-23 01:02:02 +02:00
1 changed files with 66 additions and 66 deletions

View File

@ -45,17 +45,17 @@ const stats = document.getElementById("stats");
// Loading the JSON and getting all the available parts
async function getData() {
fetch('./parts.json')
.then(function(response) {
return response.json();
})
.then(function(data) {
loadParts(data);
})
.catch(function(error) {
console.log('An error occurred:', error);
});
.then(function(response) {
return response.json();
})
.then(function(data) {
loadParts(data);
})
.catch(function(error) {
console.log('An error occurred:', error);
});
}
function loadParts(parts) {
@ -64,19 +64,19 @@ function loadParts(parts) {
parts.type.body.forEach(fillArrayBody);
parts.type.mouth.forEach(fillArrayMouth);
parts.type.arms.forEach(fillArrayArms);
//find the indexes of each part of the corresponding color and write those into the color arrays
fillArraysArms();
//Randomize initial view
randomize();
//Show little statistic
var sum = body.length + eyes.length + mouth.length + arms.length;
var variety = body.length * eyes.length * mouth.length * arms_orange.length;
stats.innerHTML = "There are " + sum + " Elements available,<br />with " + new Intl.NumberFormat("de-DE").format(variety) + " possible combinations.";
//Activate the buttons after everything is loaded in
document.getElementById("body_left").disabled = false;
document.getElementById("body_right").disabled = false;
@ -91,54 +91,54 @@ function loadParts(parts) {
}
function fillArrayEyes(item){
function fillArrayEyes(item) {
let name = item.name;
let url = item.url;
eyes.push ([name, url]); //Two dimensional array, Second dimension holds name on index 0 and url at index 1
}
function fillArrayBody(item){
function fillArrayBody(item) {
let name = item.name;
let url = item.url;
let color = item.color;
body.push ([name, url, color]); //Two dimensional array, Second dimension holds name on index 0 and url at index 1
}
function fillArrayMouth(item){
function fillArrayMouth(item) {
let name = item.name;
let url = item.url;
mouth.push ([name, url]); //Two dimensional array, Second dimension holds name on index 0 and url at index 1
}
function fillArrayArms(item){
function fillArrayArms(item) {
let name = item.name;
let url = item.url;
let color = item.color;
arms.push ([name, url, color]); //Two dimensional array, Second dimension holds name on index 0 and url at index 1
}
function fillArraysArms(){
function fillArraysArms() {
for (let i=0; i<arms.length; i++){
if (arms[i][2] == "blue" || arms[i][2] == ""){
arms_blue.push(i);
}
if (arms[i][2] == "lightgrey" || arms[i][2] == ""){
arms_lightgrey.push(i);
}
if (arms[i][2] == "orange" || arms[i][2] == ""){
arms_orange.push(i);
}
if (arms[i][2] == "red" || arms[i][2] == ""){
arms_red.push(i);
}
if (arms[i][2] == "white" || arms[i][2] == ""){
arms_white.push(i);
}
if (arms[i][2] == "yellow" || arms[i][2] == ""){
arms_yellow.push(i);
}
@ -147,18 +147,18 @@ function fillArraysArms(){
function onClick_body_next(){
function onClick_body_next() {
index_body++;
if (index_body == body.length) {index_body = 0;} //check if index is too big for the array
if (body[index_body][2] == "blue"){index_arms = arms_blue[index_color];}
else if (body[index_body][2] == "lightgrey"){index_arms = arms_lightgrey[index_color];}
else if (body[index_body][2] == "orange"){index_arms = arms_orange[index_color];}
else if (body[index_body][2] == "red"){index_arms = arms_red[index_color];}
else if (body[index_body][2] == "white"){index_arms = arms_white[index_color];}
else if (body[index_body][2] == "yellow"){index_arms = arms_yellow[index_color];}
else if (body[index_body][2] == "yellow"){index_arms = arms_yellow[index_color];}
body_image.src = "." + body[index_body][1]; //Change URL of body picture
body_name.innerHTML = body[index_body][0]; //Change body name in controls
@ -166,18 +166,18 @@ function onClick_body_next(){
arms_name.innerHTML = arms[index_arms][0]; //Change arms name in controls
}
function onClick_body_prev(){
function onClick_body_prev() {
index_body--;
if (index_body < 0) {index_body = (body.length-1);} //check if index is too big for the array
if (body[index_body][2] == "blue"){index_arms = arms_blue[index_color];}
else if (body[index_body][2] == "lightgrey"){index_arms = arms_lightgrey[index_color];}
else if (body[index_body][2] == "orange"){index_arms = arms_orange[index_color];}
else if (body[index_body][2] == "red"){index_arms = arms_red[index_color];}
else if (body[index_body][2] == "white"){index_arms = arms_white[index_color];}
else if (body[index_body][2] == "yellow"){index_arms = arms_yellow[index_color];}
else if (body[index_body][2] == "yellow"){index_arms = arms_yellow[index_color];}
body_image.src = "." + body[index_body][1]; //Change URL of body picture
body_name.innerHTML = body[index_body][0]; //Change body name in controls
@ -185,45 +185,45 @@ function onClick_body_prev(){
arms_name.innerHTML = arms[index_arms][0]; //Change arms name in controls
}
function onClick_eyes_next(){
function onClick_eyes_next() {
index_eyes++;
if (index_eyes == eyes.length) {index_eyes = 0;} //check if index is too big for the array
eyes_image.src = "." + eyes[index_eyes][1]; //Change URL of picture
eyes_name.innerHTML = eyes[index_eyes][0]; //Change name in controls
}
function onClick_eyes_prev(){
function onClick_eyes_prev() {
index_eyes--;
if (index_eyes < 0) {index_eyes = (eyes.length-1);} //check if index is too big for the array
eyes_image.src = "." + eyes[index_eyes][1]; //Change URL of picture
eyes_name.innerHTML = eyes[index_eyes][0]; //Change name in controls
}
function onClick_mouth_next(){
function onClick_mouth_next() {
index_mouth++;
if (index_mouth == mouth.length) {index_mouth = 0;} //check if index is too big for the array
mouth_image.src = "." + mouth[index_mouth][1]; //Change URL of picture
mouth_name.innerHTML = mouth[index_mouth][0]; //Change name in controls
}
function onClick_mouth_prev(){
function onClick_mouth_prev() {
index_mouth--;
if (index_mouth < 0) {index_mouth = (mouth.length-1);} //check if index is too big for the array
mouth_image.src = "." + mouth[index_mouth][1]; //Change URL of picture
mouth_name.innerHTML = mouth[index_mouth][0]; //Change name in controls
}
function onClick_arms_next(){
function onClick_arms_next() {
index_color++;
if (body[index_body][2] == "blue"){
if (index_color == arms_blue.length) {index_color = 0;}
index_arms = arms_blue[index_color];
@ -247,15 +247,15 @@ function onClick_arms_next(){
else if (body[index_body][2] == "yellow"){
if (index_color == arms_yellow.length) {index_color = 0;}
index_arms = arms_yellow[index_color];
}
}
arms_image.src = "." + arms[index_arms][1]; //Change URL of picture
arms_name.innerHTML = arms[index_arms][0]; //Change name in controls
}
function onClick_arms_prev(){
function onClick_arms_prev() {
index_color--;
if (body[index_body][2] == "blue"){
if (index_color < 0) {index_color = arms_blue.length-1;}
index_arms = arms_blue[index_color];
@ -279,18 +279,18 @@ function onClick_arms_prev(){
else if (body[index_body][2] == "yellow"){
if (index_color < 0) {index_color = arms_yellow.length-1;}
index_arms = arms_yellow[index_color];
}
}
arms_image.src = "." + arms[index_arms][1]; //Change URL of picture
arms_name.innerHTML = arms[index_arms][0]; //Change name in controls
}
function randomize(){ //Randomize which parts are shown
function randomize() { //Randomize which parts are shown
index_body = Math.floor(Math.random() * body.length);
index_eyes = Math.floor(Math.random() * eyes.length);
index_mouth = Math.floor(Math.random() * mouth.length);
index_arms = 0;
//Determine what color the body has and chose the arms color in the same way
//Basically it does a random on the arms array and returns an index number with the right color for that body
if (body[index_body][2] == "blue"){
@ -317,30 +317,30 @@ function randomize(){ //Randomize which parts are shown
index_color = Math.floor(Math.random() * arms_yellow.length)
index_arms = arms_yellow[index_color];
}
body_image.src = "." + body[index_body][1];
eyes_image.src = "." + eyes[index_eyes][1];
mouth_image.src = "." + mouth[index_mouth][1];
arms_image.src = "." + arms[index_arms][1];
body_name.innerHTML = body[index_body][0];
eyes_name.innerHTML = eyes[index_eyes][0];
mouth_name.innerHTML = mouth[index_mouth][0];
arms_name.innerHTML = arms[index_arms][0];
}
function exportImage(){ //Export image so it can be saved as one PNG
function exportImage() { //Export image so it can be saved as one PNG
let ctx=canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
neomoji_name.value = body[index_body][0] + "_" + eyes[index_eyes][0] + "_" + mouth[index_mouth][0] + "_" + arms[index_arms][0]; //Set name for the emoji to use as the image name and to show as shortcode
let body_export = new Image();
let eyes_export = new Image();
let mouth_export = new Image();
let arms_export = new Image();
body_export.src = "." + body[index_body][1];
body_export.onload = function() {
ctx.drawImage(body_export, 0, 0, 256, 256);
@ -359,7 +359,7 @@ function exportImage(){ //Export image so it can be saved as one PNG
}
}
};
export_img.hidden = false;
neomoji_name.hidden = false;
document.getElementById("exportSaveMessage").hidden = false;
@ -367,4 +367,4 @@ function exportImage(){ //Export image so it can be saved as one PNG
//Main Programm
document.getElementById("noJSmessage").hidden = true;
getData();
getData();