Merge pull request #12 from jcreek/11-add-sprites

11 add sprites
This commit is contained in:
Josh Creek
2024-04-07 10:54:47 +01:00
committed by GitHub
2709 changed files with 29309 additions and 0 deletions
+36
View File
@@ -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}
File diff suppressed because it is too large Load Diff
+7
View File
@@ -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>
+67
View File
@@ -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;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 826 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 949 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 954 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 910 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 716 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Some files were not shown because too many files have changed in this diff Show More