Skip to content

Commit

Permalink
chore: render combined objects (#330)
Browse files Browse the repository at this point in the history
Co-authored-by: Malin <[email protected]>
  • Loading branch information
wadholm and wadholm authored Oct 3, 2023
1 parent e88786e commit ea52a6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions packages/frontend/src/components/Board/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const renderGameCharacterComponent = (gameObject: IGameObjectDto) => {
export const Cell: FC<CellProps> = memo((props) => {
const { gameObjects, id } = props;

const lastGameObject =
gameObjects.length > 0 ? gameObjects[gameObjects.length - 1] : null;
const renderGameObject = (gameObject: IGameObjectDto, index: number) => (
<div key={index} className="absolute w-[100%]">
{renderGameCharacterComponent(gameObject)}
</div>
);

return (
<div
Expand All @@ -46,7 +49,9 @@ export const Cell: FC<CellProps> = memo((props) => {
: 'justify-center'
}`}
>
{lastGameObject && renderGameCharacterComponent(lastGameObject)}
{gameObjects.map((gameObject, index) =>
renderGameObject(gameObject, index),
)}
</div>
);
});
2 changes: 1 addition & 1 deletion packages/frontend/src/components/gameObject/BotObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { robot } from '../images';
import { CommonGameObject } from './CommonGameObject';

export const BotComponent: FC<BotGameObjectProperties> = memo(({ name }) => (
<CommonGameObject characterName={name} characterImg={robot} />
<CommonGameObject characterName={name} characterImg={robot} index={10} />
));
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@ interface CommonGameObjectProps {
characterName?: string;
characterImg: string;
imageClassName?: string;
index?: number;
}

export const CommonGameObject: FC<CommonGameObjectProps> = ({
characterName,
characterImg,
imageClassName,
index = 2,
}) => {
return (
<div className="flex flex-col w-full">
{characterName && (
<p className="text-[6px] text-black dark:text-white max-w-[98%] self-center sm:text-[10px] overflow-hidden whitespace-nowrap truncate">
<p className="text-[6px] text-black dark:text-white max-w-[98%] self-center sm:text-[10px] bg-gray-50 dark:bg-gray-800 overflow-hidden whitespace-nowrap truncate">
{characterName}
</p>
)}
<img
src={characterImg}
className={`w-[70%] h-[70%] self-center ${imageClassName}`}
alt={characterName}
style={{
zIndex: index,
}}
/>
</div>
);
Expand Down

0 comments on commit ea52a6f

Please sign in to comment.