59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
import {Container, Graphics} from '@pixi/react';
|
|
import {memo, useCallback} from 'react';
|
|
|
|
import {useDebug} from '@/context/debug.js';
|
|
|
|
import Emitter from './emitter.jsx';
|
|
import Sprite from './sprite.jsx';
|
|
|
|
function Crosshair({x, y}) {
|
|
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 (
|
|
<Graphics draw={draw} x={x} y={y} />
|
|
);
|
|
}
|
|
|
|
function Entities({entity}) {
|
|
const [debug] = useDebug();
|
|
if (!entity) {
|
|
return false;
|
|
}
|
|
return (
|
|
<Container
|
|
zIndex={entity.Position?.y || 0}
|
|
>
|
|
{entity.Sprite && (
|
|
<Sprite
|
|
entity={entity}
|
|
/>
|
|
)}
|
|
{entity.Emitter && (
|
|
<Emitter
|
|
entity={entity}
|
|
/>
|
|
)}
|
|
{debug && entity.Position && (
|
|
<Crosshair x={entity.Position.x} y={entity.Position.y} />
|
|
)}
|
|
</Container>
|
|
);
|
|
}
|
|
|
|
export default memo(Entities);
|