Moved everything under NeomojiMixer namespace

This commit is contained in:
Vftdan 2024-04-23 01:36:54 +02:00
parent dfc0870fc1
commit 8858549de3
2 changed files with 376 additions and 346 deletions

View File

@ -18,12 +18,12 @@
<img class="arms" id="arms_img" src="" />
</div>
<div id="controls">
<div class="body"><button id="body_left" onclick="onClick_body_prev();" disabled><</button><span class="name" id="body_name">name body</span><button id="body_right" onclick="onClick_body_next();" disabled>></button></div>
<div class="eyes"><button id="eyes_left" onclick="onClick_eyes_prev();" disabled><</button><span class="name" id="eyes_name">name eyes</span><button id="eyes_right" onclick="onClick_eyes_next();" disabled>></button></div>
<div class="mouth"><button id="mouth_left" onclick="onClick_mouth_prev();" disabled><</button><span class="name" id="mouth_name">name mouth</span><button id="mouth_right" onclick="onClick_mouth_next();" disabled>></button></div>
<div class="arms"><button id="arms_left" onclick="onClick_arms_prev();" disabled><</button><span class="name" id="arms_name">name arms</span><button id="arms_right" onclick="onClick_arms_next();" disabled>></button></div>
<div class="random"><button id="random" onclick="randomize();" disabled>Random</button></div>
<div class="export"><button id="export" onclick="exportImage();" disabled>Export Image</button></div>
<div class="body"><button id="body_left" onclick="NeomojiMixer.onClick_body_prev();" disabled><</button><span class="name" id="body_name">name body</span><button id="body_right" onclick="NeomojiMixer.onClick_body_next();" disabled>></button></div>
<div class="eyes"><button id="eyes_left" onclick="NeomojiMixer.onClick_eyes_prev();" disabled><</button><span class="name" id="eyes_name">name eyes</span><button id="eyes_right" onclick="NeomojiMixer.onClick_eyes_next();" disabled>></button></div>
<div class="mouth"><button id="mouth_left" onclick="NeomojiMixer.onClick_mouth_prev();" disabled><</button><span class="name" id="mouth_name">name mouth</span><button id="mouth_right" onclick="NeomojiMixer.onClick_mouth_next();" disabled>></button></div>
<div class="arms"><button id="arms_left" onclick="NeomojiMixer.onClick_arms_prev();" disabled><</button><span class="name" id="arms_name">name arms</span><button id="arms_right" onclick="NeomojiMixer.onClick_arms_next();" disabled>></button></div>
<div class="random"><button id="random" onclick="NeomojiMixer.randomize();" disabled>Random</button></div>
<div class="export"><button id="export" onclick="NeomojiMixer.exportImage();" disabled>Export Image</button></div>
</div>
<div id="stats">stats</div>
<canvas id="canvas_export" width="256" height="256" hidden name="test.png"></canvas>

View File

