Skip to content

Commit 9e633e5

Browse files
niloysikdarmeganindya
authored andcommitted
feat(playground): detect and update positions of collision areas for the bricks
1 parent ea72582 commit 9e633e5

File tree

2 files changed

+123
-44
lines changed

2 files changed

+123
-44
lines changed

modules/code-builder/playground/pages/WorkSpace/BrickFactory.tsx

Lines changed: 109 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const BrickFactory = ({ brickData }: { brickData: Brick }) => {
2929
setCoords(brickData.id, { x: clampX(newX), y: clampY(newY) });
3030

3131
brickData.childBricks.forEach((childBrick) => {
32-
console.log(childBrick);
3332
const childBrickCoords = getCoords(childBrick)!;
3433
setCoords(childBrick, {
3534
x: childBrickCoords.x + e.deltaX,
@@ -69,41 +68,118 @@ const BrickFactory = ({ brickData }: { brickData: Brick }) => {
6968
},
7069
});
7170

72-
switch (brickData.type) {
73-
case 'data':
74-
return (
75-
<BrickData brickData={brickData} moveProps={moveProps} coords={brickCoords} color={color} />
76-
);
77-
case 'expression':
78-
return (
79-
<BrickExpression
80-
brickData={brickData}
81-
moveProps={moveProps}
82-
coords={brickCoords}
83-
color={color}
71+
const VisualIndicators = () => (
72+
<>
73+
{/* Right args bounding box */}
74+
{'bBoxArgs' in brickData.instance && (
75+
<>
76+
{Object.keys(brickData.instance.bBoxArgs).map((name, i) => {
77+
if ('bBoxArgs' in brickData.instance) {
78+
const arg = brickData.instance.bBoxArgs[name];
79+
80+
return (
81+
<rect
82+
key={i}
83+
x={brickCoords.x + arg?.coords.x}
84+
y={brickCoords.y + arg?.coords.y}
85+
height={arg?.extent.height}
86+
width={arg?.extent.width}
87+
fill="green"
88+
opacity={0.8}
89+
/>
90+
);
91+
}
92+
})}
93+
</>
94+
)}
95+
96+
{/* Top instruction notch bounding box */}
97+
{'bBoxNotchInsTop' in brickData.instance && (
98+
<rect
99+
x={brickCoords.x + brickData.instance.bBoxNotchInsTop?.coords.x}
100+
y={brickCoords.y + brickData.instance.bBoxNotchInsTop?.coords.y}
101+
height={brickData.instance.bBoxNotchInsTop?.extent.height}
102+
width={brickData.instance.bBoxNotchInsTop?.extent.width}
103+
fill="green"
104+
opacity={0.9}
84105
/>
85-
);
86-
case 'statement':
87-
return (
88-
<BrickStatement
89-
brickData={brickData}
90-
moveProps={moveProps}
91-
coords={brickCoords}
92-
color={color}
106+
)}
107+
108+
{/* Bottom instruction notch bounding box */}
109+
{'bBoxNotchInsBot' in brickData.instance && (
110+
<rect
111+
x={brickCoords.x + brickData.instance.bBoxNotchInsBot?.coords.x}
112+
y={brickCoords.y + brickData.instance.bBoxNotchInsBot?.coords.y}
113+
height={brickData.instance.bBoxNotchInsBot?.extent.height}
114+
width={brickData.instance.bBoxNotchInsBot?.extent.width}
115+
fill="green"
116+
opacity={0.9}
93117
/>
94-
);
95-
case 'block':
96-
return (
97-
<BrickBlock
98-
brickData={brickData}
99-
moveProps={moveProps}
100-
coords={brickCoords}
101-
color={color}
118+
)}
119+
120+
{/* Top instruction notch inside nesting bounding box */}
121+
{'bBoxNotchInsNestTop' in brickData.instance && (
122+
<rect
123+
x={brickCoords.x + brickData.instance.bBoxNotchInsNestTop?.coords.x}
124+
y={brickCoords.y + brickData.instance.bBoxNotchInsNestTop?.coords.y}
125+
height={brickData.instance.bBoxNotchInsNestTop?.extent.height}
126+
width={brickData.instance.bBoxNotchInsNestTop?.extent.width}
127+
fill="green"
128+
opacity={0.9}
102129
/>
103-
);
104-
default:
105-
return <></>;
106-
}
130+
)}
131+
</>
132+
);
133+
134+
const getBrick = () => {
135+
switch (brickData.type) {
136+
case 'data':
137+
return (
138+
<BrickData
139+
brickData={brickData}
140+
moveProps={moveProps}
141+
coords={brickCoords}
142+
color={color}
143+
/>
144+
);
145+
case 'expression':
146+
return (
147+
<BrickExpression
148+
brickData={brickData}
149+
moveProps={moveProps}
150+
coords={brickCoords}
151+
color={color}
152+
/>
153+
);
154+
case 'statement':
155+
return (
156+
<BrickStatement
157+
brickData={brickData}
158+
moveProps={moveProps}
159+
coords={brickCoords}
160+
color={color}
161+
/>
162+
);
163+
case 'block':
164+
return (
165+
<BrickBlock
166+
brickData={brickData}
167+
moveProps={moveProps}
168+
coords={brickCoords}
169+
color={color}
170+
/>
171+
);
172+
default:
173+
return <></>;
174+
}
175+
};
176+
177+
return (
178+
<>
179+
<VisualIndicators />
180+
{/* {getBrick()} */}
181+
</>
182+
);
107183
};
108184

109185
export default BrickFactory;

modules/code-builder/playground/pages/WorkSpace/data.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import {
2-
ModelBrickBlock,
3-
ModelBrickData,
4-
ModelBrickExpression,
5-
ModelBrickStatement,
6-
} from '@/brick';
7-
import type { TBrickType, TBrickCoords, TBrickArgDataType } from '@/@types/brick';
1+
import { ModelBrickBlock, ModelBrickStatement } from '@/brick';
2+
import type {
3+
TBrickType,
4+
TBrickCoords,
5+
TBrickArgDataType,
6+
IBrickData,
7+
IBrickExpression,
8+
IBrickStatement,
9+
IBrickBlock,
10+
} from '@/@types/brick';
811

912
type InstanceMap = {
10-
data: ModelBrickData;
11-
expression: ModelBrickExpression;
12-
statement: ModelBrickStatement;
13-
block: ModelBrickBlock;
13+
data: IBrickData;
14+
expression: IBrickExpression;
15+
statement: IBrickStatement;
16+
block: IBrickBlock;
1417
};
1518

1619
export type Brick = {

0 commit comments

Comments
 (0)