import { forwardRef } from 'react'; import { Resource } from '../types'; import { Node2D } from '../ui/graph'; import { ResourceDescriptions } from '../ui/resource'; import { Game } from '../engine/game'; interface Props { game: Game; node2d: Node2D; selected: boolean; onSelect: () => void; onSocketRef?: (type: 'input' | 'output', index: number, el: HTMLDivElement | null) => void; } const NodeCard = forwardRef(function NodeCard({ node2d, selected, onSelect, onSocketRef }, ref) { const node = node2d.node; function handleClick() { onSelect(); } const info = node.behaviour.getDisplayInfo(); const inputSockets = info.sockets.filter((s) => s.type === 'input'); const outputSockets = info.sockets.filter((s) => s.type === 'output'); return (
{ inputSockets.map((socket) => (
onSocketRef?.('input', socket.index, el)} className="node__socket" style={{ background: ResourceDescriptions[socket.resource].color }} title={`${ResourceDescriptions[socket.resource].label} (вход)`} /> )) }
{ outputSockets.map((socket) => (
onSocketRef?.('output', socket.index, el)} className="node__socket" style={{ background: ResourceDescriptions[socket.resource].color }} title={`${ResourceDescriptions[socket.resource].label} (выход)`} /> )) }
#{node.id}
{node.name}
{node.behaviour.kind}
{ Object.entries(info.storages).map(([name, storage]) => (
{name}
{ Object.entries(storage) .map(([rt, v]) => `${ResourceDescriptions[rt as Resource].icon}${v.toStringWithDecimalPlaces(4)}`).join(' ') }
)) }
{ info.links.map((link) =>
→{link.target}/{link.resource}
) }
{JSON.stringify(info.raw, undefined, 4)}
); }); export default NodeCard;