import {Sprite as PixiSprite} from '@pixi/react';

import useAsset from '@/hooks/use-asset.js';

export default function Sprite({entity}) {
  const asset = useAsset(entity.Sprite.source);
  if (!asset) {
    return false;
  }
  let texture;
  if (asset.textures) {
    const animation = asset.animations[entity.Sprite.animation]
    texture = animation[entity.Sprite.frame];
  }
  else {
    texture = asset;
  }
  return (
    <PixiSprite
      anchor={0.5}
      texture={texture}
      x={Math.round(entity.Position.x)}
      y={Math.round(entity.Position.y)}
    />
  );
}