@ -1,50 +1,51 @@
//global variables
const NeomojiMixer = (function(NeomojiMixer) {
//global variables
//Arrays to hold the parts
let eyes = [];
let body = [];
let mouth = [];
let arms = [];
//Arrays to hold the parts
let eyes = [];
let body = [];
let mouth = [];
let arms = [];
//FOr all the different colours of the arms there will be each a own arraz
let arms_orange = [];
let arms_blue = [];
let arms_lightgrey = [];
let arms_red = [];
let arms_white = [];
let arms_yellow = [];
//FOr all the different colours of the arms there will be each a own arraz
let arms_orange = [];
let arms_blue = [];
let arms_lightgrey = [];
let arms_red = [];
let arms_white = [];
let arms_yellow = [];
//Index to easily find when to roll back to the first/last element in the list
let inex_eyes = 0;
let index_body = 0;
let index_mouth = 0;
let index_arms = 0;
let index_color = 0;
//Index to easily find when to roll back to the first/last element in the list
let inex_eyes = 0;
let index_body = 0;
let index_mouth = 0;
let index_arms = 0;
let index_color = 0;
//shotnames for HTML elements to interact with
//shotnames for HTML elements to interact with
//images
const body_image = document.getElementById("body_img");
const eyes_image = document.getElementById("eyes_img");
const mouth_image = document.getElementById("mouth_img");
const arms_image = document.getElementById("arms_img");
//images
const body_image = document.getElementById("body_img");
const eyes_image = document.getElementById("eyes_img");
const mouth_image = document.getElementById("mouth_img");
const arms_image = document.getElementById("arms_img");
const canvas = document.getElementById("canvas_export");
const export_img = document.getElementById("imageExport");
const neomoji_name = document.getElementById("fullNeomojiName");
const canvas = document.getElementById("canvas_export");
const export_img = document.getElementById("imageExport");
const neomoji_name = document.getElementById("fullNeomojiName");
//names
const body_name = document.getElementById("body_name");
const eyes_name = document.getElementById("eyes_name");
const mouth_name = document.getElementById("mouth_name");
const arms_name = document.getElementById("arms_name");
//names
const body_name = document.getElementById("body_name");
const eyes_name = document.getElementById("eyes_name");
const mouth_name = document.getElementById("mouth_name");
const arms_name = document.getElementById("arms_name");
//Stats
const stats = document.getElementById("stats");
//Stats
const stats = document.getElementById("stats");
// Loading the JSON and getting all the available parts
async function getData() {
// Loading the JSON and getting all the available parts
async function getData() {
fetch('./parts.json')
.then(function(response) {
@ -56,9 +57,9 @@ async function getData() {
.catch(function(error) {
console.log('An error occurred:', error);
});
}
}
function loadParts(parts) {
function loadParts(parts) {
//Load parts into Arrays
parts.type.eyes.forEach(fillArrayEyes);
parts.type.body.forEach(fillArrayBody);
@ -89,35 +90,35 @@ function loadParts(parts) {
document.getElementById("random").disabled = false;
document.getElementById("export").disabled = false;
}
}
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);
@ -143,11 +144,11 @@ function fillArraysArms() {
arms_yellow.push(i);
}
}
}
}
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
@ -164,9 +165,9 @@ function onClick_body_next() {
arms_image.src = "." + arms[index_arms][1]; //Change URL of arms picture
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
@ -183,45 +184,45 @@ function onClick_body_prev() {
arms_image.src = "." + arms[index_arms][1]; //Change URL of arms picture
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"){
@ -251,9 +252,9 @@ function onClick_arms_next() {
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"){
@ -283,9 +284,9 @@ function onClick_arms_prev() {
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);
@ -327,9 +328,9 @@ function randomize() { //Randomize which parts are shown
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);
@ -363,8 +364,37 @@ 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;
}
}
NeomojiMixer.eyes = eyes;
NeomojiMixer.body = body;
NeomojiMixer.mouth = mouth;
NeomojiMixer.arms = arms;
NeomojiMixer.arms_orange = arms_orange;
NeomojiMixer.arms_blue = arms_blue;
NeomojiMixer.arms_lightgrey = arms_lightgrey;
NeomojiMixer.arms_red = arms_red;
NeomojiMixer.arms_white = arms_white;
NeomojiMixer.arms_yellow = arms_yellow;
NeomojiMixer.getData = getData;
NeomojiMixer.randomize = randomize;
NeomojiMixer.exportImage = exportImage;
NeomojiMixer.onClick_body_next = onClick_body_next;
NeomojiMixer.onClick_body_prev = onClick_body_prev;
NeomojiMixer.onClick_eyes_next = onClick_eyes_next;
NeomojiMixer.onClick_eyes_prev = onClick_eyes_prev;
NeomojiMixer.onClick_mouth_next = onClick_mouth_next;
NeomojiMixer.onClick_mouth_prev = onClick_mouth_prev;
NeomojiMixer.onClick_arms_next = onClick_arms_next;
NeomojiMixer.onClick_arms_prev = onClick_arms_prev;
return NeomojiMixer;
})(window.NeomojiMixer || {});
//Main Programm
document.getElementById("noJSmessage").hidden = true;
getData();
NeomojiMixer.getData();