GraphView.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // import { useMemo, useEffect, useState } from "react";
  2. // import ReactFlow, { Background, Controls, MarkerType } from "reactflow";
  3. // import type { NodeProps, Node, Edge } from "reactflow";
  4. // import "reactflow/dist/style.css";
  5. // import styles from "./Dashboard.module.css";
  6. import type { MachineData, UIOrchestrator } from "./types";
  7. // // Type for React Flow Node Data
  8. // interface CustomNodeData {
  9. // instance: MachineData;
  10. // label: string;
  11. // currentTick?: number;
  12. // }
  13. // const MachineNode = ({ data }: NodeProps<CustomNodeData>) => {
  14. // const machine = data.instance as MachineData;
  15. // return (
  16. // <div
  17. // className={styles.machineCard}
  18. // style={{ margin: 0, minWidth: "220px", boxShadow: "inset 0 0 10px rgba(0,0,0,0.5)" }}
  19. // >
  20. // <div style={{ display: "flex", justifyContent: "space-between", marginBottom: "8px" }}>
  21. // <span style={{ color: "#5eb663", fontWeight: "bold" }}>{machine.recipe.name}</span>
  22. // <span className={styles.statusBadge} style={{ color: machine.isCrafting ? "#5eb663" : "#fe5a5a" }}>
  23. // {machine.isCrafting ? "CRAFTING" : "HALTED"}
  24. // </span>
  25. // </div>
  26. // <div
  27. // style={{
  28. // width: "100%",
  29. // height: "6px",
  30. // backgroundColor: "#1a1a1a",
  31. // border: "1px solid #000",
  32. // marginBottom: "8px",
  33. // }}
  34. // >
  35. // <div style={{ width: `${machine.craftProgress * 100}%`, height: "100%", backgroundColor: "#5eb663" }} />
  36. // </div>
  37. // <div style={{ display: "flex", justifyContent: "space-between", fontSize: "11px" }}>
  38. // <div style={{ display: "flex", gap: "4px" }}>
  39. // <span style={{ color: "#8e8e8e" }}>IN:</span>
  40. // {Object.entries(machine.inputBuffer).map(([k, v]) => (
  41. // <span key={k} style={{ color: v === 0 ? "#fe5a5a" : "#fff" }}>
  42. // {v}
  43. // </span>
  44. // ))}
  45. // </div>
  46. // <div style={{ display: "flex", gap: "4px" }}>
  47. // <span style={{ color: "#8e8e8e" }}>OUT:</span>
  48. // {Object.entries(machine.outputBuffer).map(([k, v]) => {
  49. // const isFull = v >= (machine.outputBlockLimits[k] || 0);
  50. // return (
  51. // <span key={k} style={{ color: isFull ? "#fe5a5a" : "#fff" }}>
  52. // {v}
  53. // </span>
  54. // );
  55. // })}
  56. // </div>
  57. // </div>
  58. // </div>
  59. // );
  60. // };
  61. // const ChestNode = ({ data }: NodeProps<CustomNodeData>) => (
  62. // <div
  63. // style={{
  64. // backgroundColor: "#3d3d3d",
  65. // padding: "12px",
  66. // borderRadius: "4px",
  67. // border: "2px solid #8e8e8e",
  68. // minWidth: "120px",
  69. // textAlign: "center",
  70. // color: "#e3e3e3",
  71. // fontWeight: "bold",
  72. // }}
  73. // >
  74. // {data.label}
  75. // </div>
  76. // );
  77. // const nodeTypes = { machine: MachineNode, chest: ChestNode };
  78. interface GraphViewProps {
  79. orchestrator: UIOrchestrator;
  80. tick: number;
  81. }
  82. export default function GraphView({ orchestrator, tick }: GraphViewProps) {
  83. return <div></div>;
  84. }
  85. // export default function GraphView({ orchestrator, tick }: GraphViewProps) {
  86. // const { initialNodes, initialEdges } = useMemo(() => {
  87. // const nodes: Node<CustomNodeData>[] = [];
  88. // const edges: Edge[] = [];
  89. // const objToId = new Map<any, string>();
  90. // let idCounter = 0;
  91. // const getId = (obj: any, type: string, label: string): string => {
  92. // if (!objToId.has(obj)) {
  93. // const id = `node_${idCounter++}`;
  94. // objToId.set(obj, id);
  95. // nodes.push({
  96. // id,
  97. // type,
  98. // position: { x: (idCounter % 3) * 300, y: Math.floor(idCounter / 3) * 150 },
  99. // data: { instance: obj, label },
  100. // });
  101. // }
  102. // return objToId.get(obj)!;
  103. // };
  104. // orchestrator.getInserters().forEach((ins, i) => {
  105. // edges.push({
  106. // id: `edge_${i}`,
  107. // source: getId(ins.source, ins.source.recipe ? "machine" : "chest", "Source"),
  108. // target: getId(ins.destination, ins.destination.recipe ? "machine" : "chest", "Destination"),
  109. // label: ins.targetItemId,
  110. // animated: false,
  111. // style: { stroke: "#8e8e8e", strokeWidth: 2 },
  112. // markerEnd: { type: MarkerType.ArrowClosed, color: "#8e8e8e" },
  113. // });
  114. // });
  115. // return { initialNodes: nodes, initialEdges: edges };
  116. // }, [orchestrator]);
  117. // const [nodes, setNodes] = useState<Node<CustomNodeData>[]>(initialNodes);
  118. // const [edges, setEdges] = useState<Edge[]>(initialEdges);
  119. // useEffect(() => {
  120. // setNodes((nds) => nds.map((n) => ({ ...n, data: { ...n.data, currentTick: tick } })));
  121. // setEdges((eds) =>
  122. // eds.map((edge, i) => {
  123. // const ins = orchestrator.getInserters()[i];
  124. // const isSwinging = ins.state > 0 && ins.state < 4;
  125. // return {
  126. // ...edge,
  127. // animated: isSwinging,
  128. // style: { stroke: isSwinging ? "#5eb663" : "#8e8e8e", strokeWidth: isSwinging ? 3 : 2 },
  129. // markerEnd: { type: MarkerType.ArrowClosed, color: isSwinging ? "#5eb663" : "#8e8e8e" },
  130. // };
  131. // }),
  132. // );
  133. // }, [tick, orchestrator]);
  134. // return (
  135. // <div className={styles.graphWrapper}>
  136. // <ReactFlow nodes={nodes} edges={edges} nodeTypes={nodeTypes} fitView>
  137. // <Background color="#5f5f5f" gap={16} />
  138. // <Controls />
  139. // </ReactFlow>
  140. // </div>
  141. // );
  142. // }