File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,11 @@ import {
1111 ProcessorKind ,
1212} from "mindy-website" ;
1313
14- import { createNode } from "../utils" ;
14+ import {
15+ createNode ,
16+ getMonotonicNodeCount ,
17+ incrementMonotonicNodeCount ,
18+ } from "../utils" ;
1519import type { LogicVMNode } from "./LogicVMFlow" ;
1620
1721export default function AddBuildingMenu ( ) {
@@ -39,7 +43,7 @@ export default function AddBuildingMenu() {
3943 // calculate a position such that all nodes of a given size are at the same y position without overlapping
4044 const buildingPosition = {
4145 // leave enough room to the left assuming all nodes are in the same row as this one
42- x : reactFlow . getNodes ( ) . length * node . size ,
46+ x : getMonotonicNodeCount ( ) * node . size ,
4347 // the sum of the first n natural numbers is n*(n+1)/2
4448 // for a given size, we need to leave room below for all sizes < size
4549 // so y should be the sum of all sizes < size
@@ -48,6 +52,8 @@ export default function AddBuildingMenu() {
4852 y : ( ( node . size - 1 ) * node . size ) / 2 ,
4953 } ;
5054
55+ incrementMonotonicNodeCount ( ) ;
56+
5157 return [
5258 createNode ( {
5359 ...node ,
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import { useCallback, useEffect } from "react";
1616import { DisplayKind , ProcessorKind } from "mindy-website" ;
1717
1818import { useLogicVM } from "../hooks" ;
19- import { createNode } from "../utils" ;
19+ import { createNode , setMonotonicNodeCount } from "../utils" ;
2020import AddBuildingMenu from "./AddBuildingMenu" ;
2121import BuildingLinkConnectionLine from "./edges/BuildingLinkConnectionLine" ;
2222import BuildingLinkEdge from "./edges/BuildingLinkEdge" ;
@@ -92,6 +92,8 @@ const defaultEdges: Edge[] = [
9292 } ,
9393] ;
9494
95+ setMonotonicNodeCount ( defaultNodes . length ) ;
96+
9597export default function LogicVMFlow ( ) {
9698 const vm = useLogicVM ( ) ;
9799
Original file line number Diff line number Diff line change @@ -98,3 +98,17 @@ export function createNode<N, D>(
9898 } ,
9999 } ;
100100}
101+
102+ let monotonicNodeCount = 0 ;
103+
104+ export function getMonotonicNodeCount ( ) {
105+ return monotonicNodeCount ;
106+ }
107+
108+ export function setMonotonicNodeCount ( n : number ) {
109+ monotonicNodeCount = Math . max ( n , monotonicNodeCount ) ;
110+ }
111+
112+ export function incrementMonotonicNodeCount ( ) {
113+ setMonotonicNodeCount ( monotonicNodeCount + 1 ) ;
114+ }
You can’t perform that action at this time.
0 commit comments