-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5c0e4a
commit f3802c3
Showing
10 changed files
with
305 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
Flex, | ||
Heading, | ||
Table, | ||
TableContainer, | ||
Tbody, | ||
Td, | ||
Th, | ||
Thead, | ||
Tr, | ||
} from '@chakra-ui/react' | ||
|
||
import { QUERY_KEYS, STORE_KEYS, Waypoint } from '../constants' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
export const useWaypointsQuery = () => | ||
useQuery<Waypoint[]>({ | ||
queryKey: [QUERY_KEYS.useWaypoints], | ||
queryFn: () => window.api.store.get(STORE_KEYS.waypoints), | ||
refetchOnMount: false, | ||
refetchOnWindowFocus: false, | ||
refetchOnReconnect: false, | ||
}) | ||
|
||
export function Waypoints() { | ||
const waypoints = useWaypointsQuery() | ||
|
||
return ( | ||
<> | ||
<Flex> | ||
<Heading>Waypoints</Heading> | ||
</Flex> | ||
|
||
<TableContainer> | ||
<Table> | ||
<Thead> | ||
<Tr> | ||
<Th>Name</Th> | ||
<Th>Date</Th> | ||
<Th>X</Th> | ||
<Th>Y</Th> | ||
<Th>Z</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{(waypoints.data ?? []).map((waypoint, i) => ( | ||
<Tr key={i} _hover={{ backgroundColor: 'blue.50' }}> | ||
<Td>{waypoint.name}</Td> | ||
<Td>{waypoint.date.toLocaleDateString()}</Td> | ||
<Td>{waypoint.x}</Td> | ||
<Td>{waypoint.y}</Td> | ||
<Td>{waypoint.z}</Td> | ||
</Tr> | ||
))} | ||
</Tbody> | ||
</Table> | ||
</TableContainer> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { DependencyList, useEffect } from 'react' | ||
import type { ChunkDirection } from '../types' | ||
|
||
const vanillaCoords = | ||
/tp @s (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+)/ | ||
const lunarClientCoords = /X: (-?\d+) Y: (-?\d+) Z: (-?\d+)/ | ||
|
||
export const lerp = (a: number, b: number, t: number) => a + (b - a) * t | ||
|
||
export function getDirectionFromRotation( | ||
rotation?: number | ||
): ChunkDirection | undefined { | ||
if (typeof rotation !== 'number') return undefined | ||
const angleInRadians = rotation * (Math.PI / 180) | ||
const x = -Math.sin(angleInRadians) | ||
const z = Math.cos(angleInRadians) | ||
return { | ||
x: Math.abs(x) > 0.5 ? (x > 0 ? 1 : -1) : 0, | ||
z: Math.abs(z) > 0.5 ? (z > 0 ? 1 : -1) : 0, | ||
} | ||
} | ||
|
||
export function getDirectionArrow(direction?: ChunkDirection) { | ||
if (!direction) return '' | ||
switch (direction.z) { | ||
case 1: | ||
return direction.x === 1 ? '↗' : direction.x === -1 ? '↖' : '↑' | ||
case -1: | ||
return direction.x === 1 ? '↘' : direction.x === -1 ? '↙' : '↓' | ||
case 0: | ||
return direction.x === 1 ? '→' : direction.x === -1 ? '←' : '' | ||
} | ||
} | ||
|
||
export const usePastedCoordinates = ( | ||
cb: (x: number, y: number, z: number, rotation?: number) => void, | ||
deps?: DependencyList | ||
) => | ||
useEffect(() => { | ||
const handle = window.api.onClipboardTextUpdated((text: string) => { | ||
let rotation: number | undefined | ||
let match = text.match(vanillaCoords) | ||
if (match) rotation = parseFloat(match[4]) | ||
|
||
if (!match) match = text.match(lunarClientCoords) | ||
if (!match) return | ||
|
||
const x = parseInt(match[1]) | ||
const y = parseInt(match[2]) | ||
const z = parseInt(match[3]) | ||
cb(x, y, z, rotation) | ||
}) | ||
return () => window.api.removeListener(handle) | ||
}, deps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.