Refactor colorTypeGradients method to make it shorter

develop
Jason Zhu 2023-05-08 23:14:03 +10:00
parent 57e92b17d3
commit 25a010e7c6
1 changed files with 69 additions and 123 deletions

View File

@ -1,136 +1,82 @@
const getColor = (type: string) => {
let returnColor: string;
switch (type) {
case 'grass':
returnColor = '#a8ff98';
break;
case 'poison':
returnColor = '#d6a2e4';
break;
case 'normal':
returnColor = '#dcdcdc';
break;
case 'fire':
returnColor = '#ffb971';
break;
case 'water':
returnColor = '#8cc4e2';
break;
case 'electric':
returnColor = '#ffe662';
break;
case 'ice':
returnColor = '#8cf5e4';
break;
case 'fighting':
returnColor = '#da7589';
break;
case 'ground':
returnColor = '#e69a74';
break;
case 'flying':
returnColor = '#bbc9e4';
break;
case 'psychic':
returnColor = '#ffa5da';
break;
case 'bug':
returnColor = '#bae05f';
break;
case 'rock':
returnColor = '#C9BB8A';
break;
case 'ghost':
returnColor = '#8291e0';
break;
case 'dark':
returnColor = '#8e8c94';
break;
case 'dragon':
returnColor = '#88a2e8';
break;
case 'steel':
returnColor = '#9fb8b9';
break;
case 'fairy':
returnColor = '#fdb9e9';
break;
default:
returnColor = 'gainsboro';
break;
}
return returnColor;
};
export const colorTypeGradients = (
type1: string,
type2: string,
length: number,
) => {
// debugger
let color1, color2;
let color2;
switch (type1) {
case 'grass':
color1 = '#a8ff98';
break;
case 'poison':
color1 = '#d6a2e4';
break;
case 'normal':
color1 = '#dcdcdc';
break;
case 'fire':
color1 = '#ffb971';
break;
case 'water':
color1 = '#8cc4e2';
break;
case 'electric':
color1 = '#ffe662';
break;
case 'ice':
color1 = '#8cf5e4';
break;
case 'fighting':
color1 = '#da7589';
break;
case 'ground':
color1 = '#e69a74';
break;
case 'flying':
color1 = '#bbc9e4';
break;
case 'psychic':
color1 = '#ffa5da';
break;
case 'bug':
color1 = '#bae05f';
break;
case 'rock':
color1 = '#C9BB8A';
break;
case 'ghost':
color1 = '#8291e0';
break;
case 'dark':
color1 = '#8e8c94';
break;
case 'dragon':
color1 = '#88a2e8';
break;
case 'steel':
color1 = '#9fb8b9';
break;
case 'fairy':
color1 = '#fdb9e9';
break;
default:
color1 = 'gainsboro';
break;
}
const color1 = getColor(type1);
if (length === 2) {
switch (type2) {
case 'grass':
color2 = '#a8ff98';
break;
case 'poison':
color2 = '#d6a2e4';
break;
case 'normal':
color2 = '#dcdcdc';
break;
case 'fire':
color2 = '#ffb971';
break;
case 'water':
color2 = '#8cc4e2';
break;
case 'electric':
color2 = '#ffe662';
break;
case 'ice':
color2 = '#8cf5e4';
break;
case 'fighting':
color2 = '#da7589';
break;
case 'ground':
color2 = '#e69a74';
break;
case 'flying':
color2 = '#bbc9e4';
break;
case 'psychic':
color2 = '#ffa5da';
break;
case 'bug':
color2 = '#bae05f';
break;
case 'rock':
color2 = '#C9BB8A';
break;
case 'ghost':
color2 = '#8291e0';
break;
case 'dark':
color2 = '#8e8c94';
break;
case 'dragon':
color2 = '#88a2e8';
break;
case 'steel':
color2 = '#9fb8b9';
break;
case 'fairy':
color2 = '#fdb9e9';
break;
default:
color2 = 'gainsboro';
break;
}
color2 = getColor(type2);
} else if (length === 1) {
color2 = color1;
}
const finalColor = [color1, color2];
return finalColor;
return [color1, color2];
};