diff --git a/website/src/App.tsx b/website/src/App.tsx index a7fcf941..4608a13b 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -5,6 +5,7 @@ import { styled } from "styled-components"; import { useOnKeyUp } from "./useOnKeyUp.hook"; import { useLocalStorage } from "./useLocalStorage.hook"; import { useAvoidItchIoScrolling } from "./useAvoidItchIoScrolling"; +import { Slider } from "./Slider"; const BindingsDialog = styled.dialog` border-radius: 5px; @@ -118,14 +119,7 @@ function BindingsWindow({ Volume: - setVolume(Number(e.target.value))} - /> + setVolume(e)} /> ` + position: absolute; + width: 1ex; + height: 1ex; + top: -0.3ex; + background-color: black; + left: ${(props) => props.$proportion * 90}%; +`; + +export function Slider({ + value, + onChange, +}: { + value: number; + onChange: (newValue: number) => void; +}) { + const slider = useRef(null); + + const handleClick = (event: React.MouseEvent) => { + onChange( + event.nativeEvent.offsetX / (event.target as HTMLDivElement).offsetWidth + ); + + event.stopPropagation(); + }; + + const handleDrag = (event: React.MouseEvent) => { + const sliderRef = slider.current; + + if (!sliderRef || event.buttons !== 1) { + return; + } + + const relativePosition = + event.clientX - sliderRef.getBoundingClientRect().left; + const proportion = relativePosition / sliderRef.offsetWidth; + + const clamped = Math.min(1, Math.max(0, proportion)); + + onChange(clamped); + }; + + return ( + + + { + e.stopPropagation(); + }} + /> + + + ); +} diff --git a/website/src/mgba.tsx b/website/src/mgba.tsx index e0c1e064..392f4cf2 100644 --- a/website/src/mgba.tsx +++ b/website/src/mgba.tsx @@ -57,7 +57,6 @@ export const Mgba = forwardRef( mgbaModule.current.FS.writeFile(gamePath, new Uint8Array(gameData)); mgbaModule.current.loadGame(gamePath); mgbaModule.current.setVolume(0.1); // for some reason you have to do this or you get no sound - console.log(mgbaModule.current.getVolume()); setGameLoaded(true); })(); }, [state, gameUrl]); @@ -113,9 +112,7 @@ export const Mgba = forwardRef( useEffect(() => { if (!gameLoaded) return; - console.log("before", mgbaModule.current.getVolume()); mgbaModule.current.setVolume(volume ?? 1.0); - console.log("after", mgbaModule.current.getVolume()); }, [gameLoaded, volume]); useEffect(() => {