Skip to content

Commit eacb5ab

Browse files
author
Kevin
committed
fix: add flip state management to Inputs and use in run logic
1 parent 60ce5e0 commit eacb5ab

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Inputs.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useSolutionFile,
66
useRun,
77
useSolutionContents,
8+
useFlip,
89
} from "client/run";
910
import { useClear, useLength } from "client/store";
1011
import { useControls, button } from "leva";
@@ -25,6 +26,7 @@ export function Inputs() {
2526
abort,
2627
} = useRun();
2728
const submitDisabled = !(mapFile && scenarioFile && solutionFile);
29+
const [flip, setFlip] = useFlip();
2830

2931
useControls(
3032
"Inputs",
@@ -56,8 +58,13 @@ export function Inputs() {
5658
accept: { "text/plain": [] },
5759
disabled: buffering,
5860
}),
61+
flip: {
62+
label: "Flip X/Y",
63+
value: flip,
64+
onChange: setFlip,
65+
},
5966
},
60-
[buffering]
67+
[buffering, flip]
6168
);
6269

6370
useControls(

src/client/run.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const useMapFile = () => useAtom(mapFileAtom);
1818
export const useScenarioFile = () => useAtom(scenarioFileAtom);
1919
export const useSolutionFile = () => useAtom(solutionFileAtom);
2020

21+
export const flipAtom = atom<boolean>(false);
22+
export const useFlip = () => useAtom(flipAtom);
23+
2124
// ─── Computed ────────────────────────────────────────────────────────────────
2225

2326
export function useSolutionContents() {
@@ -56,6 +59,7 @@ export function useRun() {
5659
const [mapFile] = useAtom(mapFileAtom);
5760
const [scenarioFile] = useAtom(scenarioFileAtom);
5861
const [solutionFile] = useAtom(solutionFileAtom);
62+
const [flip] = useFlip();
5963
const { data: contents } = useSolutionContents();
6064
const append = useSetAtom(appendAtom);
6165
const clear = useSetAtom(clearAtom);
@@ -76,6 +80,7 @@ export function useRun() {
7680
map: await mapFile.text(),
7781
scen: await scenarioFile.text(),
7882
paths: await solutionFile.text(),
83+
flipXY: flip,
7984
};
8085
let actions: State[] = [];
8186
const f = throttle(
@@ -97,7 +102,9 @@ export function useRun() {
97102
clear();
98103
const s = client.run.subscribe(options, {
99104
// Dodgy server sometimes outputs second option
100-
onData: (a: { data: Output[], id: string } | [string, Output[], null]) => {
105+
onData: (
106+
a: { data: Output[]; id: string } | [string, Output[], null]
107+
) => {
101108
const data = isArray(a) ? a[1] : a.data;
102109
for (const d of data) {
103110
if ("type" in d) {

0 commit comments

Comments
 (0)