@@ -0,0 +1,36 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
export let pokedexNumber: string | number;
|
||||||
|
export let form: string | undefined;
|
||||||
|
|
||||||
|
let imagePath = null as string | null;
|
||||||
|
|
||||||
|
async function fetchImagePath() {
|
||||||
|
try {
|
||||||
|
let url = `/api/sprite?pokedexNumber=${pokedexNumber}`;
|
||||||
|
if (form) {
|
||||||
|
url += `&form=${form}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(url);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch image path');
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
imagePath = `./sprites/regular/${data.spriteFileName}`;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(fetchImagePath);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if imagePath}
|
||||||
|
<img src={imagePath} alt="sprite" />
|
||||||
|
{:else}
|
||||||
|
<p>Loading...</p>
|
||||||
|
{/if}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import SignUp from '$lib/components/SignUp.svelte';
|
import SignUp from '$lib/components/SignUp.svelte';
|
||||||
import SignIn from '$lib/components/SignIn.svelte';
|
import SignIn from '$lib/components/SignIn.svelte';
|
||||||
import SignOut from '$lib/components/SignOut.svelte';
|
import SignOut from '$lib/components/SignOut.svelte';
|
||||||
|
import PokemonSprite from '$lib/components/PokemonSprite.svelte';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
let { supabase } = data;
|
let { supabase } = data;
|
||||||
@@ -51,3 +52,9 @@
|
|||||||
<SignIn {supabase} on:signedIn={setUserEmail} />
|
<SignIn {supabase} on:signedIn={setUserEmail} />
|
||||||
<br />
|
<br />
|
||||||
<SignOut {supabase} on:signedOut={setUserEmail} />
|
<SignOut {supabase} on:signedOut={setUserEmail} />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<PokemonSprite pokedexNumber={666} form={'poke-ball'} />
|
||||||
|
<PokemonSprite pokedexNumber={666} form={''} />
|
||||||
|
<PokemonSprite pokedexNumber={'003'} form={''} />
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
import sprites from '$lib/helpers/sprites.json';
|
||||||
|
|
||||||
|
interface PokemonSpritesData {
|
||||||
|
[key: string]: {
|
||||||
|
forms: {
|
||||||
|
[key: string]: {
|
||||||
|
is_prev_gen_icon?: boolean;
|
||||||
|
is_alias_of?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET({ url }) {
|
||||||
|
const pokedexNumber = url.searchParams.get('pokedexNumber');
|
||||||
|
const form = url.searchParams.get('form') ?? undefined;
|
||||||
|
|
||||||
|
if (!pokedexNumber) {
|
||||||
|
return json({
|
||||||
|
status: 400,
|
||||||
|
error: 'Pokédex number is required'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const spriteFileName = getPokemonSpriteFileName(pokedexNumber, form);
|
||||||
|
|
||||||
|
if (spriteFileName) {
|
||||||
|
// If spriteUrl is found, return it with status 200
|
||||||
|
return json({
|
||||||
|
status: 200,
|
||||||
|
spriteFileName: spriteFileName
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// If spriteUrl is not found, return 404
|
||||||
|
return json({
|
||||||
|
status: 404,
|
||||||
|
error: `Sprite URL not found for the specified Pokémon with Pokédex number ${pokedexNumber} and form ${form}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPokemonSpriteFileName(number: string, form?: string): string | undefined {
|
||||||
|
const spritesData: PokemonSpritesData = sprites;
|
||||||
|
|
||||||
|
// Check if the Pokémon number exists in the sprites JSON
|
||||||
|
if (spritesData[number] && spritesData[number]['gen-8']) {
|
||||||
|
const forms = spritesData[number]['gen-8'].forms;
|
||||||
|
let formName = '$';
|
||||||
|
|
||||||
|
// If a form is provided and it exists for the Pokémon, set the form name
|
||||||
|
if (form && forms[form]) {
|
||||||
|
formName = form;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the form has an alias
|
||||||
|
if (forms[formName].is_alias_of) {
|
||||||
|
formName = forms[formName].is_alias_of;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = `${spritesData[number].slug.eng.toLowerCase()}${formName !== '$' ? '-' + formName : ''}.png`;
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the Pokémon number doesn't exist or doesn't have gen-8 sprites, return undefined
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 506 B |
|
After Width: | Height: | Size: 793 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 416 B |
|
After Width: | Height: | Size: 763 B |
|
After Width: | Height: | Size: 768 B |
|
After Width: | Height: | Size: 959 B |
|
After Width: | Height: | Size: 940 B |
|
After Width: | Height: | Size: 477 B |
|
After Width: | Height: | Size: 921 B |
|
After Width: | Height: | Size: 473 B |
|
After Width: | Height: | Size: 957 B |
|
After Width: | Height: | Size: 383 B |
|
After Width: | Height: | Size: 547 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 905 B |
|
After Width: | Height: | Size: 916 B |
|
After Width: | Height: | Size: 919 B |
|
After Width: | Height: | Size: 925 B |
|
After Width: | Height: | Size: 845 B |
|
After Width: | Height: | Size: 903 B |
|
After Width: | Height: | Size: 909 B |
|
After Width: | Height: | Size: 893 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 826 B |
|
After Width: | Height: | Size: 843 B |
|
After Width: | Height: | Size: 843 B |
|
After Width: | Height: | Size: 858 B |
|
After Width: | Height: | Size: 782 B |
|
After Width: | Height: | Size: 828 B |
|
After Width: | Height: | Size: 843 B |
|
After Width: | Height: | Size: 840 B |
|
After Width: | Height: | Size: 841 B |
|
After Width: | Height: | Size: 850 B |
|
After Width: | Height: | Size: 856 B |
|
After Width: | Height: | Size: 857 B |
|
After Width: | Height: | Size: 783 B |
|
After Width: | Height: | Size: 822 B |
|
After Width: | Height: | Size: 851 B |
|
After Width: | Height: | Size: 840 B |
|
After Width: | Height: | Size: 868 B |
|
After Width: | Height: | Size: 885 B |
|
After Width: | Height: | Size: 885 B |
|
After Width: | Height: | Size: 894 B |
|
After Width: | Height: | Size: 814 B |
|
After Width: | Height: | Size: 859 B |
|
After Width: | Height: | Size: 881 B |
|
After Width: | Height: | Size: 872 B |
|
After Width: | Height: | Size: 934 B |
|
After Width: | Height: | Size: 940 B |
|
After Width: | Height: | Size: 949 B |
|
After Width: | Height: | Size: 954 B |
|
After Width: | Height: | Size: 876 B |
|
After Width: | Height: | Size: 919 B |
|
After Width: | Height: | Size: 951 B |
|
After Width: | Height: | Size: 935 B |
|
After Width: | Height: | Size: 774 B |
|
After Width: | Height: | Size: 793 B |
|
After Width: | Height: | Size: 800 B |
|
After Width: | Height: | Size: 811 B |
|
After Width: | Height: | Size: 741 B |
|
After Width: | Height: | Size: 780 B |
|
After Width: | Height: | Size: 789 B |
|
After Width: | Height: | Size: 781 B |
|
After Width: | Height: | Size: 888 B |
|
After Width: | Height: | Size: 899 B |
|
After Width: | Height: | Size: 900 B |
|
After Width: | Height: | Size: 910 B |
|
After Width: | Height: | Size: 829 B |
|
After Width: | Height: | Size: 891 B |
|
After Width: | Height: | Size: 900 B |
|
After Width: | Height: | Size: 878 B |
|
After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 789 B |
|
After Width: | Height: | Size: 783 B |
|
After Width: | Height: | Size: 792 B |
|
After Width: | Height: | Size: 716 B |
|
After Width: | Height: | Size: 755 B |
|
After Width: | Height: | Size: 801 B |
|
After Width: | Height: | Size: 764 B |
|
After Width: | Height: | Size: 723 B |
|
After Width: | Height: | Size: 742 B |
|
After Width: | Height: | Size: 742 B |
|
After Width: | Height: | Size: 755 B |
|
After Width: | Height: | Size: 679 B |
|
After Width: | Height: | Size: 728 B |
|
After Width: | Height: | Size: 742 B |
|
After Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 795 B |
|
After Width: | Height: | Size: 297 B |
|
After Width: | Height: | Size: 452 B |
|
After Width: | Height: | Size: 763 B |
|
After Width: | Height: | Size: 355 B |
|
After Width: | Height: | Size: 476 B |
|
After Width: | Height: | Size: 666 B |
|
After Width: | Height: | Size: 483 B |