From d2667fd0fb0556b4b4c64e7198f230e84280aef3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 30 Jul 2023 18:11:16 -0400 Subject: [PATCH] added navigation to the UI --- src/Myrian/ui/MyrianRoot.tsx | 100 +++++++++++++++++++++++++++++++---- src/Myrian/world.txt | 30 ----------- 2 files changed, 90 insertions(+), 40 deletions(-) delete mode 100644 src/Myrian/world.txt diff --git a/src/Myrian/ui/MyrianRoot.tsx b/src/Myrian/ui/MyrianRoot.tsx index 873899a4c..665593254 100644 --- a/src/Myrian/ui/MyrianRoot.tsx +++ b/src/Myrian/ui/MyrianRoot.tsx @@ -8,9 +8,19 @@ import BatteryFullIcon from "@mui/icons-material/BatteryFull"; import Battery20Icon from "@mui/icons-material/Battery20"; import FavoriteIcon from "@mui/icons-material/Favorite"; import LandscapeIcon from "@mui/icons-material/Landscape"; +import { IconButton } from "@mui/material"; +import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"; +import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; +import KeyboardArrowLeftIcon from "@mui/icons-material/KeyboardArrowLeft"; +import KeyboardArrowRightIcon from "@mui/icons-material/KeyboardArrowRight"; -const iterator = (i: number): number[] => { - return Array(i).fill(0); +import ZoomInMapIcon from "@mui/icons-material/ZoomInMap"; +import ZoomOutMapIcon from "@mui/icons-material/ZoomOutMap"; + +const iterator = (i: number, offset = 0): number[] => { + return Array(i) + .fill(0) + .map((_, v) => v + offset); }; interface ICellProps { @@ -50,6 +60,8 @@ interface IProps { } export function MyrianRoot({ myrian }: IProps): React.ReactElement { + const [center, setCenter] = useState([myrian.world[0].length / 2, myrian.world.length / 2]); + const [size, setSize] = useState(11); const [, setRerender] = useState(false); const rerender = () => setRerender((old) => !old); useEffect(() => { @@ -59,16 +71,84 @@ export function MyrianRoot({ myrian }: IProps): React.ReactElement { const sleeves = Object.fromEntries(myrian.sleeves.map((s) => [`${s.x}_${s.y}`, s])); + const move = (x: number, y: number) => () => { + setCenter((c) => [Math.max(Math.floor(size / 2), c[0] + x), Math.max(Math.floor(size / 2), c[1] + y)]); + }; + + const zoom = (size: number) => () => { + setSize((s) => s + size); + }; return ( - - - {iterator(myrian.world.length).map((_, j) => ( - - {iterator(myrian.world[j].length).map((_, i) => ( - - ))} + + + + {iterator(size, center[1] - Math.floor(size / 2)).map((j) => ( + + {iterator(size, center[0] - Math.floor(size / 2)).map((i) => ( + + ))} + + ))} + + + + + + + + + + + + + - ))} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); diff --git a/src/Myrian/world.txt b/src/Myrian/world.txt deleted file mode 100644 index 4baa940ba..000000000 --- a/src/Myrian/world.txt +++ /dev/null @@ -1,30 +0,0 @@ - - - mmmmmmm - mmmmmmmm - mmmmmmmmmmmm - bbbb mmmmm - mmmm - c mmmm - mmmm - ddddd mmmm - - mmmmmmmmmm - mmmmmmmm - mmmmmmmm mmmm - - - - - - - - - - - - - - - - \ No newline at end of file