@@ -13,10 +13,11 @@ import {
1313} from "@xyflow/react" ;
1414import { useCallback , useEffect } from "react" ;
1515
16- import { ProcessorKind } from "mindy-website" ;
16+ import { DisplayKind , ProcessorKind } from "mindy-website" ;
1717
1818import { useLogicVM } from "../hooks" ;
19- import { packPoint } from "../utils" ;
19+ import { createNode } from "../utils" ;
20+ import AddBuildingMenu from "./AddBuildingMenu" ;
2021import BuildingLinkConnectionLine from "./BuildingLinkConnectionLine" ;
2122import BuildingLinkEdge from "./BuildingLinkEdge" ;
2223import DisplayNode , { type DisplayNodeType } from "./nodes/DisplayNode" ;
@@ -38,33 +39,13 @@ const defaultEdgeOptions: Partial<Edge> = {
3839 markerEnd : { type : MarkerType . Arrow } ,
3940} ;
4041
41- function createNode < N , D > (
42- node : N & { position : { x : number ; y : number } ; data : D } ,
43- ) : N & {
44- id : string ;
45- position : { x : number ; y : number } ;
46- data : D & { position : number } ;
47- } {
48- const {
49- position : { x, y } ,
50- } = node ;
51- const position = packPoint ( x , y ) ;
52- return {
53- ...node ,
54- id : position . toString ( ) ,
55- position : { x : x * 400 , y : y * 400 } ,
56- data : {
57- ...node . data ,
58- position,
59- } ,
60- } ;
61- }
62-
6342const defaultNodes : LogicVMNode [ ] = [
6443 createNode ( {
6544 type : "display" ,
66- position : { x : 1 , y : 0 } ,
45+ position : { x : 400 , y : 0 } ,
6746 data : {
47+ position : { x : 0 , y : 0 } ,
48+ kind : DisplayKind . Tiled ,
6849 displayWidth : 256 ,
6950 displayHeight : 256 ,
7051 } ,
@@ -74,6 +55,7 @@ const defaultNodes: LogicVMNode[] = [
7455 type : "processor" ,
7556 position : { x : 0 , y : 0 } ,
7657 data : {
58+ position : { x : 1 , y : 0 } ,
7759 kind : ProcessorKind . World ,
7860 defaultCode : `
7961sensor x display1 @displayWidth
@@ -109,13 +91,6 @@ export default function LogicVMFlow() {
10991
11092 const [ edges , setEdges , onEdgesChange ] = useEdgesState < Edge > ( defaultEdges ) ;
11193
112- // abort deletions that would remove nodes
113- const onBeforeDelete = useCallback (
114- // eslint-disable-next-line @typescript-eslint/require-await
115- async ( { nodes } : { nodes : LogicVMNode [ ] } ) => nodes . length === 0 ,
116- [ ] ,
117- ) ;
118-
11994 const onConnect = useCallback (
12095 ( params : Edge | Connection ) => {
12196 // https://github.com/xyflow/xyflow/blob/a75087e8d3a6ea0731f5bd2331027dc89edce85c/packages/system/src/utils/edges/general.ts#L91
@@ -208,13 +183,15 @@ export default function LogicVMFlow() {
208183 defaultEdgeOptions = { defaultEdgeOptions }
209184 onNodesChange = { onNodesChange }
210185 onEdgesChange = { onEdgesChange }
211- onBeforeDelete = { onBeforeDelete }
212186 onConnect = { onConnect }
213187 connectionLineComponent = { BuildingLinkConnectionLine }
188+ proOptions = { { hideAttribution : true } }
189+ nodeOrigin = { [ 0.5 , 0.5 ] }
214190 fitView
215191 >
216192 < Background variant = { BackgroundVariant . Dots } />
217193 < Controls />
194+ < AddBuildingMenu />
218195 </ ReactFlow >
219196 ) ;
220197}
0 commit comments