WizardTest.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { useState, useMemo } from "react";
  2. import type { Recipe } from "../../../scripts/factorio-dump/helpers/recipes.helper";
  3. import { calculateOptimalBatch, generateAdvancedClock } from "../../engine/factorioEngine";
  4. const ADVANCED_CIRCUIT_RECIPE: Recipe = {
  5. name: "advanced-circuit",
  6. category: "electronics",
  7. subgroup:"",
  8. energy_required: 6, // Red chips take 6 seconds base
  9. ingredients: [
  10. { itemId: "electronic-circuit", amount: 2, type: "item" },
  11. { itemId: "plastic-bar", amount: 2, type: "item" },
  12. { itemId: "copper-cable", amount: 4, type: "item" },
  13. ],
  14. results: [
  15. { type: "item", name: "advanced-circuit", amount: 1 }
  16. ],
  17. };
  18. export default function WizardTest() {
  19. const [productivityBonus, setProductivityBonus] = useState<number>(1.75); // +175%
  20. const [actualSpeed, setActualSpeed] = useState<number>(10.0); // Fast endgame machine
  21. const [stackSize, setStackSize] = useState<number>(16);
  22. const result = useMemo(() => {
  23. try {
  24. const batch = calculateOptimalBatch(
  25. ADVANCED_CIRCUIT_RECIPE,
  26. productivityBonus,
  27. actualSpeed,
  28. stackSize
  29. );
  30. const clockData = generateAdvancedClock(batch, stackSize);
  31. return { batch, clockData };
  32. } catch (err) {
  33. return { error: (err as Error).message };
  34. }
  35. }, [productivityBonus, actualSpeed, stackSize]);
  36. return (
  37. <div style={{ padding: 20, fontFamily: "sans-serif", background: "#242324", color: "#ffe6c0" }}>
  38. <h2>Factorio Clock Engine Sandbox</h2>
  39. <div style={{ display: "flex", gap: 20, marginBottom: 20 }}>
  40. <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
  41. <label>Productivity Bonus (e.g. 1.75 for +175%)</label>
  42. <input
  43. type="number"
  44. step="0.01"
  45. value={productivityBonus}
  46. onChange={(e) => setProductivityBonus(Number(e.target.value))}
  47. style={{ padding: 4 }}
  48. />
  49. </div>
  50. <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
  51. <label>Actual Crafting Speed</label>
  52. <input
  53. type="number"
  54. step="0.1"
  55. value={actualSpeed}
  56. onChange={(e) => setActualSpeed(Number(e.target.value))}
  57. style={{ padding: 4 }}
  58. />
  59. </div>
  60. <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
  61. <label>Stack Size</label>
  62. <input
  63. type="number"
  64. value={stackSize}
  65. onChange={(e) => setStackSize(Number(e.target.value))}
  66. style={{ padding: 4 }}
  67. />
  68. </div>
  69. </div>
  70. <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20 }}>
  71. <div>
  72. <h3>1. Batch Math Result</h3>
  73. <pre style={{ background: "#1a1a1a", padding: 10, borderRadius: 4, overflow: "auto" }}>
  74. {JSON.stringify(result.batch, null, 2)}
  75. </pre>
  76. </div>
  77. <div>
  78. <h3>2. Generated Timeline Blocks</h3>
  79. <pre style={{ background: "#1a1a1a", padding: 10, borderRadius: 4, overflow: "auto" }}>
  80. {JSON.stringify(result.clockData, null, 2)}
  81. </pre>
  82. </div>
  83. </div>
  84. </div>
  85. );
  86. }