import {Container, Graphics} from '@pixi/react'; import {memo, useCallback} from 'react'; import {useDebug} from '@/react/context/debug.js'; import {useMainEntity} from '@/react/context/main-entity.js'; import Light from './light.jsx'; import SpriteComponent from './sprite.jsx'; function Aabb({color, width = 0.5, x0, y0, x1, y1, ...rest}) { const draw = useCallback((g) => { g.clear(); g.lineStyle(width, color); g.moveTo(x0, y0); g.lineTo(x1, y0); g.lineTo(x1, y1); g.lineTo(x0, y1); g.lineTo(x0, y0); }, [color, width, x0, x1, y0, y1]); return ( ); } function Crosshair() { const draw = useCallback((g) => { g.clear(); g.lineStyle(1, 0x000000); g.moveTo(-5, 0); g.lineTo(5, 0); g.moveTo(0, -5); g.lineTo(0, 5); g.lineStyle(0.5, 0xffffff); g.moveTo(-5, 0); g.lineTo(5, 0); g.moveTo(0, -5); g.lineTo(0, 5); g.lineStyle(1, 0x000000); g.drawCircle(0, 0, 3); g.lineStyle(0.5, 0xffffff); g.drawCircle(0, 0, 3); }, []); return ( ); } function Entity({entity, ...rest}) { const [debug] = useDebug(); const [mainEntity] = useMainEntity(); if (!entity) { return false; } const {Direction, id, Sprite} = entity; return ( <> {entity.Sprite && ( )} {entity.Light && ( )} {debug && entity.Position && ( )} {debug && ( )} {debug && entity.Collider && ( <> {entity.Collider.aabbs.map((aabb, i) => ( ))} )} {debug && mainEntity == entity.id && ( )} ); } export default memo(Entity);