|
1 | 1 | import { assert, cn } from '@/lib/utils';
|
2 |
| -import { HTMLAttributes } from 'react'; |
| 2 | +import { HTMLAttributes, useEffect, useMemo, useState } from 'react'; |
3 | 3 | import { useClientContext } from '../../single/ClientContext';
|
4 | 4 | import { BattleRoom } from '@/client/room/battleRoom';
|
5 | 5 | import { Icons, Sprites } from '@pkmn/img';
|
6 |
| -import type { Pokemon as PokemonType } from '@pkmn/client'; |
| 6 | +import type { Pokemon as PokemonType, Side } from '@pkmn/client'; |
7 | 7 | import { Username } from '../../Username';
|
8 |
| -import { useClientStore } from '@/client/client'; |
| 8 | +import { client, useClientStore } from '@/client/client'; |
9 | 9 |
|
10 | 10 |
|
| 11 | +function PokeballIcon() { |
| 12 | + const item = Icons.getPokeball('pokeball')!; |
| 13 | + return ( |
| 14 | + <span |
| 15 | + style={{ |
| 16 | + background: |
| 17 | + `transparent url("${item.url}") no-repeat scroll ${item.left}px ${item.top}px`, |
| 18 | + width: '40px', |
| 19 | + height: '30px', |
| 20 | + border: 0, |
| 21 | + display: 'inline-block', |
| 22 | + imageRendering: 'pixelated', |
| 23 | + verticalAlign: '-7px', |
| 24 | + }} |
| 25 | + > |
| 26 | + </span> |
| 27 | + ); |
| 28 | +} |
| 29 | + |
11 | 30 | function PokemonIcon({ pokemon }: Readonly<{
|
12 | 31 | pokemon: PokemonType | null,
|
13 | 32 | }>) {
|
@@ -40,31 +59,39 @@ function PokemonSprite({ pokemon, side }: Readonly<{
|
40 | 59 | return <img src={data.url} width={data.w} height={data.h} data-name={pokemon.name} alt={`${pokemon.name} sprite`} title={pokemon.name} />;
|
41 | 60 | }
|
42 | 61 |
|
| 62 | +function RenderTeam({ player }: Readonly<{ player: Side }>) { |
| 63 | + console.log(player); |
| 64 | + return <div className='w-[120px] grid grid-cols-2 md:grid-cols-3 p-2'> |
| 65 | + {player.team.map((pokemon, idx) => pokemon && <PokemonIcon key={idx} pokemon={pokemon} />)} |
| 66 | + {player.team.length < player.totalPokemon && [...Array(player.totalPokemon - player.team.length)].map((_, idx) => <PokeballIcon key={idx} />)} |
| 67 | + {/* {player.active.map((pokemon, idx) => pokemon && <PokemonSprite key={idx} pokemon={pokemon} />)} */} |
| 68 | + </div>; |
| 69 | +} |
| 70 | + |
43 | 71 | export default function BattleWindow(props: Readonly<HTMLAttributes<HTMLDivElement>>) {
|
44 | 72 | const battle = useClientStore(state => state.currentRoom) as BattleRoom;
|
45 | 73 | assert(battle?.type === 'battle', 'Trying to render BattleWindow in a room that is not a BattleRoom');
|
46 |
| - return <div className={cn(props.className, 'h-full w-full bg-gray-125 grid grid-cols-12')}> |
47 |
| - <div className='col-span-2 flex flex-col items-center' id="side-1"> |
| 74 | + return <div className={cn(props.className, 'h-full w-full bg-gray-125 flex flex-row')}> |
| 75 | + <div className=' flex flex-col items-center' id="side-1"> |
48 | 76 | <div className='text-center w-full'>
|
49 | 77 | <Username bold user={' ' + battle.battle.p1.name} />
|
50 | 78 | </div>
|
51 | 79 | <img src={Sprites.getAvatar(battle.battle.p1.avatar)} alt={`${battle.battle.p1.name}'s avatar`}/>
|
52 |
| - <div className='w-[120px] grid grid-cols-3'> |
53 |
| - {battle.battle.p1.team.map((pokemon, idx) => pokemon && <PokemonIcon key={idx} pokemon={pokemon} />)} |
| 80 | + <div className='w-full'> |
| 81 | + <RenderTeam player={battle.battle.p1} /> |
54 | 82 | </div>
|
55 | 83 | </div>
|
56 |
| - <div className='col-span-8 h-full bg-gray-100 flex justify-around items-center' id="battle"> |
57 |
| - {battle.battle.p1.active.map((pokemon, idx) => pokemon && <PokemonSprite key={idx} pokemon={pokemon} side='p1' />)} |
58 |
| - {battle.battle.p2.active.map((pokemon, idx) => pokemon && <PokemonSprite key={idx} pokemon={pokemon} side='p2' />)} |
59 |
| - |
| 84 | + <div className='h-full w-full bg-gray-100 flex justify-around items-center' id="battle"> |
| 85 | + {battle.battle.p1.active.map((pokemon, idx) => pokemon && <PokemonSprite key={idx} pokemon={pokemon} side='p1'/>)} |
| 86 | + {battle.battle.p2.active.map((pokemon, idx) => pokemon && <PokemonSprite key={idx} pokemon={pokemon} side='p2'/>)} |
60 | 87 | </div>
|
61 |
| - <div className='col-span-2 flex flex-col items-center' id="side-2"> |
| 88 | + <div className='flex flex-col items-center' id="side-2"> |
62 | 89 | <div className='text-center w-full'>
|
63 | 90 | <Username bold user={' ' + battle.battle.p2.name} />
|
64 | 91 | </div>
|
65 | 92 | <img src={Sprites.getAvatar(battle.battle.p2.avatar)} />
|
66 |
| - <div className='w-[120px] grid grid-cols-3'> |
67 |
| - {battle.battle.p2.team.map((pokemon, idx) => pokemon && <PokemonIcon key={idx} pokemon={pokemon} />)} |
| 93 | + <div className='w-full'> |
| 94 | + <RenderTeam player={battle.battle.p2} /> |
68 | 95 | </div>
|
69 | 96 | </div>
|
70 | 97 | </div>;
|
|
0 commit comments