File size: 1,494 Bytes
0092d86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81070c7
0092d86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { LoaderCircle, Pause, Play, RefreshCw } from "lucide-react";

type SimulationControlsProps = {
  hasSnapshot: boolean;
  isAutoTicking: boolean;
  isWaitingForTick: boolean;
  isWorldCommandPending: boolean;
  onStep: () => void;
  onToggleAutoTick: () => void;
};

export function SimulationControls({
  hasSnapshot,
  isAutoTicking,
  isWaitingForTick,
  isWorldCommandPending,
  onStep,
  onToggleAutoTick,
}: SimulationControlsProps) {
  const stepLabel = isWaitingForTick ? "Waiting for tick result" : "Advance one tick";
  const autoLabel = isAutoTicking ? "Pause continuous ticks" : "Run continuous ticks";

  return (
    <div className="controls" aria-label="Simulation controls">
      <button
        type="button"
        className={isWorldCommandPending ? "isLoading" : ""}
        aria-label={stepLabel}
        title={stepLabel}
        aria-busy={isWorldCommandPending}
        disabled={isWorldCommandPending}
        onClick={onStep}
      >
        {isWorldCommandPending ? (
          <LoaderCircle className="spinIcon" size={20} />
        ) : (
          <RefreshCw size={18} />
        )}
      </button>
      <button
        type="button"
        className={isAutoTicking ? "isActive" : ""}
        aria-label={autoLabel}
        title={autoLabel}
        aria-pressed={isAutoTicking}
        disabled={!hasSnapshot}
        onClick={onToggleAutoTick}
      >
        {isAutoTicking ? <Pause size={18} /> : <Play size={18} />}
      </button>
    </div>
  );
}