From be31470cfd11171fc13cadb7140f11d608f4355a Mon Sep 17 00:00:00 2001 From: Niloy Sikdar Date: Wed, 30 Aug 2023 17:40:55 +0530 Subject: [PATCH] feat(playground): detect and update positions of collision areas for the bricks --- .../pages/WorkSpace/BrickFactory.tsx | 142 ++++++++++++++---- .../playground/pages/WorkSpace/data.ts | 25 +-- 2 files changed, 123 insertions(+), 44 deletions(-) diff --git a/modules/code-builder/playground/pages/WorkSpace/BrickFactory.tsx b/modules/code-builder/playground/pages/WorkSpace/BrickFactory.tsx index 233ab08d..dcb20494 100644 --- a/modules/code-builder/playground/pages/WorkSpace/BrickFactory.tsx +++ b/modules/code-builder/playground/pages/WorkSpace/BrickFactory.tsx @@ -29,7 +29,6 @@ const BrickFactory = ({ brickData }: { brickData: Brick }) => { setCoords(brickData.id, { x: clampX(newX), y: clampY(newY) }); brickData.childBricks.forEach((childBrick) => { - console.log(childBrick); const childBrickCoords = getCoords(childBrick)!; setCoords(childBrick, { x: childBrickCoords.x + e.deltaX, @@ -69,41 +68,118 @@ const BrickFactory = ({ brickData }: { brickData: Brick }) => { }, }); - switch (brickData.type) { - case 'data': - return ( - - ); - case 'expression': - return ( - ( + <> + {/* Right args bounding box */} + {'bBoxArgs' in brickData.instance && ( + <> + {Object.keys(brickData.instance.bBoxArgs).map((name, i) => { + if ('bBoxArgs' in brickData.instance) { + const arg = brickData.instance.bBoxArgs[name]; + + return ( + + ); + } + })} + + )} + + {/* Top instruction notch bounding box */} + {'bBoxNotchInsTop' in brickData.instance && ( + - ); - case 'statement': - return ( - - ); - case 'block': - return ( - - ); - default: - return <>; - } + )} + + ); + + const getBrick = () => { + switch (brickData.type) { + case 'data': + return ( + + ); + case 'expression': + return ( + + ); + case 'statement': + return ( + + ); + case 'block': + return ( + + ); + default: + return <>; + } + }; + + return ( + <> + + {/* {getBrick()} */} + + ); }; export default BrickFactory; diff --git a/modules/code-builder/playground/pages/WorkSpace/data.ts b/modules/code-builder/playground/pages/WorkSpace/data.ts index 768712a2..b29701c4 100644 --- a/modules/code-builder/playground/pages/WorkSpace/data.ts +++ b/modules/code-builder/playground/pages/WorkSpace/data.ts @@ -1,16 +1,19 @@ -import { - ModelBrickBlock, - ModelBrickData, - ModelBrickExpression, - ModelBrickStatement, -} from '@/brick'; -import type { TBrickType, TBrickCoords, TBrickArgDataType } from '@/@types/brick'; +import { ModelBrickBlock, ModelBrickStatement } from '@/brick'; +import type { + TBrickType, + TBrickCoords, + TBrickArgDataType, + IBrickData, + IBrickExpression, + IBrickStatement, + IBrickBlock, +} from '@/@types/brick'; type InstanceMap = { - data: ModelBrickData; - expression: ModelBrickExpression; - statement: ModelBrickStatement; - block: ModelBrickBlock; + data: IBrickData; + expression: IBrickExpression; + statement: IBrickStatement; + block: IBrickBlock; }; export type Brick = {